Search in sources :

Example 6 with Core

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

the class KeyValueBucketRefresherIntegrationTest method pollsForNewConfigs.

@Test
void pollsForNewConfigs() {
    Core core = Core.create(env, authenticator(), seedNodes());
    ProposedBucketConfigInspectingProvider inspectingProvider = new ProposedBucketConfigInspectingProvider(core.configurationProvider());
    KeyValueBucketRefresher refresher = new KeyValueBucketRefresher(inspectingProvider, core) {

        @Override
        protected Duration pollerInterval() {
            // fire quickly to speed up the integration test.
            return Duration.ofMillis(10);
        }
    };
    core.openBucket(config().bucketname());
    refresher.register(config().bucketname()).block();
    long expected = env.ioConfig().configPollInterval().toNanos();
    Util.waitUntilCondition(() -> {
        List<ProposedConfigAndTimestamp> configs = new ArrayList<>(inspectingProvider.proposedConfigs());
        int size = configs.size();
        if (size < 2) {
            // we need at least 2 records to compare
            return false;
        }
        return configs.get(size - 1).nanosSince(configs.get(size - 2)) >= expected;
    });
    refresher.deregister(config().bucketname()).block();
    for (ProposedConfigAndTimestamp configAndTimestamp : inspectingProvider.proposedConfigs()) {
        assertEquals(config().bucketname(), configAndTimestamp.proposedConfig().bucketName());
        assertNotNull(configAndTimestamp.proposedConfig());
    }
    refresher.shutdown().block();
    inspectingProvider.shutdown().block();
}
Also used : ProposedConfigAndTimestamp(com.couchbase.client.core.config.refresher.ProposedBucketConfigInspectingProvider.ProposedConfigAndTimestamp) ArrayList(java.util.ArrayList) Core(com.couchbase.client.core.Core) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with Core

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

the class KeyValueMessageHandlerTest method setup.

@BeforeAll
static void setup() {
    ENV = CoreEnvironment.builder().eventBus(new SimpleEventBus(true)).build();
    Core core = mock(Core.class);
    CoreContext coreContext = new CoreContext(core, 1, ENV, PasswordAuthenticator.create("foo", "bar"));
    ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
    when(configurationProvider.collectionMap()).thenReturn(new CollectionMap());
    when(core.configurationProvider()).thenReturn(configurationProvider);
    CTX = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : HostAndPort(com.couchbase.client.core.util.HostAndPort) CoreContext(com.couchbase.client.core.CoreContext) CollectionMap(com.couchbase.client.core.io.CollectionMap) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Core(com.couchbase.client.core.Core) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with Core

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

the class RequestContextTest method requestCancellation.

@Test
void requestCancellation() {
    Request<?> request = mock(Request.class);
    Core core = mock(Core.class);
    RequestContext ctx = new RequestContext(new CoreContext(core, 1, null, mock(Authenticator.class)), request);
    ctx.cancel();
    verify(request, times(1)).cancel(CancellationReason.CANCELLED_VIA_CONTEXT);
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test)

Example 9 with Core

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

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

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