Home / Function/ testNotLeakBuffersWhenCloseByRemotePeer() — netty Function Reference

testNotLeakBuffersWhenCloseByRemotePeer() — netty Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/local/LocalChannelTest.java lines 933–992

    @Test
    public void testNotLeakBuffersWhenCloseByRemotePeer() throws Exception {
        Bootstrap cb = new Bootstrap();
        ServerBootstrap sb = new ServerBootstrap();

        cb.group(sharedGroup)
                .channel(LocalChannel.class)
                .handler(new SimpleChannelInboundHandler<ByteBuf>() {
                    @Override
                    public void channelActive(final ChannelHandlerContext ctx) throws Exception {
                        ctx.writeAndFlush(ctx.alloc().buffer().writeZero(100));
                    }

                    @Override
                    public void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
                        // Just drop the buffer
                    }
                });

        sb.group(sharedGroup)
                .channel(LocalServerChannel.class)
                .childHandler(new ChannelInitializer<LocalChannel>() {
                    @Override
                    public void initChannel(LocalChannel ch) throws Exception {
                        ch.pipeline().addLast(new SimpleChannelInboundHandler<ByteBuf>() {

                            @Override
                            public void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
                                while (buffer.isReadable()) {
                                    // Fill the ChannelOutboundBuffer with multiple buffers
                                    ctx.write(buffer.readRetainedSlice(1));
                                }
                                // Flush and so transfer the written buffers to the inboundBuffer of the remote peer.
                                // After this point the remote peer is responsible to release all the buffers.
                                ctx.flush();
                                // This close call will trigger the remote peer close as well.
                                ctx.close();
                            }
                        });
                    }
                });

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

            // Connect to the server
            cc = (LocalChannel) cb.connect(sc.localAddress()).sync().channel();

            // Close the channel
            closeChannel(cc);
            assertTrue(cc.inboundBuffer.isEmpty());
            closeChannel(sc);
        } finally {
            closeChannel(cc);
            closeChannel(sc);
        }
    }

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free