Home / Class/ DetectPeerCloseWithoutReadTest Class — netty Architecture

DetectPeerCloseWithoutReadTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  2f5040d4_a100_f0df_6a2f_a91790d5e155["DetectPeerCloseWithoutReadTest"]
  e837723b_5371_6b18_b1d0_48504d911ae7["DetectPeerCloseWithoutReadTest.java"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|defined in| e837723b_5371_6b18_b1d0_48504d911ae7
  cd180541_2271_09d6_1821_f3eb3821198a["EventLoopGroup()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| cd180541_2271_09d6_1821_f3eb3821198a
  ed700b6e_0993_6dc8_45c9_2a4304673802["serverChannel()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| ed700b6e_0993_6dc8_45c9_2a4304673802
  0b55ef73_d7cd_bc3e_deae_975707a22f28["clientChannel()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| 0b55ef73_d7cd_bc3e_deae_975707a22f28
  ef5502f6_ac17_4996_5ba2_38dcddb080b1["clientCloseWithoutServerReadIsDetectedNoExtraReadRequested()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| ef5502f6_ac17_4996_5ba2_38dcddb080b1
  4b4a8926_b21b_82f9_ba0d_826e7716acd0["clientCloseWithoutServerReadIsDetectedExtraReadRequested()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| 4b4a8926_b21b_82f9_ba0d_826e7716acd0
  0efd892e_d03e_c723_f8f6_7342d1497217["clientCloseWithoutServerReadIsDetected0()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| 0efd892e_d03e_c723_f8f6_7342d1497217
  bf84d5c4_d178_0b0d_5621_1af2b348d292["serverCloseWithoutClientReadIsDetectedNoExtraReadRequested()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| bf84d5c4_d178_0b0d_5621_1af2b348d292
  861a78b7_1d01_1ba4_7271_f6578641b64f["serverCloseWithoutClientReadIsDetectedExtraReadRequested()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| 861a78b7_1d01_1ba4_7271_f6578641b64f
  6b17939a_ac76_b01f_2ca8_f0e6e583698c["serverCloseWithoutClientReadIsDetected0()"]
  2f5040d4_a100_f0df_6a2f_a91790d5e155 -->|method| 6b17939a_ac76_b01f_2ca8_f0e6e583698c

Relationship Graph

Source Code

transport-native-unix-common-tests/src/main/java/io/netty/channel/unix/tests/DetectPeerCloseWithoutReadTest.java lines 41–214

public abstract class DetectPeerCloseWithoutReadTest {
    protected abstract EventLoopGroup newGroup();
    protected abstract Class<? extends ServerChannel> serverChannel();
    protected abstract Class<? extends Channel> clientChannel();

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void clientCloseWithoutServerReadIsDetectedNoExtraReadRequested() throws InterruptedException {
        clientCloseWithoutServerReadIsDetected0(false);
    }

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void clientCloseWithoutServerReadIsDetectedExtraReadRequested() throws InterruptedException {
        clientCloseWithoutServerReadIsDetected0(true);
    }

    private void clientCloseWithoutServerReadIsDetected0(final boolean extraReadRequested)
            throws InterruptedException {
        EventLoopGroup serverGroup = null;
        EventLoopGroup clientGroup = null;
        Channel serverChannel = null;
        try {
            final CountDownLatch latch = new CountDownLatch(1);
            final AtomicInteger bytesRead = new AtomicInteger();
            final int expectedBytes = 100;
            serverGroup = newGroup();
            clientGroup = newGroup();
            ServerBootstrap sb = new ServerBootstrap();
            sb.group(serverGroup);
            sb.channel(serverChannel());
            // Ensure we read only one message per read() call and that we need multiple read()
            // calls to consume everything.
            sb.childOption(ChannelOption.AUTO_READ, false);
            sb.childOption(ChannelOption.MAX_MESSAGES_PER_READ, 1);
            sb.childOption(ChannelOption.RECVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(expectedBytes / 10));
            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new TestHandler(bytesRead, extraReadRequested, latch));
                }
            });

            serverChannel = sb.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();

            Bootstrap cb = new Bootstrap();
            cb.group(serverGroup);
            cb.channel(clientChannel());
            cb.handler(new ChannelInboundHandlerAdapter());
            Channel clientChannel = cb.connect(serverChannel.localAddress()).syncUninterruptibly().channel();
            ByteBuf buf = clientChannel.alloc().buffer(expectedBytes);
            buf.writerIndex(buf.writerIndex() + expectedBytes);
            clientChannel.writeAndFlush(buf).addListener(ChannelFutureListener.CLOSE);

            latch.await();
            assertEquals(expectedBytes, bytesRead.get());
        } finally {
            if (serverChannel != null) {
                serverChannel.close().syncUninterruptibly();
            }
            if (serverGroup != null) {
                serverGroup.shutdownGracefully();
            }
            if (clientGroup != null) {
                clientGroup.shutdownGracefully();
            }
        }
    }

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void serverCloseWithoutClientReadIsDetectedNoExtraReadRequested() throws InterruptedException {
        serverCloseWithoutClientReadIsDetected0(false);
    }

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void serverCloseWithoutClientReadIsDetectedExtraReadRequested() throws InterruptedException {
        serverCloseWithoutClientReadIsDetected0(true);
    }

Frequently Asked Questions

What is the DetectPeerCloseWithoutReadTest class?
DetectPeerCloseWithoutReadTest is a class in the netty codebase, defined in transport-native-unix-common-tests/src/main/java/io/netty/channel/unix/tests/DetectPeerCloseWithoutReadTest.java.
Where is DetectPeerCloseWithoutReadTest defined?
DetectPeerCloseWithoutReadTest is defined in transport-native-unix-common-tests/src/main/java/io/netty/channel/unix/tests/DetectPeerCloseWithoutReadTest.java at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free