Search in sources :

Example 6 with SeedNode

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());
}
Also used : SeedNode(com.couchbase.client.core.env.SeedNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with SeedNode

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());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeedNode(com.couchbase.client.core.env.SeedNode) PasswordAuthenticator(com.couchbase.client.core.env.PasswordAuthenticator) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with SeedNode

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"));
    }
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) SeedNode(com.couchbase.client.core.env.SeedNode) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with SeedNode

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();
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) SeedNode(com.couchbase.client.core.env.SeedNode) Core(com.couchbase.client.core.Core) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with SeedNode

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

Aggregations

SeedNode (com.couchbase.client.core.env.SeedNode)18 HashSet (java.util.HashSet)11 Test (org.junit.jupiter.api.Test)11 Core (com.couchbase.client.core.Core)10 Optional (java.util.Optional)7 CoreContext (com.couchbase.client.core.CoreContext)6 Duration (java.time.Duration)6 Set (java.util.Set)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)5 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)5 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (com.couchbase.client.core.cnc.Event)4 BucketOpenRetriedEvent (com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent)4 AlreadyShutdownException (com.couchbase.client.core.error.AlreadyShutdownException)4 BucketNotFoundDuringLoadException (com.couchbase.client.core.error.BucketNotFoundDuringLoadException)4 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)3 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)3