Search in sources :

Example 1 with SimpleEventBus

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

the class TransportEncryptionIntegrationTest method failsIfWrongCertPresent.

@Test
@SuppressWarnings("unchecked")
void failsIfWrongCertPresent() {
    SimpleEventBus eventBus = new SimpleEventBus(true);
    CoreEnvironment env = secureEnvironment(SecurityConfig.enableTls(true).trustCertificates(mock(List.class)), eventBus);
    Core core = Core.create(env, authenticator(), secureSeeds());
    try {
        core.openBucket(config().bucketname());
        waitUntilCondition(() -> {
            boolean hasEndpointConnectFailedEvent = false;
            boolean hasSecureConnectionFailedEvent = false;
            for (Event event : eventBus.publishedEvents()) {
                if (event instanceof EndpointConnectionFailedEvent) {
                    hasEndpointConnectFailedEvent = true;
                }
                if (event instanceof SecureConnectionFailedEvent) {
                    hasSecureConnectionFailedEvent = true;
                }
            }
            return hasEndpointConnectFailedEvent && hasSecureConnectionFailedEvent;
        });
    } finally {
        core.shutdown().block();
        env.shutdown();
    }
}
Also used : CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) SecureConnectionFailedEvent(com.couchbase.client.core.cnc.events.io.SecureConnectionFailedEvent) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) SecureConnectionFailedEvent(com.couchbase.client.core.cnc.events.io.SecureConnectionFailedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) Event(com.couchbase.client.core.cnc.Event) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleEventBus

use of com.couchbase.client.core.cnc.SimpleEventBus 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 3 with SimpleEventBus

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

the class BaseEndpointIntegrationTest method beforeEach.

@BeforeEach
void beforeEach() {
    eventBus = new SimpleEventBus(true);
    env = environment().eventBus(eventBus).build();
    eventLoopGroup = new DefaultEventLoopGroup();
}
Also used : SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) DefaultEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.DefaultEventLoopGroup) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SimpleEventBus

use of com.couchbase.client.core.cnc.SimpleEventBus 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 5 with SimpleEventBus

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

the class AbstractKeyValueEmbeddedChannelTest method beforeEach.

@BeforeEach
protected void beforeEach() {
    channel = new EmbeddedChannel();
    eventBus = new SimpleEventBus(true);
}
Also used : SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)25 Core (com.couchbase.client.core.Core)16 Test (org.junit.jupiter.api.Test)14 CoreContext (com.couchbase.client.core.CoreContext)13 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)12 Event (com.couchbase.client.core.cnc.Event)9 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)7 Authenticator (com.couchbase.client.core.env.Authenticator)7 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)6 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)6 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)5 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)4 HostAndPort (com.couchbase.client.core.util.HostAndPort)4 ClusterType (com.couchbase.client.test.ClusterType)4 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)4 Util.waitUntilCondition (com.couchbase.client.test.Util.waitUntilCondition)4 Duration (java.time.Duration)4 List (java.util.List)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4