use of com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext 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());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method propagatesChannelActiveAfterSendingInitialRequest.
/**
* This test makes sure that after the initial request is sent, the channel active signal is
* propagated so that we do not regress bootstrap pipelining functionality.
*/
@Test
void propagatesChannelActiveAfterSendingInitialRequest() {
final ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
final AtomicBoolean channelActiveFired = new AtomicBoolean();
channel.pipeline().addLast(handler).addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channelActiveFired.set(true);
}
});
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
waitUntilCondition(channelActiveFired::get);
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method propagateConnectFailureFromDownstream.
/**
* This test verifies that if a downstream promise fails that the error
* is propagated through the captured promise.
*/
@Test
void propagateConnectFailureFromDownstream() {
final Exception connectException = new Exception("I failed");
ChannelDuplexHandler failingHandler = new ChannelDuplexHandler() {
@Override
public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
promise.setFailure(connectException);
}
};
FeatureNegotiatingHandler handler = new FeatureNegotiatingHandler(endpointContext, Collections.singleton(ServerFeature.TRACING));
channel.pipeline().addLast(failingHandler).addLast(handler);
ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
use of com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method propagatesChannelActiveAfterSendingInitialRequest.
/**
* This test makes sure that after the initial request is sent, the channel active signal is
* propagated so that we do not regress bootstrap pipelining functionality.
*/
@Test
void propagatesChannelActiveAfterSendingInitialRequest() {
final FeatureNegotiatingHandler handler = new FeatureNegotiatingHandler(endpointContext, Collections.singleton(ServerFeature.SELECT_BUCKET));
final AtomicBoolean channelActiveFired = new AtomicBoolean();
channel.pipeline().addLast(handler).addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channelActiveFired.set(true);
}
});
assertEquals(handler, channel.pipeline().get(FeatureNegotiatingHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
waitUntilCondition(channelActiveFired::get);
}
Aggregations