Search in sources :

Example 1 with CosmosClient

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));
    }
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosDbContainer(org.vividus.azure.cosmos.model.CosmosDbContainer) CosmosClient(com.azure.cosmos.CosmosClient)

Example 2 with CosmosClient

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>
}
Also used : ConsistencyLevel(com.azure.cosmos.ConsistencyLevel) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) DirectConnectionConfig(com.azure.cosmos.DirectConnectionConfig) ProxyOptions(com.azure.core.http.ProxyOptions) CosmosClient(com.azure.cosmos.CosmosClient) GatewayConnectionConfig(com.azure.cosmos.GatewayConnectionConfig)

Example 3 with CosmosClient

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>
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) ArrayList(java.util.ArrayList) CosmosClient(com.azure.cosmos.CosmosClient)

Example 4 with CosmosClient

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>
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosClient(com.azure.cosmos.CosmosClient)

Example 5 with CosmosClient

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>
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) ArrayList(java.util.ArrayList) CosmosClient(com.azure.cosmos.CosmosClient)

Aggregations

CosmosClient (com.azure.cosmos.CosmosClient)8 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)7 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)3 ProxyOptions (com.azure.core.http.ProxyOptions)2 DirectConnectionConfig (com.azure.cosmos.DirectConnectionConfig)2 GatewayConnectionConfig (com.azure.cosmos.GatewayConnectionConfig)2 ArrayList (java.util.ArrayList)2 CosmosDatabase (com.azure.cosmos.CosmosDatabase)1 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)1 CosmosDbContainer (org.vividus.azure.cosmos.model.CosmosDbContainer)1