Search in sources :

Example 26 with Core

use of com.couchbase.client.core.Core 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));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Arrays(java.util.Arrays) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) SeedNode(com.couchbase.client.core.env.SeedNode) ClusterType(com.couchbase.client.test.ClusterType) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ConfigException(com.couchbase.client.core.error.ConfigException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) Set(java.util.Set) Event(com.couchbase.client.core.cnc.Event) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) BucketNotFoundDuringLoadException(com.couchbase.client.core.error.BucketNotFoundDuringLoadException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) Services(com.couchbase.client.test.Services) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) Optional(java.util.Optional) Core(com.couchbase.client.core.Core) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) Collections(java.util.Collections) SeedNode(com.couchbase.client.core.env.SeedNode) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) HashSet(java.util.HashSet) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with Core

use of com.couchbase.client.core.Core 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();
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Arrays(java.util.Arrays) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) SeedNode(com.couchbase.client.core.env.SeedNode) ClusterType(com.couchbase.client.test.ClusterType) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ConfigException(com.couchbase.client.core.error.ConfigException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) Set(java.util.Set) Event(com.couchbase.client.core.cnc.Event) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) BucketNotFoundDuringLoadException(com.couchbase.client.core.error.BucketNotFoundDuringLoadException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) Services(com.couchbase.client.test.Services) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) Optional(java.util.Optional) Core(com.couchbase.client.core.Core) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) Collections(java.util.Collections) SeedNode(com.couchbase.client.core.env.SeedNode) ConfigException(com.couchbase.client.core.error.ConfigException) BucketNotFoundDuringLoadException(com.couchbase.client.core.error.BucketNotFoundDuringLoadException) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) Event(com.couchbase.client.core.cnc.Event) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) HashSet(java.util.HashSet) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with Core

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

the class ClusterManagerBucketLoaderIntegrationTest method loadConfigViaClusterManagerHttp.

/**
 * This is a very simplistic test that makes sure that we can "round trip" in the
 * {@link ClusterManagerBucketLoader} by grabbing a JSON decodable config through the full stack.
 */
@Test
// @Disabled
void loadConfigViaClusterManagerHttp() {
    TestNodeConfig config = config().firstNodeWith(Services.MANAGER).get();
    Core core = Core.create(env, authenticator(), seedNodes());
    ClusterManagerBucketLoader loader = new ClusterManagerBucketLoader(core);
    int port = config.ports().get(Services.MANAGER);
    ProposedBucketConfigContext ctx = loader.load(new NodeIdentifier(config.hostname(), port), port, config().bucketname(), Optional.empty()).block();
    BucketConfig loaded = BucketConfigParser.parse(ctx.config(), env, ctx.origin());
    assertNotNull(loaded);
    assertEquals(config().bucketname(), loaded.name());
    core.shutdown().block();
}
Also used : TestNodeConfig(com.couchbase.client.test.TestNodeConfig) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) BucketConfig(com.couchbase.client.core.config.BucketConfig) Core(com.couchbase.client.core.Core) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with Core

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

the class ClusterManagerBucketRefresherIntegrationTest method streamsNewConfigurations.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void streamsNewConfigurations() {
    Core core = Core.create(env, authenticator(), seedNodes());
    ProposedBucketConfigInspectingProvider inspectingProvider = new ProposedBucketConfigInspectingProvider(core.configurationProvider());
    ClusterManagerBucketRefresher refresher = new ClusterManagerBucketRefresher(inspectingProvider, core);
    core.openBucket(config().bucketname());
    waitUntilCondition(() -> core.clusterConfig().hasClusterOrBucketConfig());
    refresher.register(config().bucketname()).block();
    waitUntilCondition(() -> !inspectingProvider.proposedConfigs().isEmpty());
    ProposedBucketConfigContext proposed = inspectingProvider.proposedConfigs().get(0).proposedConfig();
    assertEquals(config().bucketname(), proposed.bucketName());
    assertNotNull(proposed.config());
    refresher.shutdown().block();
    core.shutdown().block();
}
Also used : ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) Core(com.couchbase.client.core.Core) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) Test(org.junit.jupiter.api.Test) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest)

Example 30 with Core

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

the class ClusterManagerBucketRefresher method registerStream.

/**
 * Registers the given bucket name with the http stream.
 *
 * <p>Note that this method deliberately subscribes "out of band" and not being flatMapped into the
 * {@link #register(String)} return value. The idea is that the flux config subscription keeps on going
 * forever until specifically unsubscribed through either {@link #deregister(String)} or {@link #shutdown()}.</p>
 *
 * @param ctx the core context to use.
 * @param name the name of the bucket.
 * @return once registered, returns the disposable so it can be later used to deregister.
 */
private Disposable registerStream(final CoreContext ctx, final String name) {
    return Mono.defer(() -> {
        BucketConfigStreamingRequest request = new BucketConfigStreamingRequest(ctx.environment().timeoutConfig().managementTimeout(), ctx, BestEffortRetryStrategy.INSTANCE, name, ctx.authenticator());
        core.send(request);
        return Reactor.wrap(request, request.response(), true);
    }).flux().flatMap(res -> {
        if (res.status().success()) {
            return res.configs().map(config -> new ProposedBucketConfigContext(name, config, res.address()));
        } else {
            eventBus.publish(new BucketConfigRefreshFailedEvent(core.context(), BucketConfigRefreshFailedEvent.RefresherType.MANAGER, BucketConfigRefreshFailedEvent.Reason.INDIVIDUAL_REQUEST_FAILED, Optional.of(res)));
            // and retry the whole thing
            return Flux.error(new ConfigException());
        }
    }).doOnError(e -> eventBus.publish(new BucketConfigRefreshFailedEvent(core.context(), BucketConfigRefreshFailedEvent.RefresherType.MANAGER, BucketConfigRefreshFailedEvent.Reason.STREAM_FAILED, Optional.of(e)))).doOnComplete(() -> {
        eventBus.publish(new BucketConfigRefreshFailedEvent(core.context(), BucketConfigRefreshFailedEvent.RefresherType.MANAGER, BucketConfigRefreshFailedEvent.Reason.STREAM_CLOSED, Optional.empty()));
        // handled in the retryWhen below.
        throw new ConfigException();
    }).retryWhen(Retry.any().exponentialBackoff(Duration.ofMillis(32), Duration.ofMillis(4096)).toReactorRetry()).subscribe(provider::proposeBucketConfig);
}
Also used : Disposable(reactor.core.Disposable) Reactor(com.couchbase.client.core.Reactor) Retry(com.couchbase.client.core.retry.reactor.Retry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BestEffortRetryStrategy(com.couchbase.client.core.retry.BestEffortRetryStrategy) Mono(reactor.core.publisher.Mono) BucketConfigStreamingRequest(com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest) Flux(reactor.core.publisher.Flux) EventBus(com.couchbase.client.core.cnc.EventBus) CoreContext(com.couchbase.client.core.CoreContext) Duration(java.time.Duration) Map(java.util.Map) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) ConfigException(com.couchbase.client.core.error.ConfigException) Optional(java.util.Optional) BucketConfigRefreshFailedEvent(com.couchbase.client.core.cnc.events.config.BucketConfigRefreshFailedEvent) Core(com.couchbase.client.core.Core) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) ConfigException(com.couchbase.client.core.error.ConfigException) BucketConfigRefreshFailedEvent(com.couchbase.client.core.cnc.events.config.BucketConfigRefreshFailedEvent) BucketConfigStreamingRequest(com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest)

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