Search in sources :

Example 11 with ClusterEnvironment

use of com.couchbase.client.java.env.ClusterEnvironment in project spring-boot by spring-projects.

the class CouchbaseAutoConfigurationTests method customizeEnvWithCustomCouchbaseConfiguration.

@Test
void customizeEnvWithCustomCouchbaseConfiguration() {
    this.contextRunner.withUserConfiguration(CouchbaseTestConfiguration.class, ClusterEnvironmentCustomizerConfiguration.class).withPropertyValues("spring.couchbase.connection-string=localhost", "spring.couchbase.env.timeouts.connect=100").run((context) -> {
        assertThat(context).hasSingleBean(ClusterEnvironment.class);
        ClusterEnvironment env = context.getBean(ClusterEnvironment.class);
        assertThat(env.timeoutConfig().kvTimeout()).isEqualTo(Duration.ofSeconds(5));
        assertThat(env.timeoutConfig().connectTimeout()).isEqualTo(Duration.ofSeconds(2));
    });
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) Test(org.junit.jupiter.api.Test)

Example 12 with ClusterEnvironment

use of com.couchbase.client.java.env.ClusterEnvironment in project couchbase-elasticsearch-connector by couchbase.

the class CheckpointClear method run.

private static void run(ConnectorConfig config, boolean catchUp) throws IOException {
    final ClusterEnvironment env = environmentBuilder(config.couchbase(), config.trustStore()).build();
    final Cluster cluster = createCluster(config.couchbase(), env);
    try {
        final Bucket metadataBucket = CouchbaseHelper.waitForBucket(cluster, config.couchbase().metadataBucket());
        final Collection metadataCollection = CouchbaseHelper.getMetadataCollection(metadataBucket, config.couchbase());
        final ResolvedBucketConfig bucketConfig = getBucketConfig(config.couchbase(), metadataBucket);
        final Set<SeedNode> kvNodes = getKvNodes(config.couchbase(), metadataBucket);
        final CheckpointDao checkpointDao = new CouchbaseCheckpointDao(metadataCollection, config.group().name());
        if (catchUp) {
            setCheckpointToNow(config, kvNodes, checkpointDao);
            System.out.println("Set checkpoint for connector '" + config.group().name() + "' to match current state of Couchbase bucket.");
        } else {
            final int numVbuckets = bucketConfig.numberOfPartitions();
            final Set<Integer> vbuckets = IntStream.range(0, numVbuckets).boxed().collect(toSet());
            checkpointDao.clear(bucketConfig.uuid(), vbuckets);
            System.out.println("Cleared checkpoint for connector '" + config.group().name() + "'.");
        }
    } finally {
        cluster.disconnect();
        env.shutdown();
    }
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) CheckpointDao(com.couchbase.connector.dcp.CheckpointDao) CouchbaseCheckpointDao(com.couchbase.connector.dcp.CouchbaseCheckpointDao) Bucket(com.couchbase.client.java.Bucket) SeedNode(com.couchbase.client.core.env.SeedNode) ResolvedBucketConfig(com.couchbase.connector.dcp.ResolvedBucketConfig) CouchbaseHelper.createCluster(com.couchbase.connector.dcp.CouchbaseHelper.createCluster) Cluster(com.couchbase.client.java.Cluster) Collection(com.couchbase.client.java.Collection) CouchbaseCheckpointDao(com.couchbase.connector.dcp.CouchbaseCheckpointDao) Checkpoint(com.couchbase.connector.dcp.Checkpoint)

Example 13 with ClusterEnvironment

use of com.couchbase.client.java.env.ClusterEnvironment in project couchbase-jvm-clients by couchbase.

the class SharedClusterEnvironmentIntegrationTest method canShareClusterEnvironment.

@Test
void canShareClusterEnvironment() {
    ClusterEnvironment.Builder envBuilder = ClusterEnvironment.builder();
    environmentCustomizer().accept(envBuilder);
    ClusterEnvironment env = envBuilder.build();
    ClusterOptions options = ClusterOptions.clusterOptions(authenticator()).environment(env);
    Cluster cluster1 = Cluster.connect(seedNodes(), options);
    Cluster cluster2 = Cluster.connect(seedNodes(), options);
    try {
        assertSame(cluster1.core().context().environment(), cluster2.core().context().environment());
        Bucket bucket1 = cluster1.bucket(config().bucketname());
        Bucket bucket2 = cluster2.bucket(config().bucketname());
        bucket1.waitUntilReady(Duration.ofSeconds(10));
        bucket2.waitUntilReady(Duration.ofSeconds(10));
        String documentId = UUID.randomUUID().toString();
        bucket1.defaultCollection().upsert(documentId, "foo", upsertOptions().expiry(Duration.ofSeconds(1)));
        cluster1.disconnect();
        // environment should remain active for the other cluster to use
        bucket2.defaultCollection().upsert(documentId, "foo", upsertOptions().expiry(Duration.ofSeconds(1)));
    } finally {
        cluster1.disconnect();
        cluster2.disconnect();
        env.shutdown();
    }
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)13 Cluster (com.couchbase.client.java.Cluster)7 Bucket (com.couchbase.client.java.Bucket)5 Collection (com.couchbase.client.java.Collection)4 Test (org.junit.jupiter.api.Test)4 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)3 SeedNode (com.couchbase.client.core.env.SeedNode)2 JacksonJsonSerializer (com.couchbase.client.java.codec.JacksonJsonSerializer)2 CheckpointDao (com.couchbase.connector.dcp.CheckpointDao)2 CouchbaseCheckpointDao (com.couchbase.connector.dcp.CouchbaseCheckpointDao)2 Duration (java.time.Duration)2 ComponentException (org.talend.sdk.component.api.exception.ComponentException)2 Slf4jReporter (com.codahale.metrics.Slf4jReporter)1 DefaultFullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)1 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)1 PingResult (com.couchbase.client.core.diagnostics.PingResult)1 ConnectionStringPropertyLoader (com.couchbase.client.core.env.ConnectionStringPropertyLoader)1 OwnedSupplier (com.couchbase.client.core.env.OwnedSupplier)1 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)1 Builder (com.couchbase.client.core.env.TimeoutConfig.Builder)1