use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method openBucketFromOneFirstValidSeed.
/**
* Bucket config should also be loaded when the second seed in the list is not available.
*/
@Test
void openBucketFromOneFirstValidSeed() {
TestNodeConfig cfg = config().firstNodeWith(Services.KV).get();
Set<SeedNode> seeds = new HashSet<>(Arrays.asList(SeedNode.create(cfg.hostname(), Optional.of(cfg.ports().get(Services.KV)), Optional.of(cfg.ports().get(Services.MANAGER))), SeedNode.create("1.2.3.4")));
SimpleEventBus eventBus = new SimpleEventBus(true);
environment = CoreEnvironment.builder().eventBus(eventBus).build();
core = Core.create(environment, authenticator(), seeds);
String bucketName = config().bucketname();
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
openAndClose(bucketName, provider);
provider.shutdown().block();
waitUntilCondition(() -> eventBus.publishedEvents().stream().anyMatch(e -> e instanceof EndpointConnectionFailedEvent));
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method retriesOnBucketNotFoundDuringLoadException.
/**
* Need to make sure that if a bucket is not found during load, we continue retrying the open
* bucket attempts.
*/
@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void retriesOnBucketNotFoundDuringLoadException() {
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)))));
SimpleEventBus eventBus = new SimpleEventBus(true);
environment = CoreEnvironment.builder().eventBus(eventBus).build();
core = Core.create(environment, authenticator(), seeds);
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
try {
String bucketName = "this-bucket-does-not-exist";
provider.openBucket(bucketName).subscribe(v -> {
}, e -> assertTrue(e instanceof ConfigException));
waitUntilCondition(() -> eventBus.publishedEvents().stream().anyMatch(p -> p instanceof BucketOpenRetriedEvent));
for (Event event : eventBus.publishedEvents()) {
if (event instanceof BucketOpenRetriedEvent) {
assertEquals(bucketName, ((BucketOpenRetriedEvent) event).bucketName());
assertTrue(event.cause() instanceof BucketNotFoundDuringLoadException);
}
}
} finally {
provider.shutdown().block();
}
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderIntegrationTest method openBucketAndCloseFromOneSeed.
/**
* This is the simplest "good" case, just fetch a config that should be good to load.
*/
@Test
void openBucketAndCloseFromOneSeed() {
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().build();
core = Core.create(environment, authenticator(), seeds);
String bucketName = config().bucketname();
ConfigurationProvider provider = new DefaultConfigurationProvider(core, seeds);
openAndClose(bucketName, provider);
provider.shutdown().block();
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method updateSeedNodeList.
/**
* Helper method to take the current config and update the seed node list with the latest topology.
*
* <p>If we have a global config it is used for simplicity reasons. Otherwise we iterate the configs and collect
* all the nodes to build the list.</p>
*/
private void updateSeedNodeList() {
ClusterConfig config = currentConfig;
boolean tlsEnabled = core.context().environment().securityConfig().tlsEnabled();
if (config.globalConfig() != null) {
Set<SeedNode> seedNodes = unmodifiableSet(config.globalConfig().portInfos().stream().map(ni -> {
Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslPorts() : ni.ports();
if (!ports.containsKey(ServiceType.KV)) {
// We only want seed nodes where the KV service is enabled
return null;
}
return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
}).filter(Objects::nonNull).collect(Collectors.toSet()));
if (!seedNodes.isEmpty()) {
eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
setSeedNodes(seedNodes);
}
return;
}
Set<SeedNode> seedNodes = unmodifiableSet(config.bucketConfigs().values().stream().flatMap(bc -> bc.nodes().stream()).map(ni -> {
Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslServices() : ni.services();
if (!ports.containsKey(ServiceType.KV)) {
// We only want seed nodes where the KV service is enabled
return null;
}
return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
}).filter(Objects::nonNull).collect(Collectors.toSet()));
if (!seedNodes.isEmpty()) {
eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
setSeedNodes(seedNodes);
}
}
use of com.couchbase.client.core.env.SeedNode in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProviderTest method forceDefaultModeIfDefault.
@Test
void forceDefaultModeIfDefault() {
Core core = mock(Core.class);
CoreEnvironment environment = CoreEnvironment.builder().ioConfig(IoConfig.networkResolution(NetworkResolution.DEFAULT)).build();
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(Optional.empty(), ctx.alternateAddress());
environment.shutdown();
}
Aggregations