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));
});
}
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();
}
}
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();
}
}
Aggregations