Home / Class/ DefaultChannelIdTest Class — netty Architecture

DefaultChannelIdTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f["DefaultChannelIdTest"]
  6a19041f_6bd8_86b6_9260_bd5814a5ec06["DefaultChannelIdTest.java"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|defined in| 6a19041f_6bd8_86b6_9260_bd5814a5ec06
  b3f36984_3775_75a4_bb69_9d10d284af5a["testShortText()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| b3f36984_3775_75a4_bb69_9d10d284af5a
  fa9e3cec_2d78_bb71_d4a2_2a0f0f957858["testLongText()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| fa9e3cec_2d78_bb71_d4a2_2a0f0f957858
  a6348f7a_300f_15f6_2827_b7881fada340["testIdempotentMachineId()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| a6348f7a_300f_15f6_2827_b7881fada340
  39c4582e_3624_933b_c01d_e296f8f6c685["testIdempotentProcessId()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| 39c4582e_3624_933b_c01d_e296f8f6c685
  028cfa47_f085_9404_13ef_fd941992d64e["testSerialization()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| 028cfa47_f085_9404_13ef_fd941992d64e
  c8694f39_0cfa_09b2_fa3e_9e4e1b22de4b["testDeserialization()"]
  0daa1ce3_4bc0_db70_656c_f03cb2bebe1f -->|method| c8694f39_0cfa_09b2_fa3e_9e4e1b22de4b

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/DefaultChannelIdTest.java lines 32–109

@SuppressWarnings("DynamicRegexReplaceableByCompiledPattern")
public class DefaultChannelIdTest {

    @Test
    public void testShortText() {
        String text = DefaultChannelId.newInstance().asShortText();
        assertTrue(text.matches("^[0-9a-f]{8}$"));
    }

    @Test
    public void testLongText() {
        String text = DefaultChannelId.newInstance().asLongText();
        assertTrue(text.matches("^[0-9a-f]{16}-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{16}-[0-9a-f]{8}$"));
    }

    @Test
    public void testIdempotentMachineId() {
        String a = DefaultChannelId.newInstance().asLongText().substring(0, 16);
        String b = DefaultChannelId.newInstance().asLongText().substring(0, 16);
        assertEquals(a, b);
    }

    @Test
    public void testIdempotentProcessId() {
        String a = DefaultChannelId.newInstance().asLongText().substring(17, 21);
        String b = DefaultChannelId.newInstance().asLongText().substring(17, 21);
        assertEquals(a, b);
    }

    @Test
    public void testSerialization() throws Exception {
        ChannelId a = DefaultChannelId.newInstance();
        ChannelId b;

        ByteBuf buf = Unpooled.buffer();
        try (ObjectOutputStream out = new ObjectOutputStream(new ByteBufOutputStream(buf))) {
            out.writeObject(a);
            out.flush();
        }

        try (ObjectInputStream in = new ObjectInputStream(new ByteBufInputStream(buf, true))) {
            b = (ChannelId) in.readObject();
        }

        assertEquals(a, b);
        assertNotSame(a, b);
        assertEquals(a.asLongText(), b.asLongText());
    }

    @Test
    public void testDeserialization() throws Exception {
        // DefaultChannelId with 8 byte machineId
        final DefaultChannelId c8 = new DefaultChannelId(
                new byte[] {
                        (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
                        (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef
                },
                0x000052af,
                0x00000000,
                0x06504f638eb4c386L,
                0xd964df5e);

        // DefaultChannelId with 6 byte machineId
        final DefaultChannelId c6 =
                new DefaultChannelId(
                        new byte[] {
                                (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
                                (byte) 0x89, (byte) 0xab,
                        },
                        0xce005283,
                        0x00000001,
                        0x069e6dce9eb4516fL,
                        0x721757b7);

        assertEquals("0123456789abcdef-000052af-00000000-06504f638eb4c386-d964df5e", c8.asLongText());
        assertEquals("0123456789ab-ce005283-00000001-069e6dce9eb4516f-721757b7", c6.asLongText());
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free