Home / Class/ ReplayingDecoderTest Class — netty Architecture

ReplayingDecoderTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  342ea63b_1bca_5900_7b37_0cc8ddc3402d["ReplayingDecoderTest"]
  5d169e27_346b_6317_7621_9ae5140d3800["ReplayingDecoderTest.java"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|defined in| 5d169e27_346b_6317_7621_9ae5140d3800
  276fd093_734c_d029_1800_b566c5e1a91f["testLineProtocol()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| 276fd093_734c_d029_1800_b566c5e1a91f
  b1dbb212_adb4_7f2d_fe52_c7c7eddaebf0["testReplacement()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| b1dbb212_adb4_7f2d_fe52_c7c7eddaebf0
  278d27cf_bf83_ba22_a610_468610f0f152["testSingleDecode()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| 278d27cf_bf83_ba22_a610_468610f0f152
  784a7821_3731_4891_063f_93d5ed6a12a9["testRemoveItself()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| 784a7821_3731_4891_063f_93d5ed6a12a9
  fa08f416_b7b8_071c_83f8_83cb90cdd60d["testRemoveItselfWithReplayError()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| fa08f416_b7b8_071c_83f8_83cb90cdd60d
  b51157eb_4049_977f_31ff_c552e1922dba["testRemoveItselfWriteBuffer()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| b51157eb_4049_977f_31ff_c552e1922dba
  2104eb56_9670_c934_977c_ebe5f3089e8b["testFireChannelReadCompleteOnInactive()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| 2104eb56_9670_c934_977c_ebe5f3089e8b
  bd2e091e_cef7_2695_62fb_71fb41df8777["testChannelInputShutdownEvent()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| bd2e091e_cef7_2695_62fb_71fb41df8777
  6075117b_2db1_ede0_b22c_1086558b8427["handlerRemovedWillNotReleaseBufferIfDecodeInProgress()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| 6075117b_2db1_ede0_b22c_1086558b8427
  f1e6d06b_9916_b3d2_ec90_4ddc4e22c0a3["assertCumulationReleased()"]
  342ea63b_1bca_5900_7b37_0cc8ddc3402d -->|method| f1e6d06b_9916_b3d2_ec90_4ddc4e22c0a3

Relationship Graph

Source Code

codec-base/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java lines 37–319

public class ReplayingDecoderTest {

    @Test
    public void testLineProtocol() {
        EmbeddedChannel ch = new EmbeddedChannel(new LineDecoder());

        // Ordinary input
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
        assertNull(ch.readInbound());
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'B' }));
        assertNull(ch.readInbound());
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
        assertNull(ch.readInbound());
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));

        ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' });
        ByteBuf buf2 = ch.readInbound();
        assertEquals(buf, buf2);

        buf.release();
        buf2.release();

        // Truncated input
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
        assertNull(ch.readInbound());

        ch.finish();
        assertNull(ch.readInbound());
    }

    private static final class LineDecoder extends ReplayingDecoder<Void> {

        LineDecoder() {
        }

        @Override
        protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
            ByteBuf msg = in.readBytes(in.bytesBefore((byte) '\n'));
            out.add(msg);
            in.skipBytes(1);
        }
    }

    @Test
    public void testReplacement() throws Exception {
        EmbeddedChannel ch = new EmbeddedChannel(new BloatedLineDecoder());

        // "AB" should be forwarded to LineDecoder by BloatedLineDecoder.
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'A', 'B'}));
        assertNull(ch.readInbound());

        // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n'}));

        ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' });
        ByteBuf buf2 = ch.readInbound();
        assertEquals(buf, buf2);

        buf.release();
        buf2.release();

        ch.finish();
        assertNull(ch.readInbound());
    }

    private static final class BloatedLineDecoder extends ChannelInboundHandlerAdapter {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            ctx.pipeline().replace(this, "less-bloated", new LineDecoder());
            ctx.pipeline().fireChannelRead(msg);
        }
    }

    @Test
    public void testSingleDecode() throws Exception {
        LineDecoder decoder = new LineDecoder();
        decoder.setSingleDecode(true);
        EmbeddedChannel ch = new EmbeddedChannel(decoder);

        // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n' , 'B', '\n'}));

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free