Search in sources :

Example 1 with ChannelOutboundHandlerAdapter

use of com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandlerAdapter in project couchbase-jvm-clients by couchbase.

the class BaseEndpointTest method emitsEventOnFailedDisconnect.

/**
 * If the disconnect failed for some reason, make sure the proper warning event
 * is raised and captured.
 */
@Test
void emitsEventOnFailedDisconnect() {
    final Throwable expectedCause = new Exception("something failed");
    EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {

        @Override
        public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
            promise.tryFailure(expectedCause);
        }
    });
    InstrumentedEndpoint endpoint = connectSuccessfully(channel);
    endpoint.disconnect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
    assertEquals(2, eventBus.publishedEvents().size());
    assertTrue(eventBus.publishedEvents().get(0) instanceof EndpointConnectedEvent);
    EndpointDisconnectionFailedEvent event = (EndpointDisconnectionFailedEvent) eventBus.publishedEvents().get(1);
    assertEquals(expectedCause, event.cause());
    assertEquals(Event.Severity.WARN, event.severity());
}
Also used : EndpointDisconnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ChannelOutboundHandlerAdapter(com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandlerAdapter) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ChannelPromise(com.couchbase.client.core.deps.io.netty.channel.ChannelPromise) ChannelException(com.couchbase.client.core.deps.io.netty.channel.ChannelException) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

EndpointConnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent)1 EndpointDisconnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent)1 ChannelException (com.couchbase.client.core.deps.io.netty.channel.ChannelException)1 ChannelHandlerContext (com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (com.couchbase.client.core.deps.io.netty.channel.ChannelPromise)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 Test (org.junit.jupiter.api.Test)1