Search in sources :

Example 11 with CoreContext

use of com.couchbase.client.core.CoreContext in project couchbase-jvm-clients by couchbase.

the class DefaultConfigurationProviderTest method ignoreProposedConfigWithLowerOrEqualRev.

@Test
void ignoreProposedConfigWithLowerOrEqualRev() {
    Core core = mock(Core.class);
    when(core.context()).thenReturn(new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class)));
    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());
    String bucket = "default";
    String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
    assertEquals(1, configsPushed.get());
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
    assertEquals(1, configsPushed.get());
    assertFalse(provider.config().bucketConfigs().isEmpty());
    assertEquals(1073, provider.config().bucketConfig("default").rev());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with CoreContext

use of com.couchbase.client.core.CoreContext in project couchbase-jvm-clients by couchbase.

the class DefaultConfigurationProviderTest method ignoreProposedConfigOnceShutdown.

@Test
void ignoreProposedConfigOnceShutdown() {
    Core core = mock(Core.class);
    when(core.context()).thenReturn(new CoreContext(core, 1, ENVIRONMENT, mock(Authenticator.class)));
    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());
    String bucket = "default";
    String config = readResource("config_with_external.json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
    assertEquals(1, configsPushed.get());
    String newConfig = readResource("config_with_external_higher_rev.json", DefaultConfigurationProviderTest.class);
    provider.shutdown().block();
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, newConfig, ORIGIN));
    assertEquals(3, configsPushed.get());
    assertTrue(provider.config().bucketConfigs().isEmpty());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with CoreContext

use of com.couchbase.client.core.CoreContext 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 14 with CoreContext

use of com.couchbase.client.core.CoreContext 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 15 with CoreContext

use of com.couchbase.client.core.CoreContext 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)

Aggregations

CoreContext (com.couchbase.client.core.CoreContext)52 Core (com.couchbase.client.core.Core)46 Test (org.junit.jupiter.api.Test)25 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)22 Authenticator (com.couchbase.client.core.env.Authenticator)17 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)14 BeforeEach (org.junit.jupiter.api.BeforeEach)13 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 ArrayList (java.util.ArrayList)10 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)9 HostAndPort (com.couchbase.client.core.util.HostAndPort)9 List (java.util.List)8 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)7 ServiceContext (com.couchbase.client.core.service.ServiceContext)7 Duration (java.time.Duration)7 Optional (java.util.Optional)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 SeedNode (com.couchbase.client.core.env.SeedNode)6 Event (com.couchbase.client.core.cnc.Event)5