Home / Function/ testCloseAfterWriteInSameEventLoopPreservesOrder() — netty Function Reference

testCloseAfterWriteInSameEventLoopPreservesOrder() — netty Function Reference

Architecture documentation for the testCloseAfterWriteInSameEventLoopPreservesOrder() function in LocalChannelTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6e2d3f4c_54ff_316e_9a87_fea5d4c4792f["testCloseAfterWriteInSameEventLoopPreservesOrder()"]
  d7e5442a_9b99_814d_2bd6_0be57237db65["LocalChannelTest"]
  6e2d3f4c_54ff_316e_9a87_fea5d4c4792f -->|defined in| d7e5442a_9b99_814d_2bd6_0be57237db65
  8088efe8_c29f_fb7e_c0b6_5eeb1a6637f1["channelActive()"]
  6e2d3f4c_54ff_316e_9a87_fea5d4c4792f -->|calls| 8088efe8_c29f_fb7e_c0b6_5eeb1a6637f1
  d3c8aa54_ac5d_6944_e789_c2c22ce16089["closeChannel()"]
  6e2d3f4c_54ff_316e_9a87_fea5d4c4792f -->|calls| d3c8aa54_ac5d_6944_e789_c2c22ce16089
  c89c9d89_4030_c998_7504_cb2fa2ef2bc8["channelRead()"]
  6e2d3f4c_54ff_316e_9a87_fea5d4c4792f -->|calls| c89c9d89_4030_c998_7504_cb2fa2ef2bc8
  style 6e2d3f4c_54ff_316e_9a87_fea5d4c4792f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/local/LocalChannelTest.java lines 394–459

    @Test
    public void testCloseAfterWriteInSameEventLoopPreservesOrder() throws InterruptedException {
        Bootstrap cb = new Bootstrap();
        ServerBootstrap sb = new ServerBootstrap();
        final CountDownLatch messageLatch = new CountDownLatch(3);
        final ByteBuf data = Unpooled.wrappedBuffer(new byte[1024]);

        try {
            cb.group(sharedGroup)
                    .channel(LocalChannel.class)
                    .handler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelActive(ChannelHandlerContext ctx) throws Exception {
                            ctx.writeAndFlush(data.retainedDuplicate());
                        }

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                            if (data.equals(msg)) {
                                ReferenceCountUtil.safeRelease(msg);
                                messageLatch.countDown();
                            } else {
                                super.channelRead(ctx, msg);
                            }
                        }
                    });

            sb.group(sharedGroup)
                    .channel(LocalServerChannel.class)
                    .childHandler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                            if (data.equals(msg)) {
                                messageLatch.countDown();
                                ctx.writeAndFlush(data.retainedDuplicate());
                                ctx.close();
                            } else {
                                super.channelRead(ctx, msg);
                            }
                        }

                        @Override
                        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
                            messageLatch.countDown();
                            super.channelInactive(ctx);
                        }
                    });

            Channel sc = null;
            Channel cc = null;
            try {
                // Start server
                sc = sb.bind(TEST_ADDRESS).syncUninterruptibly().channel();

                // Connect to the server
                cc = cb.connect(sc.localAddress()).syncUninterruptibly().channel();
                assertTrue(messageLatch.await(5, SECONDS));
                assertFalse(cc.isOpen());
            } finally {
                closeChannel(cc);
                closeChannel(sc);
            }
        } finally {
            data.release();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testCloseAfterWriteInSameEventLoopPreservesOrder() do?
testCloseAfterWriteInSameEventLoopPreservesOrder() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java.
Where is testCloseAfterWriteInSameEventLoopPreservesOrder() defined?
testCloseAfterWriteInSameEventLoopPreservesOrder() is defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java at line 394.
What does testCloseAfterWriteInSameEventLoopPreservesOrder() call?
testCloseAfterWriteInSameEventLoopPreservesOrder() calls 3 function(s): channelActive, channelRead, closeChannel.

Analyze Your Own Codebase

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

Try Supermodel Free