Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,13 @@ protected String getDocumentLink(Document doc) {
return doc.getSelfLink();
}
}

@Override
void shutdown() {
if (this.client != null) {
this.client.close();
}

super.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void validateNoChargeOnFailedSessionRead() throws Exception {
new CosmosClientTelemetryConfig()
.sendClientTelemetryToService(ClientTelemetry.DEFAULT_CLIENT_TELEMETRY_ENABLED))
.build();

QueryFeedOperationState dummyState = null;
try {
// CREATE collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public void queryWithContinuationTokenLimit(CosmosQueryRequestOptions options, S

client.clearCapturedRequests();

QueryFeedOperationState dummyState = TestUtils
.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);
QueryFeedOperationState dummyState = TestUtils.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);
try {
Flux<FeedResponse<Document>> queryObservable = client
.queryDocuments(
Expand Down Expand Up @@ -148,6 +147,11 @@ public Document createDocument(AsyncDocumentClient client, String collectionLink
@BeforeClass(groups = { "fast" }, timeOut = SETUP_TIMEOUT)
public void before_DocumentQuerySpyWireContentTest() throws Exception {

SpyClientUnderTestFactory.ClientUnderTest oldSnapshot = client;
if (oldSnapshot != null) {
oldSnapshot.close();
}

client = new SpyClientBuilder(this.clientBuilder()).build();

createdDatabase = SHARED_DATABASE;
Expand Down Expand Up @@ -177,18 +181,14 @@ public void before_DocumentQuerySpyWireContentTest() throws Exception {
options,
client
);
try {

// do the query once to ensure the collection is cached.
client.queryDocuments(getMultiPartitionCollectionLink(), "select * from root", state, Document.class)
.then().block();
// do the query once to ensure the collection is cached.
client.queryDocuments(getMultiPartitionCollectionLink(), "select * from root", state, Document.class)
.then().block();

// do the query once to ensure the collection is cached.
client.queryDocuments(getSinglePartitionCollectionLink(), "select * from root", state, Document.class)
.then().block();
} finally {
safeClose(state);
}
// do the query once to ensure the collection is cached.
client.queryDocuments(getSinglePartitionCollectionLink(), "select * from root", state, Document.class)
.then().block();
}

@AfterClass(groups = { "fast" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public void queryWithMaxIntegratedCacheStaleness(CosmosQueryRequestOptions optio

client.clearCapturedRequests();

QueryFeedOperationState dummyState = TestUtils
.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);
QueryFeedOperationState dummyState = TestUtils.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);
try {
client.queryDocuments(
collectionLink,
Expand Down Expand Up @@ -175,7 +174,6 @@ public void queryWithMaxIntegratedCacheStalenessInNanoseconds() {
);

try {

assertThatThrownBy(() -> client
.queryDocuments(collectionLink, query, state, Document.class)
.blockLast())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,132 +203,129 @@ public void partitionedSessionToken(boolean isNameBased) throws NoSuchMethodExce
spyClient
);

try {
spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests()).hasSize(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token

spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests()).hasSize(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
// Session token validation for cross partition query
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();

// Session token validation for cross partition query
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.Query,
queryRequestOptions,
spyClient
);
spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.Query,
queryRequestOptions,
spyClient
);
spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token

// Session token validation for feed ranges query
spyClient.clearCapturedRequests();
List<FeedRange> feedRanges = spyClient.getFeedRanges(getCollectionLink(isNameBased), true).block();
queryRequestOptions = new CosmosQueryRequestOptions();
queryRequestOptions.setFeedRange(feedRanges.get(0));
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.Query,
queryRequestOptions,
spyClient
);
spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
// Session token validation for feed ranges query
spyClient.clearCapturedRequests();
List<FeedRange> feedRanges = spyClient.getFeedRanges(getCollectionLink(isNameBased), true).block();
queryRequestOptions = new CosmosQueryRequestOptions();
queryRequestOptions.setFeedRange(feedRanges.get(0));
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.Query,
queryRequestOptions,
spyClient
);
spyClient.queryDocuments(getCollectionLink(isNameBased), query, dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token

// Session token validation for readAll with partition query
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.ReadFeed,
queryRequestOptions,
spyClient
);
spyClient.readAllDocuments(
getCollectionLink(isNameBased),
new PartitionKey(documentCreated.getId()),
dummyState,
Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
// Session token validation for readAll with partition query
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.ReadFeed,
queryRequestOptions,
spyClient
);
spyClient.readAllDocuments(
getCollectionLink(isNameBased),
new PartitionKey(documentCreated.getId()),
dummyState,
Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token

// Session token validation for readAll with cross partition
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
// Session token validation for readAll with cross partition
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();

safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.ReadFeed,
queryRequestOptions,
spyClient
);
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(
ResourceType.Document,
OperationType.ReadFeed,
queryRequestOptions,
spyClient
);

spyClient.readDocuments(getCollectionLink(isNameBased), dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
spyClient.readDocuments(getCollectionLink(isNameBased), dummyState, Document.class).blockFirst();
assertThat(getSessionTokensInRequests().size()).isGreaterThanOrEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token

// Session token validation for readMany with cross partition
// Session token validation for readMany with cross partition
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
CosmosItemIdentity cosmosItemIdentity = new CosmosItemIdentity(new PartitionKey(documentCreated.getId()), documentCreated.getId());
List<CosmosItemIdentity> cosmosItemIdentities = new ArrayList<>();
cosmosItemIdentities.add(cosmosItemIdentity);
safeClose(dummyState);
dummyState = TestUtils.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, queryRequestOptions, spyClient);
spyClient.readMany(
cosmosItemIdentities,
getCollectionLink(isNameBased),
dummyState,
InternalObjectNode.class).block();
assertThat(getSessionTokensInRequests().size()).isEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
// session token

// Session token validation for create in Batch
if(isNameBased) { // Batch only work with name based url
spyClient.clearCapturedRequests();
queryRequestOptions = new CosmosQueryRequestOptions();
CosmosItemIdentity cosmosItemIdentity = new CosmosItemIdentity(new PartitionKey(documentCreated.getId()), documentCreated.getId());
List<CosmosItemIdentity> cosmosItemIdentities = new ArrayList<>();
cosmosItemIdentities.add(cosmosItemIdentity);
safeClose(dummyState);
dummyState = TestUtils
.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, queryRequestOptions, spyClient);
spyClient.readMany(
cosmosItemIdentities,
getCollectionLink(isNameBased),
dummyState,
InternalObjectNode.class).block();
Document document = newDocument();
document.set("mypk", document.getId());
ItemBatchOperation<Document> itemBatchOperation = new ItemBatchOperation<Document>(CosmosItemOperationType.CREATE,
documentCreated.getId(), new PartitionKey(documentCreated.getId()), new RequestOptions(), document);
List<ItemBatchOperation<Document>> itemBatchOperations = new ArrayList<>();
itemBatchOperations.add(itemBatchOperation);

Method method = SinglePartitionKeyServerBatchRequest.class.getDeclaredMethod("createBatchRequest",
PartitionKey.class,
List.class);
method.setAccessible(true);
SinglePartitionKeyServerBatchRequest serverBatchRequest =
(SinglePartitionKeyServerBatchRequest) method.invoke(SinglePartitionKeyServerBatchRequest.class, new PartitionKey(document.getId()),
itemBatchOperations);
spyClient
.executeBatchRequest(
getCollectionLink(isNameBased),
serverBatchRequest,
new RequestOptions(),
false,
true)
.block();
assertThat(getSessionTokensInRequests().size()).isEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
// session token

// Session token validation for create in Batch
if (isNameBased) { // Batch only work with name based url
spyClient.clearCapturedRequests();
Document document = newDocument();
document.set("mypk", document.getId());
ItemBatchOperation<Document> itemBatchOperation = new ItemBatchOperation<Document>(CosmosItemOperationType.CREATE,
documentCreated.getId(), new PartitionKey(documentCreated.getId()), new RequestOptions(), document);
List<ItemBatchOperation<Document>> itemBatchOperations = new ArrayList<>();
itemBatchOperations.add(itemBatchOperation);

Method method = SinglePartitionKeyServerBatchRequest.class.getDeclaredMethod("createBatchRequest",
PartitionKey.class,
List.class);
method.setAccessible(true);
SinglePartitionKeyServerBatchRequest serverBatchRequest =
(SinglePartitionKeyServerBatchRequest) method.invoke(SinglePartitionKeyServerBatchRequest.class, new PartitionKey(document.getId()),
itemBatchOperations);
spyClient
.executeBatchRequest(
getCollectionLink(isNameBased),
serverBatchRequest,
new RequestOptions(),
false,
true)
.block();
assertThat(getSessionTokensInRequests().size()).isEqualTo(1);
assertThat(getSessionTokensInRequests().get(0)).isNotEmpty();
assertThat(getSessionTokensInRequests().get(0)).doesNotContain(","); // making sure we have only one scope session token
}
} finally {
safeClose(dummyState);
}

safeClose(dummyState);
}

@Test(groups = { "fast" }, timeOut = TIMEOUT, dataProvider = "sessionTestArgProvider")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ public void crossPartitionQuery() {
options.setMaxDegreeOfParallelism(-1);
ModelBridgeInternal.setQueryRequestOptionsMaxItemCount(options, 100);

QueryFeedOperationState dummyState = TestUtils
.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);

QueryFeedOperationState dummyState =
TestUtils.createDummyQueryFeedOperationState(ResourceType.Document, OperationType.Query, options, client);
try {
Flux<FeedResponse<Document>> results = client.queryDocuments(
getCollectionLink(),
Expand All @@ -245,6 +244,7 @@ public void crossPartitionQuery() {

validateQuerySuccess(results, validator, QUERY_TIMEOUT);
validateNoDocumentQueryOperationThroughGateway();

// validates only the first query for fetching query plan goes to gateway.
assertThat(client.getCapturedRequests().stream().filter(r -> r.getResourceType() == ResourceType.Document)).hasSize(1);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ public static void setTransportClient(StoreReader storeReader, TransportClient t
set(storeReader, transportClient, "transportClient");
}

public static void setTransportClient(CosmosClient client, TransportClient transportClient) {
StoreClient storeClient = getStoreClient((RxDocumentClientImpl) CosmosBridgeInternal.getAsyncDocumentClient(client));
set(storeClient, transportClient, "transportClient");
ReplicatedResourceClient replicatedResClient = getReplicatedResourceClient(storeClient);
ConsistencyWriter writer = getConsistencyWriter(replicatedResClient);
set(replicatedResClient, transportClient, "transportClient");
set(writer, transportClient, "transportClient");
}

public static TransportClient getTransportClient(ReplicatedResourceClient replicatedResourceClient) {
return get(TransportClient.class, replicatedResourceClient, "transportClient");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,11 @@ public URI serviceEndpoint() {
return null;
}

@Override
public URI serverKeyUsedAsActualRemoteAddress() {
return this.remoteURI;
}

@Override
public void injectConnectionErrors(String ruleId, double threshold, Class<?> eventType) {
throw new NotImplementedException("injectConnectionErrors is not supported in FakeEndpoint");
Expand Down
Loading