Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void createClients() {
.connectionPolicy(configuration.getConnectionPolicy())
.consistencyLevel(configuration.getConsistencyLevel())
.connectionReuseAcrossClientsEnabled(true)
.contentResponseOnWriteEnabled(Boolean.parseBoolean(configuration.isContentResponseOnWriteEnabled()))
.buildAsyncClient();
List<PojoizedJson> docsToRead = new ArrayList<>();
CosmosAsyncDatabase cosmosAsyncDatabase = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ abstract class AsyncBenchmark<T> {
.key(cfg.getMasterKey())
.connectionPolicy(cfg.getConnectionPolicy())
.consistencyLevel(cfg.getConsistencyLevel())
.contentResponseOnWriteEnabled(Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled()))
.buildAsyncClient();
configuration = cfg;
logger = LoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public Duration convert(String value) {
@Parameter(names = "-useSync", description = "Uses Sync API")
private boolean useSync = false;

@Parameter(names = "-contentResponseOnWriteEnabled", description = "if set to false, does not returns content response on document write operations")
private String contentResponseOnWriteEnabled = String.valueOf(true);

@Parameter(names = {"-h", "-help", "--help"}, description = "Help", help = true)
private boolean help = false;

Expand Down Expand Up @@ -264,6 +267,10 @@ ConsistencyLevel getConsistencyLevel() {
return consistencyLevel;
}

String isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

String getDatabaseId() {
return databaseId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static void main(String[] args) throws Exception {
return;
}

validateConfiguration(cfg);

if (cfg.isSync()) {
syncBenchmark(cfg);
} else {
Expand All @@ -44,6 +46,19 @@ public static void main(String[] args) throws Exception {
}
}

private static void validateConfiguration(Configuration cfg) {
switch (cfg.getOperationType()) {
case WriteLatency:
case WriteThroughput:
break;
default:
if (!Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled())) {
throw new IllegalArgumentException("contentResponseOnWriteEnabled parameter can only be set to false " +
"for write latency and write throughput operations");
}
}
}

private static void syncBenchmark(Configuration cfg) throws Exception {
LOGGER.info("Sync benchmark ...");
SyncBenchmark benchmark = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public T apply(T o, Throwable throwable) {
.key(cfg.getMasterKey())
.connectionPolicy(cfg.getConnectionPolicy())
.consistencyLevel(cfg.getConsistencyLevel())
.contentResponseOnWriteEnabled(Boolean.parseBoolean(cfg.isContentResponseOnWriteEnabled()))
.buildClient();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public static AsyncDocumentClient housekeepingClient() {
options.setMaxRetryWaitTime(Duration.ofSeconds(60));
connectionPolicy.setThrottlingRetryOptions(options);
return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.build();
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withContentResponseOnWriteEnabled(true)
.build();
}

public static String getCollectionLink(Database db, DocumentCollection collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static CosmosAsyncClient getCosmosClient() {
.key(SampleConfigurations.MASTER_KEY)
.connectionPolicy(ConnectionPolicy.getDefaultPolicy())
.consistencyLevel(ConsistencyLevel.EVENTUAL)
.contentResponseOnWriteEnabled(true)
.buildAsyncClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public MultiMasterScenario() {
.withMasterKeyOrResourceToken(this.accountKey)
.withServiceEndpoint(this.accountEndpoint)
.withConsistencyLevel(ConsistencyLevel.EVENTUAL)
.withConnectionPolicy(policy).build();
.withConnectionPolicy(policy)
.withContentResponseOnWriteEnabled(true)
.build();


workers.add(new Worker(client, databaseName, basicCollectionName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void before_CollectionCRUDAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void before_ConflictAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void before_TokenResolverTest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down Expand Up @@ -145,6 +146,7 @@ public void readDocumentThroughTokenResolver() throws Exception {
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withTokenResolver(getTokenResolverForRead())
.withContentResponseOnWriteEnabled(true)
.build();
List<ResourceResponse<Document>> capturedResponse = Collections
.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -183,6 +185,7 @@ public void deleteDocumentThroughTokenResolver() throws Exception {
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withTokenResolver(getTokenResolverForReadWrite())
.withContentResponseOnWriteEnabled(true)
.build();
List<ResourceResponse<Document>> capturedResponse = Collections
.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -225,6 +228,7 @@ public void blockListUserThroughTokenResolver() throws Exception {
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withTokenResolver(getTokenResolverWithBlockList(blockListedUserId, errorMessage))
.withContentResponseOnWriteEnabled(true)
.build();

// READ a document using a block listed user, passing the 'userId' in the item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void before_DatabaseCRUDAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

this.client = this.clientBuilder().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void before_DocumentCRUDAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void before_DocumentQueryAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void before_InMemoryGroupbyTest() throws Exception {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public void before_OfferCRUDAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void before_StoredProcedureAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void before_UniqueIndexAsyncAPITest() {
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConsistencyLevel(ConsistencyLevel.SESSION);
.withConsistencyLevel(ConsistencyLevel.SESSION)
.withContentResponseOnWriteEnabled(true);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void cleanupStaleDatabase() {
connectionPolicy.setThrottlingRetryOptions(options);
AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST)
.withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(connectionPolicy)
.withConnectionPolicy(connectionPolicy).withContentResponseOnWriteEnabled(true)
.build();
safeCleanDatabases(client);
client.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class CosmosAsyncClient implements Closeable {
private final CosmosKeyCredential cosmosKeyCredential;
private final boolean sessionCapturingOverride;
private final boolean enableTransportClientSharing;
private final boolean contentResponseOnWriteEnabled;

CosmosAsyncClient(CosmosClientBuilder builder) {
this.configs = builder.configs();
Expand All @@ -61,6 +62,7 @@ public final class CosmosAsyncClient implements Closeable {
this.cosmosKeyCredential = builder.getKeyCredential();
this.sessionCapturingOverride = builder.isSessionCapturingOverrideEnabled();
this.enableTransportClientSharing = builder.isConnectionReuseAcrossClientsEnabled();
this.contentResponseOnWriteEnabled = builder.isContentResponseOnWriteEnabled();
this.asyncDocumentClient = new AsyncDocumentClient.Builder()
.withServiceEndpoint(this.serviceEndpoint)
.withMasterKeyOrResourceToken(this.keyOrResourceToken)
Expand All @@ -71,6 +73,7 @@ public final class CosmosAsyncClient implements Closeable {
.withTokenResolver(this.cosmosAuthorizationTokenResolver)
.withCosmosKeyCredential(this.cosmosKeyCredential)
.withTransportClientSharing(this.enableTransportClientSharing)
.withContentResponseOnWriteEnabled(this.contentResponseOnWriteEnabled)
.build();
}

Expand Down Expand Up @@ -163,6 +166,22 @@ CosmosKeyCredential cosmosKeyCredential() {
return cosmosKeyCredential;
}

/**
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* By-default, this is false.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* CREATE a Database if it does not already exist on the service
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package com.azure.cosmos;

import com.azure.cosmos.implementation.AsyncDocumentClient;
import com.azure.cosmos.implementation.DocumentCollection;
import com.azure.cosmos.models.CosmosContainerProperties;

/**
* DO NOT USE. For internal use only by the SDK. These methods might break at any time. No support will be provided.
Expand Down Expand Up @@ -66,7 +64,8 @@ public static CosmosClientBuilder cloneCosmosClientBuilder(CosmosClientBuilder b
.keyCredential(builder.getKeyCredential())
.permissions(builder.getPermissions())
.authorizationTokenResolver(builder.getAuthorizationTokenResolver())
.resourceToken(builder.getResourceToken());
.resourceToken(builder.getResourceToken())
.contentResponseOnWriteEnabled(builder.isContentResponseOnWriteEnabled());

return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CosmosClientBuilder {
private CosmosKeyCredential cosmosKeyCredential;
private boolean sessionCapturingOverrideEnabled;
private boolean connectionReuseAcrossClientsEnabled;
private boolean contentResponseOnWriteEnabled;

/**
* Instantiates a new Cosmos client builder.
Expand Down Expand Up @@ -291,6 +292,41 @@ public CosmosClientBuilder keyCredential(CosmosKeyCredential cosmosKeyCredential
return this;
}

/**
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* By-default, this is false.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to false (which is by default), this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is false.
*
* @param contentResponseOnWriteEnabled a boolean indicating whether resource will be included in the response or not
* @return current cosmosClientBuilder
*/
public CosmosClientBuilder contentResponseOnWriteEnabled(boolean contentResponseOnWriteEnabled) {
this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled;
return this;
}

/**
* Builds a cosmos configuration object with the provided properties
*
Expand Down
Loading