Home / Class/ ByteToMessageDecoderTest Class — netty Architecture

ByteToMessageDecoderTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  b1c999fe_35fb_8b70_a958_296cffb0616a["ByteToMessageDecoderTest"]
  7546c8b4_deb3_9871_fb31_44de7e30e65b["ByteToMessageDecoderTest.java"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|defined in| 7546c8b4_deb3_9871_fb31_44de7e30e65b
  6f8ca1c9_2e0a_cabe_0014_b5ad61e0d753["testRemoveItself()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 6f8ca1c9_2e0a_cabe_0014_b5ad61e0d753
  2958e749_3d93_7b3e_0aa1_45be254190fe["testRemoveItselfWriteBuffer()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 2958e749_3d93_7b3e_0aa1_45be254190fe
  2a3dc621_f315_4402_029b_ebc4e8161397["testInternalBufferClearReadAll()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 2a3dc621_f315_4402_029b_ebc4e8161397
  14862962_3758_4dbc_fb0e_cba4adb4b40a["testInternalBufferClearReadPartly()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 14862962_3758_4dbc_fb0e_cba4adb4b40a
  5082856a_b229_862d_0072_81f9b24f56a3["EmbeddedChannel()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 5082856a_b229_862d_0072_81f9b24f56a3
  c086c53d_4e79_5402_b1ef_099d8db02408["handlerRemovedWillNotReleaseBufferIfDecodeInProgress()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| c086c53d_4e79_5402_b1ef_099d8db02408
  c77d087e_a5a5_cb71_6c42_0b7e063121da["assertCumulationReleased()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| c77d087e_a5a5_cb71_6c42_0b7e063121da
  9718af44_d4ad_5564_6a71_991f41945996["testFireChannelReadCompleteOnInactive()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 9718af44_d4ad_5564_6a71_991f41945996
  9247eabb_a09b_cac5_89fd_993c11b416f4["testRemoveWhileInCallDecode()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 9247eabb_a09b_cac5_89fd_993c11b416f4
  99af3ed4_5872_2bc2_ddbc_5d558d033dc0["testDecodeLastEmptyBuffer()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 99af3ed4_5872_2bc2_ddbc_5d558d033dc0
  5185bf22_9ccd_65c9_b750_375e3adc5f50["testDecodeLastNonEmptyBuffer()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 5185bf22_9ccd_65c9_b750_375e3adc5f50
  055e5723_0f5b_8b83_9de3_bedcb348a8e8["assertBuffer()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 055e5723_0f5b_8b83_9de3_bedcb348a8e8
  90dce904_8279_671e_9cd4_a212751e3b18["testReadOnlyBuffer()"]
  b1c999fe_35fb_8b70_a958_296cffb0616a -->|method| 90dce904_8279_671e_9cd4_a212751e3b18

Relationship Graph

Source Code

codec-base/src/test/java/io/netty/handler/codec/ByteToMessageDecoderTest.java lines 49–763

public class ByteToMessageDecoderTest {

    @Test
    public void testRemoveItself() {
        EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
            private boolean removed;

            @Override
            protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
                assertFalse(removed);
                in.readByte();
                ctx.pipeline().remove(this);
                removed = true;
            }
        });

        ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
        channel.writeInbound(buf.copy());
        ByteBuf b = channel.readInbound();
        assertEquals(b, buf.skipBytes(1));
        b.release();
        buf.release();
    }

    @Test
    public void testRemoveItselfWriteBuffer() {
        final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a', 'b', 'c'});
        EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
            private boolean removed;

            @Override
            protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
                assertFalse(removed);
                in.readByte();
                ctx.pipeline().remove(this);

                // This should not let it keep call decode
                buf.writeByte('d');
                removed = true;
            }
        });

        channel.writeInbound(buf.copy());
        ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {'b', 'c'});
        ByteBuf b = channel.readInbound();
        assertEquals(expected, b);
        expected.release();
        buf.release();
        b.release();
    }

    /**
     * Verifies that internal buffer of the ByteToMessageDecoder is released once decoder is removed from pipeline. In
     * this case input is read fully.
     */
    @Test
    public void testInternalBufferClearReadAll() {
        final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a'});
        EmbeddedChannel channel = newInternalBufferTestChannel();
        assertFalse(channel.writeInbound(buf));
        assertFalse(channel.finish());
    }

    /**
     * Verifies that internal buffer of the ByteToMessageDecoder is released once decoder is removed from pipeline. In
     * this case input was not fully read.
     */
    @Test
    public void testInternalBufferClearReadPartly() {
        final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a', 'b'});
        EmbeddedChannel channel = newInternalBufferTestChannel();
        assertTrue(channel.writeInbound(buf));
        assertTrue(channel.finish());
        ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {'b'});
        ByteBuf b = channel.readInbound();
        assertEquals(expected, b);
        assertNull(channel.readInbound());
        expected.release();
        b.release();
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free