Home / Function/ testReusePort() — netty Function Reference

testReusePort() — netty Function Reference

Architecture documentation for the testReusePort() function in QuicPortReuseTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  fdab0759_86e5_36b9_e197_e0333880b0fd["testReusePort()"]
  79a8a7c7_3f01_8924_7f42_31b6eaa3881b["QuicPortReuseTest"]
  fdab0759_86e5_36b9_e197_e0333880b0fd -->|defined in| 79a8a7c7_3f01_8924_7f42_31b6eaa3881b
  style fdab0759_86e5_36b9_e197_e0333880b0fd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicPortReuseTest.java lines 40–137

    @ParameterizedTest
    @MethodSource("newSslTaskExecutors")
    @Timeout(100)
    public void testReusePort(Executor executor) throws Throwable {
        int numBytes = 1000;
        final AtomicInteger byteCounter = new AtomicInteger();

        ChannelOption<Boolean> reusePort = QuicTestUtils.soReusePortOption();
        int numBinds = reusePort == null ? 1 : 4;
        int numConnects = 16;

        List<Channel> serverChannels = new ArrayList<>();
        Bootstrap serverBootstrap = QuicTestUtils.newServerBootstrap()
                .handler(new QuicCodecDispatcher() {
                    @Override
                    protected void initChannel(Channel channel, int localConnectionIdLength,
                                               QuicConnectionIdGenerator idGenerator) {
                        ChannelHandler codec = QuicTestUtils.newQuicServerBuilder(executor)
                                .localConnectionIdLength(localConnectionIdLength)
                                .connectionIdAddressGenerator(idGenerator)
                                .tokenHandler(InsecureQuicTokenHandler.INSTANCE)
                                .handler(QuicTestUtils.NOOP_HANDLER)
                                .streamHandler(new ChannelInboundHandlerAdapter() {

                                    @Override
                                    public boolean isSharable() {
                                        return true;
                                    }

                                    @Override
                                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
                                        byteCounter.addAndGet(((ByteBuf) msg).readableBytes());
                                        ReferenceCountUtil.release(msg);
                                    }
                                }).build();
                        channel.pipeline().addLast(codec);
                    }
                });

        if (reusePort != null) {
            serverBootstrap.option(reusePort, true);
        }

        SocketAddress bindAddress = null;
        for (int i = 0; i < numBinds; i++) {
            Channel bindChannel;
            if (bindAddress == null) {
                bindChannel = serverBootstrap.bind().sync().channel();
            } else {
                bindChannel = serverBootstrap.bind(bindAddress).sync().channel();
            }
            serverChannels.add(bindChannel);
            if (bindAddress == null) {
                bindAddress = bindChannel.localAddress();
            }
        }

        Channel channel = QuicTestUtils.newClient(executor);
        QuicChannelBootstrap cb = QuicTestUtils.newQuicChannelBootstrap(channel)
                .handler(QuicTestUtils.NOOP_HANDLER)
                .streamHandler(QuicTestUtils.NOOP_HANDLER)
                .remoteAddress(bindAddress);
        List<QuicChannel> channels = new ArrayList<>();

        try {
            for (int i = 0; i < numConnects; i++) {
                channels.add(cb
                        .connect()
                        .get());
            }

            for (QuicChannel quicChannel: channels) {
                quicChannel.createStream(QuicStreamType.BIDIRECTIONAL,
                        new ChannelInboundHandlerAdapter() {
                            @Override
                            public void channelActive(ChannelHandlerContext ctx) {
                                ctx.writeAndFlush(Unpooled.directBuffer().writeZero(numBytes))
                                        .addListener(ChannelFutureListener.CLOSE);
                            }
                        });
            }

Domain

Subdomains

Frequently Asked Questions

What does testReusePort() do?
testReusePort() is a function in the netty codebase, defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicPortReuseTest.java.
Where is testReusePort() defined?
testReusePort() is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicPortReuseTest.java at line 40.

Analyze Your Own Codebase

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

Try Supermodel Free