diff --git a/buffer/src/test/java/io/netty/buffer/SimpleLeakAwareCompositeByteBufTest.java b/buffer/src/test/java/io/netty/buffer/SimpleLeakAwareCompositeByteBufTest.java index 580bcdbb72..e173ddcb5c 100644 --- a/buffer/src/test/java/io/netty/buffer/SimpleLeakAwareCompositeByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/SimpleLeakAwareCompositeByteBufTest.java @@ -15,7 +15,9 @@ */ package io.netty.buffer; +import io.netty.util.ByteProcessor; import io.netty.util.ResourceLeakTracker; +import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -23,7 +25,9 @@ import org.junit.Test; import java.util.ArrayDeque; import java.util.Queue; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; public class SimpleLeakAwareCompositeByteBufTest extends WrappedCompositeByteBufTest { @@ -131,6 +135,26 @@ public class SimpleLeakAwareCompositeByteBufTest extends WrappedCompositeByteBuf assertWrapped(newBuffer(8).asReadOnly()); } + @Test + public void forEachByteUnderLeakDetectionShouldNotThrowException() { + CompositeByteBuf buf = (CompositeByteBuf) newBuffer(8); + assertThat(buf, CoreMatchers.instanceOf(SimpleLeakAwareCompositeByteBuf.class)); + CompositeByteBuf comp = (CompositeByteBuf) newBuffer(8); + assertThat(comp, CoreMatchers.instanceOf(SimpleLeakAwareCompositeByteBuf.class)); + + ByteBuf inner = comp.alloc().directBuffer(1).writeByte(0); + comp.addComponent(true, inner); + buf.addComponent(true, comp); + + assertEquals(-1, buf.forEachByte(new ByteProcessor() { + @Override + public boolean process(byte value) { + return true; + } + })); + assertTrue(buf.release()); + } + protected final void assertWrapped(ByteBuf buf) { try { assertSame(clazz, buf.getClass());