use of com.azure.cosmos.CosmosClient in project vividus by vividus-framework.
the class CosmosDbServiceTests method testWithContainer.
private void testWithContainer(BiConsumer<CosmosDbContainer, CosmosContainer> testToRun, String containerId) {
CosmosDbContainer dbContainer = new CosmosDbContainer();
dbContainer.setId(containerId);
dbContainer.setDbKey(DB_KEY);
try (CosmosClient client = mock(CosmosClient.class);
MockedConstruction<CosmosClientBuilder> builderConstructor = mockConstruction(CosmosClientBuilder.class, (mock, context) -> {
when(mock.endpoint(ENDPOINT)).thenReturn(mock);
when(mock.key(KEY)).thenReturn(mock);
when(mock.connectionSharingAcrossClientsEnabled(true)).thenReturn(mock);
when(mock.buildClient()).thenReturn(client);
})) {
when(client.getDatabase(DB)).thenReturn(database);
when(database.getContainer(containerId)).thenReturn(container);
testToRun.accept(dbContainer, container);
assertThat(builderConstructor.constructed(), hasSize(1));
}
}
use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method PerformanceTipsJavaSDKv4CDirectOverrideSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - Direct data plane, Gateway control plane
*/
/**
* Performance tips - Direct data plane, Gateway control plane
*/
public static void PerformanceTipsJavaSDKv4CDirectOverrideSync() {
String HOSTNAME = "";
String MASTERKEY = "";
// Arbitrary
ConsistencyLevel CONSISTENCY = ConsistencyLevel.EVENTUAL;
// <PerformanceClientDirectOverrideSync>
/* Independent customization of Direct mode data plane and Gateway mode control plane */
DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
// Example config, do not use these settings as defaults
directConnectionConfig.setMaxConnectionsPerEndpoint(120);
directConnectionConfig.setIdleConnectionTimeout(Duration.ofMillis(100));
GatewayConnectionConfig gatewayConnectionConfig = GatewayConnectionConfig.getDefaultConfig();
// Example config, do not use these settings as defaults
gatewayConnectionConfig.setProxy(new ProxyOptions(ProxyOptions.Type.HTTP, InetSocketAddress.createUnresolved("your.proxy.addr", 80)));
gatewayConnectionConfig.setMaxConnectionPoolSize(150);
CosmosClient clientDirectCustom = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).directMode(directConnectionConfig, gatewayConnectionConfig).buildClient();
// </PerformanceClientDirectOverrideSync>
}
use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method ConfigureMultimasterInYourApplicationsThatUseComosDBSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-multi-master
* Multi-master tutorial
*/
/**
* Enable multi-master from client
*/
public static void ConfigureMultimasterInYourApplicationsThatUseComosDBSync() {
String MASTER_KEY = "";
String HOST = "";
String region = "West US 2";
// <ConfigureMultimasterSync>
ArrayList<String> preferredRegions = new ArrayList<String>();
preferredRegions.add(region);
CosmosClient client = new CosmosClientBuilder().endpoint(HOST).key(MASTER_KEY).multipleWriteRegionsEnabled(true).preferredRegions(preferredRegions).buildClient();
// </ConfigureMultimasterSync>
}
use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method ManageConsistencyLevelsInAzureCosmosDBSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-consistency
* Manage consistency
*/
/**
* Managed consistency from client
*/
public static void ManageConsistencyLevelsInAzureCosmosDBSync() {
String MASTER_KEY = "";
String HOST = "";
// <ManageConsistencySync>
CosmosClient client = new CosmosClientBuilder().endpoint(HOST).key(MASTER_KEY).consistencyLevel(ConsistencyLevel.EVENTUAL).buildClient();
// </ManageConsistencySync>
}
use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method TutorialSetUpAzureCosmosDBGlobalDistributionUsingTheSqlApiPreferredLocationsSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-global-distribution-sql-api
* Tutorial: Set up Azure Cosmos DB global distribution using the SQL API
*/
/**
* Preferred locations
*/
public static void TutorialSetUpAzureCosmosDBGlobalDistributionUsingTheSqlApiPreferredLocationsSync() {
String MASTER_KEY = "";
String HOST = "";
// <TutorialGlobalDistributionPreferredLocationSync>
ArrayList<String> preferredRegions = new ArrayList<String>();
preferredRegions.add("East US");
preferredRegions.add("West US");
preferredRegions.add("Canada Central");
CosmosClient client = new CosmosClientBuilder().endpoint(HOST).key(MASTER_KEY).preferredRegions(preferredRegions).contentResponseOnWriteEnabled(true).buildClient();
// </TutorialGlobalDistributionPreferredLocationSync>
}
Aggregations