Home / Class/ AbstractChannelTest Class — netty Architecture

AbstractChannelTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  63f919c7_8527_59bf_45a5_f49840c141ac["AbstractChannelTest"]
  334974d2_8d7e_4b1a_a8e7_e64ecc4a4788["AbstractChannelTest.java"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|defined in| 334974d2_8d7e_4b1a_a8e7_e64ecc4a4788
  9e832794_2034_22cd_5ae1_685bbe0f831b["ensureInitialRegistrationFiresActive()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| 9e832794_2034_22cd_5ae1_685bbe0f831b
  f02f8dd4_ae43_9cb4_dad3_4d9110ec9db3["ensureSubsequentRegistrationDoesNotFireActive()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| f02f8dd4_ae43_9cb4_dad3_4d9110ec9db3
  6408d737_6094_3ad8_0f91_eda3468f58ce["ensureDefaultChannelId()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| 6408d737_6094_3ad8_0f91_eda3468f58ce
  457d0ae7_b83c_4a96_5450_a02a1074d26c["processIdWithProcessHandleJava9()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| 457d0ae7_b83c_4a96_5450_a02a1074d26c
  e0d94ee0_9fca_b8bf_8a64_75cafbedcf1e["processIdWithJmxPrejava9()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| e0d94ee0_9fca_b8bf_8a64_75cafbedcf1e
  d995674a_eb16_206d_4092_cae0cc9b4cea["testClosedChannelExceptionCarryIOException()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| d995674a_eb16_206d_4092_cae0cc9b4cea
  f81463a5_0fdf_2b9b_b736_b430f541ed43["assertClosedChannelException()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| f81463a5_0fdf_2b9b_b736_b430f541ed43
  9225cd8f_6728_b060_f06a_6f6e2e5381c9["registerChannel()"]
  63f919c7_8527_59bf_45a5_f49840c141ac -->|method| 9225cd8f_6728_b060_f06a_6f6e2e5381c9

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/AbstractChannelTest.java lines 36–251

public class AbstractChannelTest {

    @Test
    public void ensureInitialRegistrationFiresActive() throws Throwable {
        EventLoop eventLoop = mock(EventLoop.class);
        // This allows us to have a single-threaded test
        when(eventLoop.inEventLoop()).thenReturn(true);

        TestChannel channel = new TestChannel();
        ChannelInboundHandler handler = mock(ChannelInboundHandler.class);
        channel.pipeline().addLast(handler);

        registerChannel(eventLoop, channel);

        verify(handler).handlerAdded(any(ChannelHandlerContext.class));
        verify(handler).channelRegistered(any(ChannelHandlerContext.class));
        verify(handler).channelActive(any(ChannelHandlerContext.class));
    }

    @Test
    public void ensureSubsequentRegistrationDoesNotFireActive() throws Throwable {
        final EventLoop eventLoop = mock(EventLoop.class);
        // This allows us to have a single-threaded test
        when(eventLoop.inEventLoop()).thenReturn(true);

        doAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocationOnMock) {
                ((Runnable) invocationOnMock.getArgument(0)).run();
                return null;
            }
        }).when(eventLoop).execute(any(Runnable.class));

        final TestChannel channel = new TestChannel();
        ChannelInboundHandler handler = mock(ChannelInboundHandler.class);

        channel.pipeline().addLast(handler);

        registerChannel(eventLoop, channel);
        channel.unsafe().deregister(new DefaultChannelPromise(channel));

        registerChannel(eventLoop, channel);

        verify(handler).handlerAdded(any(ChannelHandlerContext.class));

        // Should register twice
        verify(handler,  times(2)) .channelRegistered(any(ChannelHandlerContext.class));
        verify(handler).channelActive(any(ChannelHandlerContext.class));
        verify(handler).channelUnregistered(any(ChannelHandlerContext.class));
    }

    @Test
    public void ensureDefaultChannelId() {
        TestChannel channel = new TestChannel();
        final ChannelId channelId = channel.id();
        assertTrue(channelId instanceof DefaultChannelId);
    }

    @Test
    @EnabledForJreRange(min = JRE.JAVA_9)
    void processIdWithProcessHandleJava9() {
        ClassLoader loader = PlatformDependent.getClassLoader(DefaultChannelId.class);
        int processHandlePid = DefaultChannelId.processHandlePid(loader);
        assertTrue(processHandlePid != -1);
        assertEquals(DefaultChannelId.jmxPid(loader), processHandlePid);
        assertEquals(DefaultChannelId.defaultProcessId(), processHandlePid);
    }

    @Test
    @EnabledForJreRange(max = JRE.JAVA_8)
    void processIdWithJmxPrejava9() {
        ClassLoader loader = PlatformDependent.getClassLoader(DefaultChannelId.class);
        int processHandlePid = DefaultChannelId.processHandlePid(loader);
        assertEquals(-1, processHandlePid);
        assertEquals(DefaultChannelId.defaultProcessId(), DefaultChannelId.jmxPid(loader));
    }

    @Test
    public void testClosedChannelExceptionCarryIOException() throws Exception {
        final IOException ioException = new IOException();
        final Channel channel = new TestChannel() {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free