Search in sources :

Example 1 with TestNodeConfig

use of com.couchbase.client.test.TestNodeConfig in project couchbase-jvm-clients by couchbase.

the class DefaultConfigurationProviderIntegrationTest method openBucketFromSecondValidSeed.

/**
 * Bucket config should also be loaded when the first seed in the list is not available.
 */
@Test
void openBucketFromSecondValidSeed() {
    TestNodeConfig cfg = config().firstNodeWith(Services.KV).get();
    Set<SeedNode> seeds = new HashSet<>(Arrays.asList(SeedNode.create("1.2.3.4"), 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);
    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 2 with TestNodeConfig

use of com.couchbase.client.test.TestNodeConfig 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 3 with TestNodeConfig

use of com.couchbase.client.test.TestNodeConfig in project couchbase-jvm-clients by couchbase.

the class GlobalLoaderIntegrationTest method loadGlobalConfigViaCarrierPublication.

/**
 * This is a very simplistic test that makes sure that we can "round trip" in the
 * {@link GlobalLoader} by grabbing a JSON decodable config through the full stack.
 */
@Test
void loadGlobalConfigViaCarrierPublication() {
    TestNodeConfig config = config().firstNodeWith(Services.KV).get();
    Core core = Core.create(env, authenticator(), seedNodes());
    GlobalLoader loader = new GlobalLoader(core);
    ProposedGlobalConfigContext globalConfigContext = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV)).block();
    assertNotNull(globalConfigContext);
    assertNotNull(globalConfigContext.config());
    core.shutdown().block();
}
Also used : TestNodeConfig(com.couchbase.client.test.TestNodeConfig) ProposedGlobalConfigContext(com.couchbase.client.core.config.ProposedGlobalConfigContext) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) Core(com.couchbase.client.core.Core) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with TestNodeConfig

use of com.couchbase.client.test.TestNodeConfig in project couchbase-jvm-clients by couchbase.

the class KeyValueBucketLoaderIntegrationTest method loadConfigViaCarrierPublication.

/**
 * This is a very simplistic test that makes sure that we can "round trip" in the
 * {@link KeyValueBucketLoader} by grabbing a JSON decodable config through the full stack.
 */
@Test
void loadConfigViaCarrierPublication() {
    TestNodeConfig config = config().firstNodeWith(Services.KV).get();
    Core core = Core.create(env, authenticator(), seedNodes());
    KeyValueBucketLoader loader = new KeyValueBucketLoader(core);
    ProposedBucketConfigContext loaded = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV), config().bucketname(), Optional.empty()).block();
    assertNotNull(loaded);
    assertEquals(config().bucketname(), loaded.bucketName());
    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) Core(com.couchbase.client.core.Core) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with TestNodeConfig

use of com.couchbase.client.test.TestNodeConfig in project couchbase-jvm-clients by couchbase.

the class KeyValueEndpointIntegrationTest method beforeAll.

@BeforeAll
static void beforeAll() {
    TestNodeConfig node = config().nodes().get(0);
    env = environment().build();
    core = Core.create(env, authenticator(), seedNodes());
    serviceContext = new ServiceContext(new CoreContext(core, 1, env, authenticator()), node.hostname(), node.ports().get(Services.KV), ServiceType.KV, Optional.empty());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ServiceContext(com.couchbase.client.core.service.ServiceContext) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

TestNodeConfig (com.couchbase.client.test.TestNodeConfig)25 Test (org.junit.jupiter.api.Test)16 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)15 Core (com.couchbase.client.core.Core)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)6 SeedNode (com.couchbase.client.core.env.SeedNode)5 HashSet (java.util.HashSet)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 Bootstrap (com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap)4 SocketChannel (com.couchbase.client.core.deps.io.netty.channel.socket.SocketChannel)4 NioSocketChannel (com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel)4 NodeIdentifier (com.couchbase.client.core.node.NodeIdentifier)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CoreContext (com.couchbase.client.core.CoreContext)3 Event (com.couchbase.client.core.cnc.Event)3 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)3 BucketOpenRetriedEvent (com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent)3 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)3 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)3