Home / Class/ ThreadPerChannelEventLoopGroupTest Class — netty Architecture

ThreadPerChannelEventLoopGroupTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f4567ea2_d860_6e7e_51e1_01e57493fa4f["ThreadPerChannelEventLoopGroupTest"]
  1d770e03_0ce7_365c_d3e3_72d553b4a7d5["ThreadPerChannelEventLoopGroupTest.java"]
  f4567ea2_d860_6e7e_51e1_01e57493fa4f -->|defined in| 1d770e03_0ce7_365c_d3e3_72d553b4a7d5
  2cc502ae_2a3e_ce82_2c8b_54d2aa14a4fc["testTerminationFutureSuccessInLog()"]
  f4567ea2_d860_6e7e_51e1_01e57493fa4f -->|method| 2cc502ae_2a3e_ce82_2c8b_54d2aa14a4fc
  d4190fb8_00e0_9168_b7ab_f0c14a9af675["testTerminationFutureSuccessReflectively()"]
  f4567ea2_d860_6e7e_51e1_01e57493fa4f -->|method| d4190fb8_00e0_9168_b7ab_f0c14a9af675
  a1cc7dac_2447_0e97_a67a_2b155b9c5c4c["runTest()"]
  f4567ea2_d860_6e7e_51e1_01e57493fa4f -->|method| a1cc7dac_2447_0e97_a67a_2b155b9c5c4c

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/ThreadPerChannelEventLoopGroupTest.java lines 37–117

@Disabled("Flaky test; See: https://github.com/netty/netty/issues/11551")
public class ThreadPerChannelEventLoopGroupTest {

    private static final ChannelHandler NOOP_HANDLER = new ChannelHandlerAdapter() {
        @Override
        public boolean isSharable() {
            return true;
        }
    };

    @Test
    public void testTerminationFutureSuccessInLog() throws Exception {
        for (int i = 0; i < 2; i++) {
            ThreadPerChannelEventLoopGroup loopGroup = new ThreadPerChannelEventLoopGroup(64);
            runTest(loopGroup);
        }
    }

    @Test
    public void testTerminationFutureSuccessReflectively() throws Exception {
        Field terminationFutureField =
                ThreadPerChannelEventLoopGroup.class.getDeclaredField("terminationFuture");
        terminationFutureField.setAccessible(true);
        final Exception[] exceptionHolder = new Exception[1];
        for (int i = 0; i < 2; i++) {
            ThreadPerChannelEventLoopGroup loopGroup = new ThreadPerChannelEventLoopGroup(64);
            Promise<?> promise = new DefaultPromise<Void>(GlobalEventExecutor.INSTANCE) {
                @Override
                public Promise<Void> setSuccess(Void result) {
                    try {
                        return super.setSuccess(result);
                    } catch (IllegalStateException e) {
                        exceptionHolder[0] = e;
                        throw e;
                    }
                }
            };
            terminationFutureField.set(loopGroup, promise);
            runTest(loopGroup);
        }
        // The global event executor will not terminate, but this will give the test a chance to fail.
        GlobalEventExecutor.INSTANCE.awaitTermination(100, TimeUnit.MILLISECONDS);
        assertNull(exceptionHolder[0]);
    }

    private static void runTest(ThreadPerChannelEventLoopGroup loopGroup) throws InterruptedException {
        int taskCount = 100;
        EventExecutor testExecutor = new TestEventExecutor();
        ChannelGroup channelGroup = new DefaultChannelGroup(testExecutor);
        while (taskCount-- > 0) {
            Channel channel = new EmbeddedChannel(NOOP_HANDLER);
            loopGroup.register(new DefaultChannelPromise(channel, testExecutor));
            channelGroup.add(channel);
        }
        channelGroup.close().sync();
        loopGroup.shutdownGracefully(100, 200, TimeUnit.MILLISECONDS).sync();
        assertTrue(loopGroup.isTerminated());
    }

    private static class TestEventExecutor extends SingleThreadEventExecutor {

        TestEventExecutor() {
            super(null, new DefaultThreadFactory("test"), false);
        }

        @Override
        protected void run() {
            for (;;) {
                Runnable task = takeTask();
                if (task != null) {
                    task.run();
                    updateLastExecutionTime();
                }

                if (confirmShutdown()) {
                    break;
                }
            }
        }
    }
}

Frequently Asked Questions

What is the ThreadPerChannelEventLoopGroupTest class?
ThreadPerChannelEventLoopGroupTest is a class in the netty codebase, defined in transport/src/test/java/io/netty/channel/ThreadPerChannelEventLoopGroupTest.java.
Where is ThreadPerChannelEventLoopGroupTest defined?
ThreadPerChannelEventLoopGroupTest is defined in transport/src/test/java/io/netty/channel/ThreadPerChannelEventLoopGroupTest.java at line 37.

Analyze Your Own Codebase

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

Try Supermodel Free