Home / Class/ LengthFieldPrependerTest Class — netty Architecture

LengthFieldPrependerTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  08a86b56_30dc_8ade_d1cb_23b1a52cba79["LengthFieldPrependerTest"]
  2752789d_9f2d_fde7_80ad_b6c05f645be1["LengthFieldPrependerTest.java"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|defined in| 2752789d_9f2d_fde7_80ad_b6c05f645be1
  ee09856c_a84a_5e15_f0fa_5acbf893f473["setUp()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| ee09856c_a84a_5e15_f0fa_5acbf893f473
  da94bacb_c338_869b_98f5_9fbf8fbb8e0e["testPrependLength()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| da94bacb_c338_869b_98f5_9fbf8fbb8e0e
  8ab10f3c_798b_9559_60b0_912b3041f7eb["testPrependLengthIncludesLengthFieldLength()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| 8ab10f3c_798b_9559_60b0_912b3041f7eb
  9dd21210_d694_9d4c_b131_63b57380395d["testPrependAdjustedLength()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| 9dd21210_d694_9d4c_b131_63b57380395d
  26caf189_6d42_94a1_4481_5ad4f44c4be3["testAdjustedLengthLessThanZero()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| 26caf189_6d42_94a1_4481_5ad4f44c4be3
  696c6ed0_379c_33e2_5b0b_067894dd2578["testPrependLengthInLittleEndian()"]
  08a86b56_30dc_8ade_d1cb_23b1a52cba79 -->|method| 696c6ed0_379c_33e2_5b0b_067894dd2578

Relationship Graph

Source Code

codec-base/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java lines 34–116

public class LengthFieldPrependerTest {

    private ByteBuf msg;

    @BeforeEach
    public void setUp() throws Exception {
        msg = copiedBuffer("A", CharsetUtil.ISO_8859_1);
    }

    @Test
    public void testPrependLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(msg.readableBytes(), buf.readInt());
        buf.release();

        buf = ch.readOutbound();
        assertSame(buf, msg);
        buf.release();
    }

    @Test
    public void testPrependLengthIncludesLengthFieldLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(5, buf.readInt());
        buf.release();

        buf = ch.readOutbound();
        assertSame(buf, msg);
        buf.release();
    }

    @Test
    public void testPrependAdjustedLength() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        assertEquals(msg.readableBytes() - 1, buf.readInt());
        buf.release();

        buf = ch.readOutbound();
        assertSame(buf, msg);
        buf.release();
    }

    @Test
    public void testAdjustedLengthLessThanZero() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -2));
        try {
            ch.writeOutbound(msg);
            fail(EncoderException.class.getSimpleName() + " must be raised.");
        } catch (EncoderException e) {
            // Expected
        }
    }

    @Test
    public void testPrependLengthInLittleEndian() throws Exception {
        final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(ByteOrder.LITTLE_ENDIAN, 4, 0, false));
        ch.writeOutbound(msg);
        ByteBuf buf = ch.readOutbound();
        assertEquals(4, buf.readableBytes());
        byte[] writtenBytes = new byte[buf.readableBytes()];
        buf.getBytes(0, writtenBytes);
        assertEquals(1, writtenBytes[0]);
        assertEquals(0, writtenBytes[1]);
        assertEquals(0, writtenBytes[2]);
        assertEquals(0, writtenBytes[3]);
        buf.release();

        buf = ch.readOutbound();
        assertSame(buf, msg);
        buf.release();
        assertFalse(ch.finish(), "The channel must have been completely read");
    }

Frequently Asked Questions

What is the LengthFieldPrependerTest class?
LengthFieldPrependerTest is a class in the netty codebase, defined in codec-base/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java.
Where is LengthFieldPrependerTest defined?
LengthFieldPrependerTest is defined in codec-base/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java at line 34.

Analyze Your Own Codebase

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

Try Supermodel Free