Home / Class/ SocketHalfClosedTest Class — netty Architecture

SocketHalfClosedTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  12fb37da_402f_660c_11c3_2383afda173c["SocketHalfClosedTest"]
  f83511ba_39cb_73dd_453f_92c6a5fe10ae["SocketHalfClosedTest.java"]
  12fb37da_402f_660c_11c3_2383afda173c -->|defined in| f83511ba_39cb_73dd_453f_92c6a5fe10ae
  21200df9_eb56_eff5_7800_6d3d66799334["maxReadCompleteWithNoDataAfterInputShutdown()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 21200df9_eb56_eff5_7800_6d3d66799334
  c562440a_8a60_0e56_4204_87fa7867fe78["testAllDataReadEventTriggeredAfterHalfClosure()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| c562440a_8a60_0e56_4204_87fa7867fe78
  0257caf2_49bb_c678_4b3a_f599308c0f78["allDataReadEventTriggeredAfterHalfClosure()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 0257caf2_49bb_c678_4b3a_f599308c0f78
  934e12c4_7f18_ee29_20df_e86d96a84c00["testHalfClosureReceiveDataOnFinalWait2StateWhenSoLingerSet()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 934e12c4_7f18_ee29_20df_e86d96a84c00
  71714971_050a_f2f7_0fcc_c7f3afe1077f["testHalfClosureOnlyOneEventWhenAutoRead()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 71714971_050a_f2f7_0fcc_c7f3afe1077f
  400c4529_5b5e_12a2_fbf3_476c13dd093d["testAllDataReadAfterHalfClosure()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 400c4529_5b5e_12a2_fbf3_476c13dd093d
  0335448a_bfdd_8f1e_477c_9743080bee45["testAutoCloseFalseDoesShutdownOutput()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 0335448a_bfdd_8f1e_477c_9743080bee45
  4a2ffbbc_84a4_f186_7637_0f13afdf125d["testAllDataReadClosure()"]
  12fb37da_402f_660c_11c3_2383afda173c -->|method| 4a2ffbbc_84a4_f186_7637_0f13afdf125d

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java lines 56–865

@Timeout(value = 20000, unit = MILLISECONDS)
public class SocketHalfClosedTest extends AbstractSocketTest {

    protected int maxReadCompleteWithNoDataAfterInputShutdown() {
        return 2; // nio needs read flag to detect full closure.
    }

    @Test
    public void testAllDataReadEventTriggeredAfterHalfClosure(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                if (bootstrap.config().group() instanceof OioEventLoopGroup) {
                    logger.debug("Ignoring test for incompatible OIO event system");
                    return;
                } else if (bootstrap.config().group() instanceof IoEventLoopGroup) {
                    IoEventLoopGroup group = (IoEventLoopGroup) bootstrap.config().group();
                    if (group.isIoType(NioIoHandler.class)) {
                        logger.debug("Ignoring test for incompatible NioHandler");
                        return;
                    }
                }
                allDataReadEventTriggeredAfterHalfClosure(serverBootstrap, bootstrap);
            }
        });
    }

    private void allDataReadEventTriggeredAfterHalfClosure(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        final int totalServerBytesWritten = 1;
        final CountDownLatch clientReadAllDataLatch = new CountDownLatch(1);
        final CountDownLatch clientHalfClosedLatch = new CountDownLatch(1);
        final CountDownLatch clientHalfClosedAllBytesRead = new CountDownLatch(1);
        final AtomicInteger clientReadCompletes = new AtomicInteger();
        final AtomicInteger clientZeroDataReadCompletes = new AtomicInteger();
        Channel serverChannel = null;
        Channel clientChannel = null;
        AtomicReference<Channel> serverChildChannel = new AtomicReference<>();
        try {
            cb.option(ChannelOption.ALLOW_HALF_CLOSURE, true)
                    .option(ChannelOption.AUTO_CLOSE, false)
                    .option(ChannelOption.AUTO_READ, false);

            sb.option(ChannelOption.ALLOW_HALF_CLOSURE, true)
                    .option(ChannelOption.AUTO_CLOSE, false)
                    .childOption(ChannelOption.TCP_NODELAY, true);

            sb.childHandler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    serverChildChannel.set(ch);
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelActive(ChannelHandlerContext ctx) throws Exception {
                            ByteBuf buf = ctx.alloc().buffer(totalServerBytesWritten);
                            buf.writerIndex(buf.capacity());
                            ctx.writeAndFlush(buf);
                        }

                        @Override
                        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
                            ctx.close();
                        }
                    });
                }
            });

            // client.
            cb.handler(new ChannelInitializer<Channel>() {
                @Override
                protected void initChannel(Channel ch) {
                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                        private int bytesRead;
                        private int bytesSinceReadComplete;

                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) {
                            ByteBuf buf = (ByteBuf) msg;
                            bytesRead += buf.readableBytes();
                            bytesSinceReadComplete += buf.readableBytes();
                            buf.release();
                        }

Frequently Asked Questions

What is the SocketHalfClosedTest class?
SocketHalfClosedTest is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java.
Where is SocketHalfClosedTest defined?
SocketHalfClosedTest is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java at line 56.

Analyze Your Own Codebase

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

Try Supermodel Free