Home / Class/ QuicCodecDispatcherTest Class — netty Architecture

QuicCodecDispatcherTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  fadd0a68_af3f_4e94_ce6f_6f6ce1e2f7b1["QuicCodecDispatcherTest"]
  cd655053_fc38_aea5_aaf9_bbabb4083442["QuicCodecDispatcherTest.java"]
  fadd0a68_af3f_4e94_ce6f_6f6ce1e2f7b1 -->|defined in| cd655053_fc38_aea5_aaf9_bbabb4083442
  109ae264_d03b_6be0_7e28_dc77cf8e0c51["testPacketsAreDispatchedToCorrectChannel()"]
  fadd0a68_af3f_4e94_ce6f_6f6ce1e2f7b1 -->|method| 109ae264_d03b_6be0_7e28_dc77cf8e0c51
  6f052415_e9c7_32ed_5dfc_d9feba53afc9["writePacket()"]
  fadd0a68_af3f_4e94_ce6f_6f6ce1e2f7b1 -->|method| 6f052415_e9c7_32ed_5dfc_d9feba53afc9
  966439e3_9a5a_8edb_4236_f5d989c00dfd["DatagramPacket()"]
  fadd0a68_af3f_4e94_ce6f_6f6ce1e2f7b1 -->|method| 966439e3_9a5a_8edb_4236_f5d989c00dfd

Relationship Graph

Source Code

codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicCodecDispatcherTest.java lines 35–121

public class QuicCodecDispatcherTest {

    @Test
    public void testPacketsAreDispatchedToCorrectChannel() throws QuicException {
        short localConnectionIdLength = 16;

        AtomicInteger initChannelCalled = new AtomicInteger();
        QuicCodecDispatcher dispatcher = new QuicCodecDispatcher(localConnectionIdLength) {
            @Override
            protected void initChannel(Channel channel, int localConnectionIdLength,
                                       QuicConnectionIdGenerator idGenerator) {
                initChannelCalled.incrementAndGet();
            }
        };

        EmbeddedChannel[] channels = new EmbeddedChannel[8];
        for (int i = 0; i < channels.length; i++) {
            channels[i] = new EmbeddedChannel(dispatcher);
        }

        int numPackets = 0;
        for (int i = 0; i < 100; i++) {
            writePacket(channels, false, localConnectionIdLength);
            numPackets++;
            writePacket(channels, true, localConnectionIdLength);
            numPackets++;
        }

        for (int idx = 0; idx < channels.length; idx++) {
            EmbeddedChannel channel = channels[idx];
            for (;;) {
                DatagramPacket packet = channel.readInbound();
                    if (packet == null) {
                        break;
                    }
                try {
                    boolean hasShortHeader = QuicCodecDispatcher.hasShortHeader(packet.content());
                    ByteBuf id = QuicCodecDispatcher.getDestinationConnectionId(
                            packet.content(), localConnectionIdLength);
                    if (hasShortHeader) {
                        assertNotNull(id);
                        assertEquals(idx, QuicCodecDispatcher.decodeIdx(id));
                    } else {
                        assertNull(id);
                    }
                    numPackets--;
                } finally {
                    packet.release();
                }
            }
            assertFalse(channel.finishAndReleaseAll());
        }
        assertEquals(0, numPackets);
        assertEquals(channels.length, initChannelCalled.get());
    }

    private static void writePacket(EmbeddedChannel[] channels, boolean shortHeader, short localConnectionIdLength) {
        DatagramPacket packet = createQuicPacket(
                ThreadLocalRandom.current().nextInt(channels.length),
                shortHeader, localConnectionIdLength);
        channels[ThreadLocalRandom.current().nextInt(channels.length)].writeInbound(packet);
    }

    // See https://www.rfc-editor.org/rfc/rfc9000.html#section-17
    private static DatagramPacket createQuicPacket(int idx, boolean shortHeader, short localConnectionIdLength) {
        ByteBuf content = Unpooled.buffer();
        byte[] random = new byte[localConnectionIdLength];
        ThreadLocalRandom.current().nextBytes(random);

        if (shortHeader) {
            content.writeByte(0);
            int writerIndex = content.writerIndex();
            content.writeBytes(random);
            content.setShort(writerIndex, (short) idx);
        } else {
            content.writeByte(1);
            content.writeInt(7);
            content.writeByte((byte) localConnectionIdLength);
            int writerIndex = content.writerIndex();
            content.writeBytes(random);
            content.setShort(writerIndex, (short) idx);

Frequently Asked Questions

What is the QuicCodecDispatcherTest class?
QuicCodecDispatcherTest is a class in the netty codebase, defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicCodecDispatcherTest.java.
Where is QuicCodecDispatcherTest defined?
QuicCodecDispatcherTest is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicCodecDispatcherTest.java at line 35.

Analyze Your Own Codebase

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

Try Supermodel Free