Search in sources :

Example 36 with Core

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

the class DefaultConfigurationProviderTest method applyBucketConfigWithRevOrEpoch.

@ParameterizedTest
@CsvSource({ "config_lower_rev_no_epoch,1,0,config_higher_rev_no_epoch,2,0", "config_lower_rev_no_epoch,1,0,config_lower_rev_higher_epoch,1,2", "config_lower_rev_lower_epoch,1,1,config_lower_rev_higher_epoch,1,2", "config_higher_rev_lower_epoch,2,1,config_lower_rev_higher_epoch,1,2" })
void applyBucketConfigWithRevOrEpoch(String oldConfigFile, long oldRev, long oldEpoch, String newConfigFile, long newRev, long newEpoch) {
    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 bucket = "travel-sample";
    String config = readResource(oldConfigFile + ".json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
    assertEquals(oldRev, provider.config().bucketConfig(bucket).rev());
    assertEquals(oldEpoch, provider.config().bucketConfig(bucket).revEpoch());
    String newConfig = readResource(newConfigFile + ".json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, newConfig, ORIGIN));
    assertEquals(newRev, provider.config().bucketConfig(bucket).rev());
    assertEquals(newEpoch, provider.config().bucketConfig(bucket).revEpoch());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) Core(com.couchbase.client.core.Core) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with Core

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

the class DefaultConfigurationProviderTest method currentConfigIsReplayedToLateSubscriber.

@Test
void currentConfigIsReplayedToLateSubscriber() {
    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);
    provider.configs().blockFirst(Duration.ofSeconds(10));
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) 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 38 with Core

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

the class DefaultConfigurationProviderTest method canUpdateConfigWithNewRev.

@Test
void canUpdateConfigWithNewRev() {
    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.proposeBucketConfig(new ProposedBucketConfigContext(bucket, newConfig, ORIGIN));
    assertEquals(2, configsPushed.get());
    assertFalse(provider.config().bucketConfigs().isEmpty());
    assertEquals(1888, 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 39 with Core

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

the class DefaultConfigurationProviderTest method ignoresBucketConfigWithOlderRevOrEpoch.

@ParameterizedTest
@CsvSource({ "config_higher_rev_no_epoch,2,0,config_lower_rev_no_epoch", "config_lower_rev_lower_epoch,1,1,config_higher_rev_no_epoch", "config_higher_rev_lower_epoch,2,1,config_lower_rev_lower_epoch", "config_lower_rev_higher_epoch,1,2,config_higher_rev_lower_epoch" })
void ignoresBucketConfigWithOlderRevOrEpoch(String oldConfigFile, long oldRev, long oldEpoch, String newConfigFile) {
    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 bucket = "travel-sample";
    String config = readResource(oldConfigFile + ".json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, config, ORIGIN));
    assertEquals(oldRev, provider.config().bucketConfig(bucket).rev());
    assertEquals(oldEpoch, provider.config().bucketConfig(bucket).revEpoch());
    String newConfig = readResource(newConfigFile + ".json", DefaultConfigurationProviderTest.class);
    provider.proposeBucketConfig(new ProposedBucketConfigContext(bucket, newConfig, ORIGIN));
    assertEquals(oldRev, provider.config().bucketConfig(bucket).rev());
    assertEquals(oldEpoch, provider.config().bucketConfig(bucket).revEpoch());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) Core(com.couchbase.client.core.Core) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with Core

use of com.couchbase.client.core.Core 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();
}
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

Core (com.couchbase.client.core.Core)49 CoreContext (com.couchbase.client.core.CoreContext)31 Test (org.junit.jupiter.api.Test)25 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)17 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Stability (com.couchbase.client.core.annotation.Stability)11 Optional (java.util.Optional)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 BucketConfig (com.couchbase.client.core.config.BucketConfig)10 Authenticator (com.couchbase.client.core.env.Authenticator)10 List (java.util.List)10 Flux (reactor.core.publisher.Flux)10 Mono (reactor.core.publisher.Mono)10 Reactor (com.couchbase.client.core.Reactor)9 SeedNode (com.couchbase.client.core.env.SeedNode)9 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)9 HashSet (java.util.HashSet)9