Home / Class/ EpollDatagramChannelTest Class — netty Architecture

EpollDatagramChannelTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  fbe8add9_85f0_e800_9650_c89745ed8cad["EpollDatagramChannelTest"]
  39849237_31df_8d76_f0f3_fd77e1d115e8["EpollDatagramChannelTest.java"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|defined in| 39849237_31df_8d76_f0f3_fd77e1d115e8
  bd693c1b_75b8_948e_d978_caccd3f8e08d["setUp()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| bd693c1b_75b8_948e_d978_caccd3f8e08d
  ea66a718_2ee6_4267_838a_dc673f877266["testDefaultMaxMessagePerRead()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| ea66a718_2ee6_4267_838a_dc673f877266
  9df27a12_84bc_5ae0_ad9c_7152ca43cfa6["testNotActiveNoLocalRemoteAddress()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| 9df27a12_84bc_5ae0_ad9c_7152ca43cfa6
  bfc5d22e_865c_146d_17dc_562eb8438bac["testActiveHasLocalAddress()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| bfc5d22e_865c_146d_17dc_562eb8438bac
  64595fba_1e3c_9e86_9875_7cac41c8cce6["testLocalAddressBeforeAndAfterBind()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| 64595fba_1e3c_9e86_9875_7cac41c8cce6
  553e86cc_11de_a68b_148b_dccad908010f["checkNotActiveNoLocalRemoteAddress()"]
  fbe8add9_85f0_e800_9650_c89745ed8cad -->|method| 553e86cc_11de_a68b_148b_dccad908010f

Relationship Graph

Source Code

transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramChannelTest.java lines 40–116

public class EpollDatagramChannelTest {

    @BeforeEach
    public void setUp() {
        Epoll.ensureAvailability();
    }

    @Test
    public void testDefaultMaxMessagePerRead() {
        EpollDatagramChannel channel = new EpollDatagramChannel();
        assertEquals(16, channel.config().getMaxMessagesPerRead());
        channel.unsafe().closeForcibly();
    }

    @Test
    public void testNotActiveNoLocalRemoteAddress() throws IOException {
        checkNotActiveNoLocalRemoteAddress(new EpollDatagramChannel());
        checkNotActiveNoLocalRemoteAddress(new EpollDatagramChannel(SocketProtocolFamily.INET));
        checkNotActiveNoLocalRemoteAddress(new EpollDatagramChannel(SocketProtocolFamily.INET6));
    }

    @Test
    public void testActiveHasLocalAddress() throws IOException {
        Socket socket = Socket.newSocketDgram();
        EpollDatagramChannel channel = new EpollDatagramChannel(socket.intValue());
        InetSocketAddress localAddress = channel.localAddress();
        assertTrue(channel.active);
        assertNotNull(localAddress);
        assertEquals(socket.localAddress(), localAddress);
        channel.fd().close();
    }

    @Test
    public void testLocalAddressBeforeAndAfterBind() {
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, EpollIoHandler.newFactory());
        try {
            TestHandler handler = new TestHandler();
            InetSocketAddress localAddressBeforeBind = new InetSocketAddress(LOCALHOST, 0);

            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(EpollDatagramChannel.class)
                    .localAddress(localAddressBeforeBind)
                    .handler(handler);

            ChannelFuture future = bootstrap.bind().syncUninterruptibly();

            assertNull(handler.localAddress);

            SocketAddress localAddressAfterBind = future.channel().localAddress();
            assertNotNull(localAddressAfterBind);
            assertTrue(localAddressAfterBind instanceof InetSocketAddress);
            assertTrue(((InetSocketAddress) localAddressAfterBind).getPort() != 0);

            future.channel().close().syncUninterruptibly();
        } finally {
            group.shutdownGracefully();
        }
    }

    private static void checkNotActiveNoLocalRemoteAddress(EpollDatagramChannel channel) throws IOException {
        assertFalse(channel.active);
        assertNull(channel.localAddress());
        assertNull(channel.remoteAddress());
        channel.fd().close();
    }

    private static final class TestHandler extends ChannelInboundHandlerAdapter {
        private volatile SocketAddress localAddress;

        @Override
        public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
            this.localAddress = ctx.channel().localAddress();
            super.channelRegistered(ctx);
        }
    }
}

Frequently Asked Questions

What is the EpollDatagramChannelTest class?
EpollDatagramChannelTest is a class in the netty codebase, defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramChannelTest.java.
Where is EpollDatagramChannelTest defined?
EpollDatagramChannelTest is defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramChannelTest.java at line 40.

Analyze Your Own Codebase

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

Try Supermodel Free