Home / Function/ writingAfterClosedChannelDoesNotNPE() — netty Function Reference

writingAfterClosedChannelDoesNotNPE() — netty Function Reference

Architecture documentation for the writingAfterClosedChannelDoesNotNPE() function in Lz4FrameEncoderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  1ffe5b69_82b0_1fff_8694_98cfb8688d7e["writingAfterClosedChannelDoesNotNPE()"]
  16452743_407c_c5f6_ee9f_baa8b84020f0["Lz4FrameEncoderTest"]
  1ffe5b69_82b0_1fff_8694_98cfb8688d7e -->|defined in| 16452743_407c_c5f6_ee9f_baa8b84020f0
  6111e409_d85d_a017_6935_7ac7b5d5a337["Lz4FrameEncoder()"]
  1ffe5b69_82b0_1fff_8694_98cfb8688d7e -->|calls| 6111e409_d85d_a017_6935_7ac7b5d5a337
  style 1ffe5b69_82b0_1fff_8694_98cfb8688d7e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java lines 242–306

    @Test
    @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
    public void writingAfterClosedChannelDoesNotNPE() throws InterruptedException {
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory());
        Channel serverChannel = null;
        Channel clientChannel = null;
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Throwable> writeFailCauseRef = new AtomicReference<Throwable>();
        try {
            ServerBootstrap sb = new ServerBootstrap();
            sb.group(group);
            sb.channel(NioServerSocketChannel.class);
            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                }
            });

            Bootstrap bs = new Bootstrap();
            bs.group(group);
            bs.channel(NioSocketChannel.class);
            bs.handler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    ch.pipeline().addLast(new Lz4FrameEncoder());
                }
            });

            serverChannel = sb.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
            clientChannel = bs.connect(serverChannel.localAddress()).syncUninterruptibly().channel();

            final Channel finalClientChannel = clientChannel;
            clientChannel.eventLoop().execute(new Runnable() {
                @Override
                public void run() {
                    finalClientChannel.close();
                    final int size = 27;
                    ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(size, size);
                    finalClientChannel.writeAndFlush(buf.writerIndex(buf.writerIndex() + size))
                            .addListener(future -> {
                                try {
                                    writeFailCauseRef.set(future.cause());
                                } finally {
                                    latch.countDown();
                                }
                            });
                }
            });
            latch.await();
            Throwable writeFailCause = writeFailCauseRef.get();
            assertNotNull(writeFailCause);
            Throwable writeFailCauseCause = writeFailCause.getCause();
            if (writeFailCauseCause != null) {
                assertThat(writeFailCauseCause).isNotInstanceOf(NullPointerException.class);
            }
        } finally {
            if (serverChannel != null) {
                serverChannel.close();
            }
            if (clientChannel != null) {
                clientChannel.close();
            }
            group.shutdownGracefully();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does writingAfterClosedChannelDoesNotNPE() do?
writingAfterClosedChannelDoesNotNPE() is a function in the netty codebase, defined in codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java.
Where is writingAfterClosedChannelDoesNotNPE() defined?
writingAfterClosedChannelDoesNotNPE() is defined in codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java at line 242.
What does writingAfterClosedChannelDoesNotNPE() call?
writingAfterClosedChannelDoesNotNPE() calls 1 function(s): Lz4FrameEncoder.

Analyze Your Own Codebase

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

Try Supermodel Free