Home / Function/ testCloseOnHandshakeFailure() — netty Function Reference

testCloseOnHandshakeFailure() — netty Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java lines 753–817

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void testCloseOnHandshakeFailure() throws Exception {
        CertificateBuilder ca = new CertificateBuilder()
                .subject("cn=localhost")
                .setIsCertificateAuthority(true);

        X509Bundle cert = ca.buildSelfSigned();
        final SslContext sslServerCtx = SslContextBuilder.forServer(
                cert.getKeyPair().getPrivate(), cert.getCertificatePath()).build();
        final SslContext sslClientCtx = SslContextBuilder.forClient()
                .trustManager(ca.buildSelfSigned().toTrustManagerFactory())
                .build();

        EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory());
        Channel sc = null;
        Channel cc = null;
        try {
            LocalAddress address = new LocalAddress(getClass().getSimpleName() + ".testCloseOnHandshakeFailure");
            ServerBootstrap sb = new ServerBootstrap()
                    .group(group)
                    .channel(LocalServerChannel.class)
                    .childHandler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel ch) {
                            ch.pipeline().addLast(sslServerCtx.newHandler(ch.alloc()));
                        }
                    });
            sc = sb.bind(address).syncUninterruptibly().channel();

            final AtomicReference<SslHandler> sslHandlerRef = new AtomicReference<SslHandler>();
            Bootstrap b = new Bootstrap()
                    .group(group)
                    .channel(LocalChannel.class)
                    .handler(new ChannelInitializer<Channel>() {
                        @Override
                        protected void initChannel(Channel ch) {
                            SslHandler handler = sslClientCtx.newHandler(ch.alloc());

                            // We propagate the SslHandler via an AtomicReference to the outer-scope as using
                            // pipeline.get(...) may return null if the pipeline was teared down by the time we call it.
                            // This will happen if the channel was closed in the meantime.
                            sslHandlerRef.set(handler);
                            ch.pipeline().addLast(handler);
                        }
                    });
            cc = b.connect(sc.localAddress()).syncUninterruptibly().channel();
            SslHandler handler = sslHandlerRef.get();
            handler.handshakeFuture().awaitUninterruptibly();
            assertFalse(handler.handshakeFuture().isSuccess());

            cc.closeFuture().syncUninterruptibly();
        } finally {
            if (cc != null) {
                cc.close().syncUninterruptibly();
            }
            if (sc != null) {
                sc.close().syncUninterruptibly();
            }
            group.shutdownGracefully();

            ReferenceCountUtil.release(sslServerCtx);
            ReferenceCountUtil.release(sslClientCtx);
        }
    }

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free