Home / Class/ SslHandlerTest Class — netty Architecture

SslHandlerTest Class — netty Architecture

Architecture documentation for the SslHandlerTest class in SslHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e["SslHandlerTest"]
  95d7e028_ee72_2502_f279_8411001f0ae8["SslHandlerTest.java"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|defined in| 95d7e028_ee72_2502_f279_8411001f0ae8
  2811a98f_8f4d_ac6f_07ea_705d8d6c1727["testNonApplicationDataFailureFailsQueuedWrites()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 2811a98f_8f4d_ac6f_07ea_705d8d6c1727
  3a22f0f6_3628_287f_0969_0c79725f6f43["testNoSslHandshakeEventWhenNoHandshake()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 3a22f0f6_3628_287f_0969_0c79725f6f43
  a6487d43_ea5b_5f43_0acc_16059789f895["testClientHandshakeTimeout()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| a6487d43_ea5b_5f43_0acc_16059789f895
  c3867ffd_40b6_187b_8623_06bc21709d59["testServerHandshakeTimeout()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| c3867ffd_40b6_187b_8623_06bc21709d59
  704ea18e_668d_9dce_0f06_6a89d0ab4d62["SSLEngine()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 704ea18e_668d_9dce_0f06_6a89d0ab4d62
  de3781b8_14ea_faf5_5cf1_a060cadcc2ed["testHandshakeTimeout()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| de3781b8_14ea_faf5_5cf1_a060cadcc2ed
  cc6fe9aa_1e48_294f_0829_e1a8f2a80fc2["testHandshakeAndClosePromiseFailedOnRemoval()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| cc6fe9aa_1e48_294f_0829_e1a8f2a80fc2
  7cdd140b_e838_5f9e_3ed0_a6c7003e46e9["testTruncatedPacket()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 7cdd140b_e838_5f9e_3ed0_a6c7003e46e9
  45f21521_6490_7a8c_6ddd_ec45a857fa2e["testNonByteBufWriteIsReleased()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 45f21521_6490_7a8c_6ddd_ec45a857fa2e
  fbf78b7c_d94d_0fb2_5fb0_16c7afa87b6d["testNonByteBufNotPassThrough()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| fbf78b7c_d94d_0fb2_5fb0_16c7afa87b6d
  098fffee_511d_867f_97d5_836761113930["testIncompleteWriteDoesNotCompletePromisePrematurely()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 098fffee_511d_867f_97d5_836761113930
  98953171_0ed0_62ee_1794_dcc8bb2d806d["testReleaseSslEngine()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| 98953171_0ed0_62ee_1794_dcc8bb2d806d
  f8a971ae_000f_175f_75d9_5cc23152e24c["testIssueReadAfterActiveWriteFlush()"]
  adaf7dc7_94e2_152f_ffdb_453fdaa4f25e -->|method| f8a971ae_000f_175f_75d9_5cc23152e24c

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java lines 108–1900

public class SslHandlerTest {

    private static final Executor DIRECT_EXECUTOR = new Executor() {
        @Override
        public void execute(Runnable command) {
            command.run();
        }
    };

    @Test
    @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
    public void testNonApplicationDataFailureFailsQueuedWrites() throws NoSuchAlgorithmException, InterruptedException {
        final CountDownLatch writeLatch = new CountDownLatch(1);
        final Queue<ChannelPromise> writesToFail = new ConcurrentLinkedQueue<ChannelPromise>();
        SSLEngine engine = newClientModeSSLEngine();
        SslHandler handler = new SslHandler(engine) {
            @Override
            public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                super.write(ctx, msg, promise);
                writeLatch.countDown();
            }
        };
        EmbeddedChannel ch = new EmbeddedChannel(new ChannelDuplexHandler() {
            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
                if (msg instanceof ByteBuf) {
                    if (((ByteBuf) msg).isReadable()) {
                        writesToFail.add(promise);
                    } else {
                        promise.setSuccess();
                    }
                }
                ReferenceCountUtil.release(msg);
            }
        }, handler);

        try {
            final CountDownLatch writeCauseLatch = new CountDownLatch(1);
            final AtomicReference<Throwable> failureRef = new AtomicReference<Throwable>();
            ch.write(Unpooled.wrappedBuffer(new byte[]{1})).addListener(future -> {
                failureRef.compareAndSet(null, future.cause());
                writeCauseLatch.countDown();
            });
            writeLatch.await();

            // Simulate failing the SslHandler non-application writes after there are applications writes queued.
            ChannelPromise promiseToFail;
            while ((promiseToFail = writesToFail.poll()) != null) {
                promiseToFail.setFailure(new RuntimeException("fake exception"));
            }

            writeCauseLatch.await();
            Throwable writeCause = failureRef.get();
            assertNotNull(writeCause);
            assertInstanceOf(SSLException.class, writeCause);
            Throwable cause = handler.handshakeFuture().cause();
            assertNotNull(cause);
            assertInstanceOf(SSLException.class, cause);
        } finally {
            assertFalse(ch.finishAndReleaseAll());
        }
    }

    @Test
    public void testNoSslHandshakeEventWhenNoHandshake() throws Exception {
        final AtomicBoolean inActive = new AtomicBoolean(false);

        SSLEngine engine = SSLContext.getDefault().createSSLEngine();
        EmbeddedChannel ch = new EmbeddedChannel(
                DefaultChannelId.newInstance(), false, false, new ChannelInboundHandlerAdapter() {
            @Override
            public void channelActive(ChannelHandlerContext ctx) throws Exception {
                // Not forward the event to the SslHandler but just close the Channel.
                ctx.close();
            }
        }, new SslHandler(engine) {
            @Override
            public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
                // We want to override what Channel.isActive() will return as otherwise it will
                // return true and so trigger an handshake.
                inActive.set(true);

Frequently Asked Questions

What is the SslHandlerTest class?
SslHandlerTest is a class in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java.
Where is SslHandlerTest defined?
SslHandlerTest is defined in handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java at line 108.

Analyze Your Own Codebase

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

Try Supermodel Free