Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -66,7 +66,6 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
Expand Down Expand Up @@ -592,8 +591,6 @@ public void databaseAccountToClients() {
cosmosDiagnosticsNode.get("clientCfgs").get("clientEndpoints").get(TestConfigurations.HOST).asInt();

assertThat(updatedClientCount).isEqualTo(clientCount + 1);
} catch (JsonMappingException e) {
throw new RuntimeException(e);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.azure.cosmos.ConsistencyLevel;
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfigBuilder;
import com.azure.cosmos.CosmosException;
import com.azure.cosmos.CosmosNettyLeakDetectorFactory;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.DocumentClientTest;
Expand All @@ -19,7 +21,10 @@
import com.azure.cosmos.models.CompositePath;
import com.azure.cosmos.models.CompositePathSortOrder;
import com.azure.cosmos.models.CosmosClientTelemetryConfig;
import com.azure.cosmos.models.CosmosItemOperation;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.CosmosBulkExecutionOptions;
import com.azure.cosmos.models.CosmosBulkOperations;
import com.azure.cosmos.models.FeedResponse;
import com.azure.cosmos.models.IncludedPath;
import com.azure.cosmos.models.IndexingPolicy;
Expand Down Expand Up @@ -199,24 +204,62 @@ protected static void truncateCollection(DocumentCollection collection) {

logger.info("Truncating DocumentCollection {} documents ...", collection.getId());

houseKeepingClient.queryDocuments(collection.getSelfLink(), "SELECT * FROM root", state, Document.class)
.publishOn(Schedulers.parallel())
.flatMap(page -> Flux.fromIterable(page.getResults()))
.flatMap(doc -> {
RequestOptions requestOptions = new RequestOptions();

if (paths != null && !paths.isEmpty()) {
List<String> pkPath = PathParser.getPathParts(paths.get(0));
Object propertyValue = doc.getObjectByPath(pkPath);
if (propertyValue == null) {
propertyValue = Undefined.value();
String altLink = collection.getAltLink();
String[] altLinkSegments = altLink.split("/");
// altLink format: dbs/{dbName}/colls/{collName}
String databaseName = altLinkSegments[1];
String containerName = altLinkSegments[3];

Flux<CosmosItemOperation> deleteOperations =
houseKeepingClient.queryDocuments(collection.getSelfLink(), "SELECT * FROM root", state, Document.class)
.publishOn(Schedulers.parallel())
.flatMap(page -> Flux.fromIterable(page.getResults()))
.map(doc -> {
Comment thread
xinlian12 marked this conversation as resolved.
Outdated
PartitionKey partitionKey;
if (paths != null && !paths.isEmpty()) {
List<String> pkPath = PathParser.getPathParts(paths.get(0));
Object propertyValue = doc.getObjectByPath(pkPath);
if (propertyValue == null) {
propertyValue = Undefined.value();
}
partitionKey = new PartitionKey(propertyValue);
} else {
partitionKey = PartitionKey.NONE;
}

requestOptions.setPartitionKey(new PartitionKey(propertyValue));
}

return houseKeepingClient.deleteDocument(doc.getSelfLink(), requestOptions);
}).then().block();
return CosmosBulkOperations.getDeleteItemOperation(doc.getId(), partitionKey);
});

CosmosBulkExecutionOptions bulkOptions = new CosmosBulkExecutionOptions();
ImplementationBridgeHelpers.CosmosBulkExecutionOptionsHelper
.getCosmosBulkExecutionOptionsAccessor()
.getImpl(bulkOptions)
.setCosmosEndToEndLatencyPolicyConfig(
new CosmosEndToEndOperationLatencyPolicyConfigBuilder(Duration.ofSeconds(65))
.build());

cosmosClient.getDatabase(databaseName)
.getContainer(containerName)
.executeBulkOperations(deleteOperations, bulkOptions)
.flatMap(response -> {
if (response.getException() != null) {
Exception ex = response.getException();
if (ex instanceof CosmosException) {
CosmosException cosmosException = (CosmosException) ex;
if (cosmosException.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND
&& cosmosException.getSubStatusCode() == 0) {
return Mono.empty();
}
}
return Mono.error(ex);
}
if (response.getResponse() != null
&& response.getResponse().getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) {
return Mono.empty();
}
Comment thread
xinlian12 marked this conversation as resolved.
return Mono.just(response);
})
.blockLast();

logger.info("Truncating DocumentCollection {} triggers ...", collection.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public InternalObjectNode createDocument(CosmosAsyncContainer cosmosContainer, M
return BridgeInternal.getProperties(cosmosContainer.createItem(docDefinition).block());
}

public List<InternalObjectNode> bulkInsert(CosmosAsyncContainer cosmosContainer, List<Map<String, Object>> keyValuePropsList) {
public List<InternalObjectNode> bulkInsertDocs(CosmosAsyncContainer cosmosContainer, List<Map<String, Object>> keyValuePropsList) {

ArrayList<InternalObjectNode> result = new ArrayList<InternalObjectNode>();

Expand Down Expand Up @@ -740,7 +740,7 @@ public void before_OrderbyDocumentQueryTest() throws Exception {
props = new HashMap<>();
keyValuePropsList.add(props);

createdDocuments = bulkInsert(createdCollection, keyValuePropsList);
createdDocuments = bulkInsertDocs(createdCollection, keyValuePropsList);

for(int i = 0; i < 10; i++) {
Map<String, Object> p = new HashMap<>();
Expand Down
Loading
Loading