Home / Function/ testHandshakeFailedByWriteBeforeChannelActive() — netty Function Reference

testHandshakeFailedByWriteBeforeChannelActive() — netty Function Reference

Architecture documentation for the testHandshakeFailedByWriteBeforeChannelActive() function in SslHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4066b3cf_6998_4847_3e05_5d046722b5e6["testHandshakeFailedByWriteBeforeChannelActive()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e["SslHandlerTest"]
  4066b3cf_6998_4847_3e05_5d046722b5e6 -->|defined in| adaf7dc7_94e2_152f_ffdb_453fdaa4f25e
  style 4066b3cf_6998_4847_3e05_5d046722b5e6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java lines 835–903

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void testHandshakeFailedByWriteBeforeChannelActive() throws Exception {
        final SslContext sslClientCtx = SslContextBuilder.forClient()
                                                         .protocols(SslProtocols.SSL_v3)
                                                         .trustManager(InsecureTrustManagerFactory.INSTANCE)
                                                         .sslProvider(SslProvider.JDK).build();

        EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
        Channel sc = null;
        Channel cc = null;
        final CountDownLatch activeLatch = new CountDownLatch(1);
        final AtomicReference<AssertionError> errorRef = new AtomicReference<AssertionError>();
        final SslHandler sslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT);
        try {
            sc = new ServerBootstrap()
                    .group(group)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ChannelInboundHandlerAdapter())
                    .bind(new InetSocketAddress(0)).syncUninterruptibly().channel();

            cc = new Bootstrap()
                    .group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel ch) throws Exception {
                            ch.pipeline().addLast(sslHandler);
                            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                                @Override
                                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
                                        throws Exception {
                                    if (cause instanceof AssertionError) {
                                        errorRef.set((AssertionError) cause);
                                    }
                                }

                                @Override
                                public void channelActive(ChannelHandlerContext ctx) throws Exception {
                                    activeLatch.countDown();
                                }
                            });
                        }
                    }).connect(sc.localAddress()).addListener((ChannelFutureListener) future -> {
                        // Write something to trigger the handshake before fireChannelActive is called.
                        future.channel().writeAndFlush(wrappedBuffer(new byte [] { 1, 2, 3, 4 }));
                    }).syncUninterruptibly().channel();

            // Ensure there is no AssertionError thrown by having the handshake failed by the writeAndFlush(...) before
            // channelActive(...) was called. Let's first wait for the activeLatch countdown to happen and after this
            // check if we saw and AssertionError (even if we timed out waiting).
            activeLatch.await(5, TimeUnit.SECONDS);
            AssertionError error = errorRef.get();
            if (error != null) {
                throw error;
            }
            assertInstanceOf(SSLException.class, sslHandler.handshakeFuture().await().cause());
        } finally {
            if (cc != null) {
                cc.close().syncUninterruptibly();
            }
            if (sc != null) {
                sc.close().syncUninterruptibly();
            }
            group.shutdownGracefully();

            ReferenceCountUtil.release(sslClientCtx);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testHandshakeFailedByWriteBeforeChannelActive() do?
testHandshakeFailedByWriteBeforeChannelActive() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java.
Where is testHandshakeFailedByWriteBeforeChannelActive() defined?
testHandshakeFailedByWriteBeforeChannelActive() is defined in handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java at line 835.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free