Home / Class/ CloseNotifyTest Class — netty Architecture

CloseNotifyTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  91635dfc_456c_fec9_4413_a1ee45d49032["CloseNotifyTest"]
  210bd811_a079_b692_5128_0a27880ecc13["CloseNotifyTest.java"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|defined in| 210bd811_a079_b692_5128_0a27880ecc13
  317fac11_4953_82ab_0135_80a75f4c2486["data()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| 317fac11_4953_82ab_0135_80a75f4c2486
  c8dc5de5_36bd_d22b_8ec3_7c93cc9586c8["eventsOrder()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| c8dc5de5_36bd_d22b_8ec3_7c93cc9586c8
  d06bebe4_66af_bb53_d991_a0ac3abcdccf["jdkTls13()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| d06bebe4_66af_bb53_d991_a0ac3abcdccf
  f32d201a_b88b_4d0d_0e9d_e795d6b90e14["EmbeddedChannel()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| f32d201a_b88b_4d0d_0e9d_e795d6b90e14
  57cc154b_b9c1_7bdd_c318_8f6ea3e5e55e["forwardData()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| 57cc154b_b9c1_7bdd_c318_8f6ea3e5e55e
  aaff46e6_d1c4_937c_05e7_56dcbca48920["forwardAllWithCloseNotify()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| aaff46e6_d1c4_937c_05e7_56dcbca48920
  ab5d83ff_c28a_dc10_ae57_ed5274a8c1f7["String()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| ab5d83ff_c28a_dc10_ae57_ed5274a8c1f7
  e3e1dd51_18ae_e079_751c_f22cc096ec24["discardEmptyOutboundBuffers()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| e3e1dd51_18ae_e079_751c_f22cc096ec24
  3b5ef0d4_0faf_0554_a2cf_8eddf09ebf76["assertCloseNotify()"]
  91635dfc_456c_fec9_4413_a1ee45d49032 -->|method| 3b5ef0d4_0faf_0554_a2cf_8eddf09ebf76

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/CloseNotifyTest.java lines 51–234

public class CloseNotifyTest {

    private static final UnpooledByteBufAllocator ALLOC = UnpooledByteBufAllocator.DEFAULT;
    private static final Object INACTIVE = new Object() {
        @Override
        public String toString() {
            return "INACTIVE";
        }
    };

    static Collection<Object[]> data() {
        return asList(new Object[][] {
                { SslProvider.JDK, SslProtocols.TLS_v1_2 },
                { SslProvider.JDK, SslProtocols.TLS_v1_3 },
                { SslProvider.OPENSSL, SslProtocols.TLS_v1_2 },
                { SslProvider.OPENSSL, SslProtocols.TLS_v1_3 },
        });
    }

    @ParameterizedTest(name = "{index}: provider={0}, protocol={1}")
    @Timeout(30)
    @MethodSource("data")
    public void eventsOrder(SslProvider provider, String protocol) throws Exception {
        assumeTrue(provider != SslProvider.OPENSSL || OpenSsl.isAvailable(), "OpenSSL is not available");

        if (SslProtocols.TLS_v1_3.equals(protocol)) {
            // Ensure we support TLSv1.3
            assumeTrue(SslProvider.isTlsv13Supported(provider));
        }
        BlockingQueue<Object> clientEventQueue = new LinkedBlockingQueue<Object>();
        BlockingQueue<Object> serverEventQueue = new LinkedBlockingQueue<Object>();

        EmbeddedChannel clientChannel = initChannel(provider, protocol, true, clientEventQueue);
        EmbeddedChannel serverChannel = initChannel(provider, protocol, false, serverEventQueue);

        try {
            // handshake:
            forwardData(clientChannel, serverChannel);
            forwardData(serverChannel, clientChannel);
            forwardData(clientChannel, serverChannel);
            forwardData(serverChannel, clientChannel);
            assertInstanceOf(SslHandshakeCompletionEvent.class, clientEventQueue.poll());
            assertInstanceOf(SslHandshakeCompletionEvent.class, serverEventQueue.poll());
            assertEquals(protocol, handshakenProtocol(clientChannel));

            // send data:
            clientChannel.writeOutbound(writeAscii(ALLOC, "request_msg"));
            forwardData(clientChannel, serverChannel);
            assertEquals("request_msg", serverEventQueue.poll());

            // respond with data and close_notify:
            serverChannel.writeOutbound(writeAscii(ALLOC, "response_msg"));
            assertTrue(serverChannel.finish());
            assertInstanceOf(SslCloseCompletionEvent.class, serverEventQueue.poll());
            assertTrue(clientEventQueue.isEmpty());

            // consume server response with close_notify:
            forwardAllWithCloseNotify(serverChannel, clientChannel);
            assertEquals("response_msg", clientEventQueue.poll());
            assertInstanceOf(SslCloseCompletionEvent.class, clientEventQueue.poll());

            // make sure client automatically responds with close_notify:
            if (!jdkTls13(provider, protocol)) {
                // JDK impl of TLSv1.3 does not automatically generate "close_notify" in response to the received
                // "close_notify" alert. This is a legit behavior according to the spec:
                // https://tools.ietf.org/html/rfc8446#section-6.1. Handle it differently:
                assertCloseNotify((ByteBuf) clientChannel.readOutbound());
            }
        } finally {
            try {
                clientChannel.finish();
            } finally {
                serverChannel.finish();
            }
        }

        if (jdkTls13(provider, protocol)) {
            assertCloseNotify((ByteBuf) clientChannel.readOutbound());
        } else {
            discardEmptyOutboundBuffers(clientChannel);
        }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free