From 5dd35448a2282bab8f004318460d570c989d5356 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 24 Apr 2013 18:47:36 +0900 Subject: [PATCH] Add a failing test that will pass once #1306 is fixed --- .../handler/codec/ReplayingDecoderTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java b/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java index 90d219e2c8..b48e115204 100644 --- a/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java @@ -20,7 +20,9 @@ import io.netty.buffer.ByteBufIndexFinder; import io.netty.buffer.MessageBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundByteHandlerAdapter; import io.netty.channel.embedded.EmbeddedByteChannel; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; @@ -44,7 +46,8 @@ public class ReplayingDecoderTest { // Truncated input ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' })); assertNull(ch.readInbound()); - ch.close(); + + ch.finish(); assertNull(ch.readInbound()); } @@ -60,4 +63,28 @@ public class ReplayingDecoderTest { out.add(msg); } } + + @Test + @Ignore("needs a fix") + public void testReplacement() throws Exception { + EmbeddedByteChannel ch = new EmbeddedByteChannel(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'})); + assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound()); + + ch.finish(); + assertNull(ch.readInbound()); + } + + private static final class BloatedLineDecoder extends ChannelInboundByteHandlerAdapter { + @Override + protected void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) throws Exception { + ctx.pipeline().replace(this, "less-bloated", new LineDecoder()); + } + } }