Home / Function/ testPeerWriteInWritePromiseCompleteSameEventLoopPreservesOrder() — netty Function Reference

testPeerWriteInWritePromiseCompleteSameEventLoopPreservesOrder() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  da8d733a_4f9a_da6c_a90d_d621cf553c25["testPeerWriteInWritePromiseCompleteSameEventLoopPreservesOrder()"]
  d7e5442a_9b99_814d_2bd6_0be57237db65["LocalChannelTest"]
  da8d733a_4f9a_da6c_a90d_d621cf553c25 -->|defined in| d7e5442a_9b99_814d_2bd6_0be57237db65
  d3c8aa54_ac5d_6944_e789_c2c22ce16089["closeChannel()"]
  da8d733a_4f9a_da6c_a90d_d621cf553c25 -->|calls| d3c8aa54_ac5d_6944_e789_c2c22ce16089
  c89c9d89_4030_c998_7504_cb2fa2ef2bc8["channelRead()"]
  da8d733a_4f9a_da6c_a90d_d621cf553c25 -->|calls| c89c9d89_4030_c998_7504_cb2fa2ef2bc8
  style da8d733a_4f9a_da6c_a90d_d621cf553c25 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/local/LocalChannelTest.java lines 611–691

    @Test
    public void testPeerWriteInWritePromiseCompleteSameEventLoopPreservesOrder() throws InterruptedException {
        Bootstrap cb = new Bootstrap();
        ServerBootstrap sb = new ServerBootstrap();
        final CountDownLatch messageLatch = new CountDownLatch(2);
        final ByteBuf data = Unpooled.wrappedBuffer(new byte[1024]);
        final ByteBuf data2 = Unpooled.wrappedBuffer(new byte[512]);
        final CountDownLatch serverChannelLatch = new CountDownLatch(1);
        final AtomicReference<Channel> serverChannelRef = new AtomicReference<Channel>();

        try {
            cb.group(sharedGroup)
            .channel(LocalChannel.class)
            .handler(new ChannelInboundHandlerAdapter() {
                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    if (data2.equals(msg) && messageLatch.getCount() == 1) {
                        ReferenceCountUtil.safeRelease(msg);
                        messageLatch.countDown();
                    } else {
                        super.channelRead(ctx, msg);
                    }
                }
            });

            sb.group(sharedGroup)
            .channel(LocalServerChannel.class)
            .childHandler(new ChannelInitializer<LocalChannel>() {
                @Override
                public void initChannel(LocalChannel ch) throws Exception {
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                            if (data.equals(msg) && messageLatch.getCount() == 2) {
                                ReferenceCountUtil.safeRelease(msg);
                                messageLatch.countDown();
                            } else {
                                super.channelRead(ctx, msg);
                            }
                        }
                    });
                    serverChannelRef.set(ch);
                    serverChannelLatch.countDown();
                }
            });

            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(serverChannelLatch.await(5, SECONDS));

                final Channel ccCpy = cc;
                // Make sure a write operation is executed in the eventloop
                cc.pipeline().lastContext().executor().execute(new Runnable() {
                    @Override
                    public void run() {
                        ChannelPromise promise = ccCpy.newPromise();
                        promise.addListener(future -> {
                            Channel serverChannelCpy = serverChannelRef.get();
                            serverChannelCpy.writeAndFlush(
                                    data2.retainedDuplicate(), serverChannelCpy.newPromise());
                        });
                        ccCpy.writeAndFlush(data.retainedDuplicate(), promise);
                    }
                });

                assertTrue(messageLatch.await(5, SECONDS));
            } finally {
                closeChannel(cc);
                closeChannel(sc);
            }
        } finally {
            data.release();
            data2.release();
        }
    }

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free