Search in sources :

Example 1 with ChannelHandlerContext

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

the class ErrorMapLoadingHandlerTest 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);
        }
    };
    ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
    channel.pipeline().addLast(failingHandler).addLast(handler);
    ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) ChannelDuplexHandler(com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ChannelPromise(com.couchbase.client.core.deps.io.netty.channel.ChannelPromise) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 2 with ChannelHandlerContext

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

the class SaslListMechanismsHandlerTest 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 SaslListMechanismsHandler handler = new SaslListMechanismsHandler(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(SaslListMechanismsHandler.class));
    channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    channel.pipeline().fireChannelActive();
    channel.runPendingTasks();
    waitUntilCondition(channelActiveFired::get);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InetSocketAddress(java.net.InetSocketAddress) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 3 with ChannelHandlerContext

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

the class SaslListMechanismsHandlerTest 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);
        }
    };
    SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
    channel.pipeline().addLast(failingHandler).addLast(handler);
    ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) ChannelDuplexHandler(com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ChannelPromise(com.couchbase.client.core.deps.io.netty.channel.ChannelPromise) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 4 with ChannelHandlerContext

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

the class BaseEndpointIntegrationTest method startLocalServer.

private LocalServerController startLocalServer(final DefaultEventLoopGroup eventLoopGroup) {
    final LocalServerController localServerController = new LocalServerController();
    ServerBootstrap bootstrap = new ServerBootstrap().group(eventLoopGroup).localAddress(new LocalAddress("server")).childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            ch.pipeline().addLast(new SimpleChannelInboundHandler<ByteBuf>() {

                @Override
                protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
                }

                @Override
                public void channelActive(ChannelHandlerContext ctx) {
                    localServerController.channel.set(ctx.channel());
                    localServerController.connectAttempts.incrementAndGet();
                    ctx.fireChannelActive();
                }
            });
        }
    }).channel(LocalServerChannel.class);
    bootstrap.bind().awaitUninterruptibly();
    return localServerController;
}
Also used : LocalAddress(com.couchbase.client.core.deps.io.netty.channel.local.LocalAddress) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) LocalServerChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalServerChannel) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ChannelInitializer(com.couchbase.client.core.deps.io.netty.channel.ChannelInitializer) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) ServerBootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.ServerBootstrap)

Example 5 with ChannelHandlerContext

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

the class SelectBucketHandlerTest 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);
        }
    };
    SelectBucketHandler handler = new SelectBucketHandler(endpointContext, "bucket");
    channel.pipeline().addLast(failingHandler).addLast(handler);
    ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    assertEquals(connectException, connect.awaitUninterruptibly().cause());
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) ChannelDuplexHandler(com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) ChannelPromise(com.couchbase.client.core.deps.io.netty.channel.ChannelPromise) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelHandlerContext (com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext)9 Test (org.junit.jupiter.api.Test)8 InetSocketAddress (java.net.InetSocketAddress)7 ChannelPromise (com.couchbase.client.core.deps.io.netty.channel.ChannelPromise)5 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)4 ChannelDuplexHandler (com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler)4 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)4 SocketAddress (java.net.SocketAddress)4 TimeoutException (java.util.concurrent.TimeoutException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EndpointConnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent)1 EndpointDisconnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent)1 ServerBootstrap (com.couchbase.client.core.deps.io.netty.bootstrap.ServerBootstrap)1 Channel (com.couchbase.client.core.deps.io.netty.channel.Channel)1 ChannelException (com.couchbase.client.core.deps.io.netty.channel.ChannelException)1 ChannelInitializer (com.couchbase.client.core.deps.io.netty.channel.ChannelInitializer)1 ChannelOutboundHandlerAdapter (com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandlerAdapter)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 LocalAddress (com.couchbase.client.core.deps.io.netty.channel.local.LocalAddress)1