Home / Class/ SocketAutoReadTest Class — netty Architecture

SocketAutoReadTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a0dc2361_672e_c520_4628_36c9b2fa0172["SocketAutoReadTest"]
  9b48ca78_1238_62ed_f777_a60e46d03430["SocketAutoReadTest.java"]
  a0dc2361_672e_c520_4628_36c9b2fa0172 -->|defined in| 9b48ca78_1238_62ed_f777_a60e46d03430
  9932a6bc_e543_2379_a683_36445e49a66a["testAutoReadOffDuringReadOnlyReadsOneTime()"]
  a0dc2361_672e_c520_4628_36c9b2fa0172 -->|method| 9932a6bc_e543_2379_a683_36445e49a66a

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketAutoReadTest.java lines 42–233

public class SocketAutoReadTest extends AbstractSocketTest {
    @Test
    public void testAutoReadOffDuringReadOnlyReadsOneTime(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap, Bootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable {
                testAutoReadOffDuringReadOnlyReadsOneTime(serverBootstrap, bootstrap);
            }
        });
    }

    public void testAutoReadOffDuringReadOnlyReadsOneTime(ServerBootstrap sb, Bootstrap cb) throws Throwable {
        testAutoReadOffDuringReadOnlyReadsOneTime(true, sb, cb);
        testAutoReadOffDuringReadOnlyReadsOneTime(false, sb, cb);
    }

    private static void testAutoReadOffDuringReadOnlyReadsOneTime(boolean readOutsideEventLoopThread,
                                                           ServerBootstrap sb, Bootstrap cb) throws Throwable {
        Channel serverChannel = null;
        Channel clientChannel = null;
        try {
            AutoReadInitializer serverInitializer = new AutoReadInitializer(!readOutsideEventLoopThread);
            AutoReadInitializer clientInitializer = new AutoReadInitializer(!readOutsideEventLoopThread);
            sb.option(ChannelOption.SO_BACKLOG, 1024)
                    .option(ChannelOption.AUTO_READ, true)
                    .childOption(ChannelOption.AUTO_READ, true)
                    // We want to ensure that we attempt multiple individual read operations per read loop so we can
                    // test the auto read feature being turned off when data is first read.
                    .childOption(ChannelOption.RECVBUF_ALLOCATOR, new TestRecvByteBufAllocator())
                    .childHandler(serverInitializer);

            serverChannel = sb.bind().syncUninterruptibly().channel();

            cb.option(ChannelOption.AUTO_READ, true)
                    // We want to ensure that we attempt multiple individual read operations per read loop so we can
                    // test the auto read feature being turned off when data is first read.
                    .option(ChannelOption.RECVBUF_ALLOCATOR, new TestRecvByteBufAllocator())
                    .handler(clientInitializer);

            clientChannel = cb.connect(serverChannel.localAddress()).syncUninterruptibly().channel();

            // 3 bytes means 3 independent reads for TestRecvByteBufAllocator
            clientChannel.writeAndFlush(randomBufferType(clientChannel.alloc(), new byte[3], 0, 3));
            serverInitializer.autoReadHandler.assertSingleRead();

            // 3 bytes means 3 independent reads for TestRecvByteBufAllocator
            serverInitializer.channel.writeAndFlush(
                    randomBufferType(serverInitializer.channel.alloc(), new byte[3], 0, 3));
            clientInitializer.autoReadHandler.assertSingleRead();

            if (readOutsideEventLoopThread) {
                serverInitializer.channel.read();
            }
            serverInitializer.autoReadHandler.assertSingleReadSecondTry();

            if (readOutsideEventLoopThread) {
                clientChannel.read();
            }
            clientInitializer.autoReadHandler.assertSingleReadSecondTry();
        } finally {
            if (clientChannel != null) {
                clientChannel.close().sync();
            }
            if (serverChannel != null) {
                serverChannel.close().sync();
            }
        }
    }

    private static class AutoReadInitializer extends ChannelInitializer<Channel> {
        final AutoReadHandler autoReadHandler;
        volatile Channel channel;

        AutoReadInitializer(boolean readInEventLoop) {
            autoReadHandler = new AutoReadHandler(readInEventLoop);
        }

        @Override
        protected void initChannel(Channel ch) throws Exception {
            channel = ch;
            ch.pipeline().addLast(autoReadHandler);

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free