Search in sources :

Example 6 with ServiceContext

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

the class BaseEndpointTest method beforeEach.

@BeforeEach
void beforeEach() {
    eventLoopGroup = new NioEventLoopGroup(1);
    eventBus = new SimpleEventBus(true, Collections.singletonList(EndpointStateChangedEvent.class));
    environment = CoreEnvironment.builder().eventBus(eventBus).build();
    CoreContext coreContext = new CoreContext(mock(Core.class), 1, environment, authenticator);
    ctx = new ServiceContext(coreContext, LOCALHOST, 1234, ServiceType.KV, Optional.empty());
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ServiceContext(com.couchbase.client.core.service.ServiceContext) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) NioEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.nio.NioEventLoopGroup) Core(com.couchbase.client.core.Core) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ServiceContext

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

the class BaseEndpointTest method disconnectDuringRetry.

/**
 * Make sure that while we are retrying and a disconnect event comes along, we stop
 * retrying and end up in the disconnected state right away.
 */
@Test
void disconnectDuringRetry() {
    SimpleEventBus eventBus = new SimpleEventBus(true, Collections.singletonList(EndpointStateChangedEvent.class));
    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);
        endpoint.disconnect();
        waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
        waitUntilCondition(() -> eventBus.publishedEvents().size() >= 4);
        int warn = 0;
        int debug = 0;
        for (Event event : eventBus.publishedEvents()) {
            if (event.severity() == Event.Severity.WARN) {
                warn++;
                assertTrue(event instanceof EndpointConnectionFailedEvent);
            } else if (event.severity() == Event.Severity.DEBUG) {
                debug++;
                assertTrue(event instanceof EndpointConnectionAbortedEvent);
            } else {
                throw new RuntimeException("Unexpected Event: " + event);
            }
        }
        assertEquals(3, warn);
        assertEquals(1, debug);
    } finally {
        environment.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) EndpointStateChangedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent) CompletableFuture(java.util.concurrent.CompletableFuture) EndpointConnectionAbortedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent) 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) Test(org.junit.jupiter.api.Test)

Aggregations

CoreContext (com.couchbase.client.core.CoreContext)7 ServiceContext (com.couchbase.client.core.service.ServiceContext)7 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)4 Core (com.couchbase.client.core.Core)3 Event (com.couchbase.client.core.cnc.Event)3 Channel (com.couchbase.client.core.deps.io.netty.channel.Channel)3 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)3 Test (org.junit.jupiter.api.Test)3 EndpointConnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent)2 EndpointConnectionAbortedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent)2 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)2 EndpointConnectionIgnoredEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent)2 EndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent)2 EndpointDisconnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent)2 EndpointStateChangedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent)2 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 UnexpectedEndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.UnexpectedEndpointDisconnectedEvent)1