Home / Class/ ServerSocketSuspendTest Class — netty Architecture

ServerSocketSuspendTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  b05adb2f_065c_aba2_8df3_2df1df2bb241["ServerSocketSuspendTest"]
  ceabaaab_883c_c6bf_1006_e4b3e5308f1c["ServerSocketSuspendTest.java"]
  b05adb2f_065c_aba2_8df3_2df1df2bb241 -->|defined in| ceabaaab_883c_c6bf_1006_e4b3e5308f1c
  b127ec4c_4b34_c5af_4c3b_801a3610aba2["testSuspendAndResumeAccept()"]
  b05adb2f_065c_aba2_8df3_2df1df2bb241 -->|method| b127ec4c_4b34_c5af_4c3b_801a3610aba2

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/ServerSocketSuspendTest.java lines 36–116

public class ServerSocketSuspendTest extends AbstractServerSocketTest {

    private static final int NUM_CHANNELS = 10;
    private static final long TIMEOUT = 3000000000L;

    @Test
    @Disabled("Need to investigate why it fails on osx")
    public void testSuspendAndResumeAccept(TestInfo testInfo) throws Throwable {
        run(testInfo, new Runner<ServerBootstrap>() {
            @Override
            public void run(ServerBootstrap serverBootstrap) throws Throwable {
                testSuspendAndResumeAccept(serverBootstrap);
            }
        });
    }

    public void testSuspendAndResumeAccept(ServerBootstrap sb) throws Throwable {
        AcceptedChannelCounter counter = new AcceptedChannelCounter(NUM_CHANNELS);

        sb.option(ChannelOption.SO_BACKLOG, 1);
        sb.option(ChannelOption.AUTO_READ, false);
        sb.childHandler(counter);

        Channel sc = sb.bind().sync().channel();

        List<Socket> sockets = new ArrayList<Socket>();

        try {
            long startTime = System.nanoTime();
            for (int i = 0; i < NUM_CHANNELS; i ++) {
                Socket s = new Socket();
                SocketUtils.connect(s, sc.localAddress(), 10000);
                sockets.add(s);
            }

            sc.config().setAutoRead(true);

            counter.latch.await();

            long endTime = System.nanoTime();
            assertTrue(endTime - startTime > TIMEOUT);
        } finally {
            for (Socket s: sockets) {
                s.close();
            }
        }

        Thread.sleep(TIMEOUT / 1000000);

        try {
            long startTime = System.nanoTime();
            for (int i = 0; i < NUM_CHANNELS; i ++) {
                Socket s = new Socket();
                s.connect(sc.localAddress(), 10000);
                sockets.add(s);
            }
            long endTime = System.nanoTime();

            assertTrue(endTime - startTime < TIMEOUT);
        } finally {
            for (Socket s: sockets) {
                s.close();
            }
        }
    }

    @ChannelHandler.Sharable
    private static final class AcceptedChannelCounter extends ChannelInboundHandlerAdapter {

        final CountDownLatch latch;

        AcceptedChannelCounter(int nChannels) {
            latch = new CountDownLatch(nChannels);
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            latch.countDown();
        }
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free