Home / Function/ testSegmentedDatagramPacket() — netty Function Reference

testSegmentedDatagramPacket() — netty Function Reference

Architecture documentation for the testSegmentedDatagramPacket() function in EpollDatagramUnicastTest.java from the netty codebase.

Function java Buffer Search called by 4

Entity Profile

Dependency Diagram

graph TD
  95e5314a_d0ff_6db1_b1ae_6c079f85dd17["testSegmentedDatagramPacket()"]
  10b176d1_e8aa_bbf1_f1ba_fff123bd29ed["EpollDatagramUnicastTest"]
  95e5314a_d0ff_6db1_b1ae_6c079f85dd17 -->|defined in| 10b176d1_e8aa_bbf1_f1ba_fff123bd29ed
  40e5559a_8bb3_69ec_7015_26c5d0fef26f["testSendSegmentedDatagramPacket()"]
  40e5559a_8bb3_69ec_7015_26c5d0fef26f -->|calls| 95e5314a_d0ff_6db1_b1ae_6c079f85dd17
  2909acef_b4a5_779b_fa63_c915521960f2["testSendSegmentedDatagramPacketComposite()"]
  2909acef_b4a5_779b_fa63_c915521960f2 -->|calls| 95e5314a_d0ff_6db1_b1ae_6c079f85dd17
  be3da79c_1075_12e7_f994_20abfde6fd28["testSendAndReceiveSegmentedDatagramPacket()"]
  be3da79c_1075_12e7_f994_20abfde6fd28 -->|calls| 95e5314a_d0ff_6db1_b1ae_6c079f85dd17
  84e1b9f9_05e2_f4c4_3a1a_50a4b5cdce43["testSendAndReceiveSegmentedDatagramPacketComposite()"]
  84e1b9f9_05e2_f4c4_3a1a_50a4b5cdce43 -->|calls| 95e5314a_d0ff_6db1_b1ae_6c079f85dd17
  style 95e5314a_d0ff_6db1_b1ae_6c079f85dd17 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java lines 114–193

    private void testSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb, boolean composite, boolean gro)
            throws Throwable {
        if (!(cb.group() instanceof IoEventLoopGroup &&
                ((IoEventLoopGroup) cb.group()).isIoType(EpollIoHandler.class))) {
            // Only supported for the native epoll transport.
            return;
        }

        if (gro && !(sb.group() instanceof IoEventLoopGroup) &&
                ((IoEventLoopGroup) sb.group()).isIoType(EpollIoHandler.class)) {
            // Only supported for the native epoll transport.
            return;
        }
        assumeTrue(EpollDatagramChannel.isSegmentedDatagramPacketSupported());
        Channel sc = null;
        Channel cc = null;

        try {
            cb.handler(new SimpleChannelInboundHandler<Object>() {
                @Override
                public void channelRead0(ChannelHandlerContext ctx, Object msgs) {
                    // Nothing will be sent.
                }
            });

            cc = cb.bind(newSocketAddress()).sync().channel();

            final int numBuffers = 16;
            final int segmentSize = 512;
            int bufferCapacity = numBuffers * segmentSize;
            final CountDownLatch latch = new CountDownLatch(numBuffers);
            AtomicReference<Throwable> errorRef = new AtomicReference<Throwable>();
            if (gro) {
                // Enable GRO and also ensure we can read everything with one read as otherwise
                // we will drop things on the floor.
                sb.option(EpollChannelOption.UDP_GRO, true);
                sb.option(ChannelOption.RECVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(bufferCapacity));
            }
            sc = sb.handler(new SimpleChannelInboundHandler<DatagramPacket>() {
                @Override
                public void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) {
                    if (packet.content().readableBytes() == segmentSize) {
                        latch.countDown();
                    }
                }
            }).bind(newSocketAddress()).sync().channel();

            if (sc instanceof EpollDatagramChannel) {
                assertEquals(gro, sc.config().getOption(EpollChannelOption.UDP_GRO));
            }
            InetSocketAddress addr = sendToAddress((InetSocketAddress) sc.localAddress());
            final ByteBuf buffer;
            if (composite) {
                CompositeByteBuf compositeBuffer = Unpooled.compositeBuffer();
                for (int i = 0; i < numBuffers; i++) {
                    compositeBuffer.addComponent(true,
                            Unpooled.directBuffer(segmentSize).writeZero(segmentSize));
                }
                buffer = compositeBuffer;
            } else {
                buffer = Unpooled.directBuffer(bufferCapacity).writeZero(bufferCapacity);
            }
            cc.writeAndFlush(new io.netty.channel.unix.SegmentedDatagramPacket(buffer, segmentSize, addr)).sync();

            if (!latch.await(10, TimeUnit.SECONDS)) {
                Throwable error = errorRef.get();
                if (error != null) {
                    throw error;
                }
                fail();
            }
        } finally {
            if (cc != null) {
                cc.close().sync();
            }
            if (sc != null) {
                sc.close().sync();
            }
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testSegmentedDatagramPacket() do?
testSegmentedDatagramPacket() is a function in the netty codebase, defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java.
Where is testSegmentedDatagramPacket() defined?
testSegmentedDatagramPacket() is defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java at line 114.
What calls testSegmentedDatagramPacket()?
testSegmentedDatagramPacket() is called by 4 function(s): testSendAndReceiveSegmentedDatagramPacket, testSendAndReceiveSegmentedDatagramPacketComposite, testSendSegmentedDatagramPacket, testSendSegmentedDatagramPacketComposite.

Analyze Your Own Codebase

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

Try Supermodel Free