use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method performShutdown.
/**
* Perform the shutdown and checks that afterwards the other ops don't work anymore.
*/
@Test
void performShutdown() throws Exception {
TestNodeConfig cfg = config().firstNodeWith(Services.KV).get();
Set<SeedNode> seeds = new HashSet<>(Collections.singletonList(SeedNode.create(cfg.hostname(), Optional.of(cfg.ports().get(Services.KV)), Optional.of(cfg.ports().get(Services.MANAGER)))));
environment = CoreEnvironment.builder().timeoutConfig(TimeoutConfig.kvTimeout(kvTimeout).managementTimeout(managementTimeout)).build();
core = Core.create(environment, authenticator(), seeds);
String bucketName = config().bucketname();
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
AtomicInteger configEvents = new AtomicInteger(0);
CountDownLatch configsComplete = new CountDownLatch(1);
// ignore initial empty config
provider.configs().skip(1).subscribe((c) -> configEvents.incrementAndGet(), (e) -> {
}, configsComplete::countDown);
assertEquals(0, provider.config().bucketConfigs().size());
provider.openBucket(bucketName).timeout(DEFAULT_TIMEOUT).block();
assertEquals(1, provider.config().bucketConfigs().size());
provider.shutdown().timeout(DEFAULT_TIMEOUT).block();
assertEquals(0, provider.config().bucketConfigs().size());
assertThrows(AlreadyShutdownException.class, () -> provider.shutdown().block());
assertThrows(AlreadyShutdownException.class, () -> provider.openBucket("foo").block());
assertThrows(AlreadyShutdownException.class, () -> provider.closeBucket("foo").block());
assertTrue(configsComplete.await(1, TimeUnit.SECONDS));
assertEquals(3, configEvents.get());
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method canProposeNewBucketConfig.
@Test
void canProposeNewBucketConfig() {
Core core = mock(Core.class);
CoreContext ctx = new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class));
when(core.context()).thenReturn(ctx);
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, SeedNode.LOCALHOST);
final AtomicInteger configsPushed = new AtomicInteger(0);
provider.configs().skip(// ignore initial empty config
1).subscribe((c) -> configsPushed.incrementAndGet());
assertTrue(provider.config().bucketConfigs().isEmpty());
assertEquals(1, provider.currentSeedNodes().size());
String bucket = "default";
String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals(1, configsPushed.get());
assertFalse(provider.config().bucketConfigs().isEmpty());
assertEquals(1073, provider.config().bucketConfig("default").rev());
assertEquals(3, getSeedNodesFromConfig(provider).size());
for (SeedNode node : getSeedNodesFromConfig(provider)) {
assertEquals(11210, node.kvPort().get());
assertEquals(8091, node.clusterManagerPort().get());
}
assertEquals(Optional.empty(), ctx.alternateAddress());
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method updatesSeedNodesFromGlobalConfig.
/**
* Makes sure that even if we only get a global config the seed nodes are properly updated from
* that config.
*/
@Test
void updatesSeedNodesFromGlobalConfig() {
Core core = mock(Core.class);
when(core.context()).thenReturn(new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class)));
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, SeedNode.LOCALHOST);
String newConfig = readResource("global_config_mad_hatter_multi_node.json", DefaultConfigurationProviderTest.class);
provider.proposeGlobalConfig(new ProposedGlobalConfigContext(newConfig, "127.0.0.1"));
assertEquals(2, getSeedNodesFromConfig(provider).size());
for (SeedNode sn : getSeedNodesFromConfig(provider)) {
assertEquals(11210, sn.kvPort().get());
assertEquals(8091, sn.clusterManagerPort().get());
assertTrue(sn.address().equals("10.143.193.101") || sn.address().equals("10.143.193.102"));
}
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method externalModeSelectedIfAuto.
@Test
void externalModeSelectedIfAuto() {
Core core = mock(Core.class);
CoreEnvironment environment = CoreEnvironment.create();
CoreContext ctx = new CoreContext(core, 1, environment, PasswordAuthenticator.create("user", "pw"));
when(core.context()).thenReturn(ctx);
Set<SeedNode> seedNodes = new HashSet<>(Collections.singletonList(SeedNode.create("192.168.132.234")));
DefaultConfigurationProvider provider = new DefaultConfigurationProvider(core, seedNodes);
assertTrue(provider.config().bucketConfigs().isEmpty());
assertEquals(1, provider.currentSeedNodes().size());
String bucket = "default";
String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
assertEquals("external", ctx.alternateAddress().get());
environment.shutdown();
}
use of com.couchbase.client.core.env.SeedNode 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();
}
}
Aggregations