Search in sources :

Example 6 with SimpleEventBus

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

the class DefaultConfigurationProviderTest method setup.

@BeforeAll
static void setup() {
    EVENT_BUS = new SimpleEventBus(true);
    ENVIRONMENT = CoreEnvironment.builder().eventBus(EVENT_BUS).build();
}
Also used : SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with SimpleEventBus

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

the class CoreTest method beforeAll.

@BeforeAll
static void beforeAll() {
    EVENT_BUS = new SimpleEventBus(true);
    ENV = CoreEnvironment.builder().eventBus(EVENT_BUS).build();
}
Also used : SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with SimpleEventBus

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

the class WaitUntilReadyIntegrationTest method beforeAll.

@BeforeAll
static void beforeAll() {
    eventBus = new SimpleEventBus(true);
    environment = env -> env.eventBus(eventBus);
    cluster = createCluster(environment);
}
Also used : SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with SimpleEventBus

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

the class ClusterManagerBucketRefresherTest method beforeEach.

@BeforeEach
void beforeEach() {
    SimpleEventBus eventBus = new SimpleEventBus(true);
    env = CoreEnvironment.builder().eventBus(eventBus).build();
    CoreContext coreContext = mock(CoreContext.class);
    core = mock(Core.class);
    when(core.context()).thenReturn(coreContext);
    when(coreContext.environment()).thenReturn(env);
    ConfigurationProvider provider = mock(ConfigurationProvider.class);
    refresher = new ClusterManagerBucketRefresher(provider, core);
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Core(com.couchbase.client.core.Core) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with SimpleEventBus

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

the class BaseEndpointTest method retryOnTimeoutUntilEventuallyConnected.

/**
 * This test fakes a situation where the channel future from netty would simply not return
 * at all and time out, and the client would resubscribe. Then at some future attempt the
 * future returns fine and we should end up in a connected state and ready to go.
 */
@Test
void retryOnTimeoutUntilEventuallyConnected() {
    SimpleEventBus eventBus = new SimpleEventBus(true);
    CoreEnvironment env = CoreEnvironment.builder().eventBus(eventBus).timeoutConfig(TimeoutConfig.connectTimeout(Duration.ofMillis(10))).build();
    CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, authenticator);
    ServiceContext ctx = new ServiceContext(coreContext, LOCALHOST, 1234, ServiceType.KV, Optional.empty());
    try {
        final CompletableFuture<Channel> cf = new CompletableFuture<>();
        InstrumentedEndpoint endpoint = InstrumentedEndpoint.create(eventLoopGroup, ctx, () -> Mono.fromFuture(cf));
        endpoint.connect();
        waitUntilCondition(() -> eventBus.publishedEvents().size() >= 3);
        EmbeddedChannel channel = new EmbeddedChannel();
        cf.complete(channel);
        waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
        assertTrue(eventBus.publishedEvents().size() >= 3);
        boolean failedFound = false;
        boolean successFound = false;
        for (Event event : eventBus.publishedEvents()) {
            if (event instanceof EndpointConnectionFailedEvent) {
                assertEquals(Event.Severity.WARN, event.severity());
                assertEquals(Duration.ofMillis(10), event.duration());
                failedFound = true;
            } else if (event instanceof EndpointConnectedEvent) {
                assertEquals(Event.Severity.DEBUG, event.severity());
                assertTrue(event.duration().toNanos() > 0);
                successFound = true;
            }
        }
        assertTrue(failedFound);
        assertTrue(successFound);
    } finally {
        env.shutdown();
    }
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ServiceContext(com.couchbase.client.core.service.ServiceContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) CompletableFuture(java.util.concurrent.CompletableFuture) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EndpointDisconnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) EndpointConnectionAbortedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) EndpointConnectionIgnoredEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent) Event(com.couchbase.client.core.cnc.Event) EndpointStateChangedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent) EndpointDisconnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) Core(com.couchbase.client.core.Core) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) Test(org.junit.jupiter.api.Test)

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