Skip to content

Commit 60b06df

Browse files
author
Norman Maurer
committed
Add tests to try to track down some buffer issues
1 parent 70f5a4e commit 60b06df

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,4 +1720,32 @@ public boolean process(byte value) throws Exception {
17201720

17211721
assertThat(lastIndex.get(), is(CAPACITY / 4));
17221722
}
1723+
1724+
@Test
1725+
public void testInternalNioBuffer() {
1726+
testInternalNioBuffer(128);
1727+
testInternalNioBuffer(1024);
1728+
testInternalNioBuffer(4 * 1024);
1729+
testInternalNioBuffer(64 * 1024);
1730+
testInternalNioBuffer(32 * 1024 * 1024);
1731+
testInternalNioBuffer(64 * 1024 * 1024);
1732+
}
1733+
1734+
private void testInternalNioBuffer(int a) {
1735+
ByteBuf buffer = freeLater(newBuffer(2));
1736+
ByteBuffer buf = buffer.internalNioBuffer(0, 1);
1737+
assertEquals(1, buf.remaining());
1738+
1739+
for (int i = 0; i < a; i++) {
1740+
buffer.writeByte(i);
1741+
}
1742+
1743+
buf = buffer.internalNioBuffer(0, a);
1744+
assertEquals(a, buf.remaining());
1745+
1746+
for (int i = 0; i < a; i++) {
1747+
assertEquals((byte) i, buf.get());
1748+
}
1749+
assertFalse(buf.hasRemaining());
1750+
}
17231751
}

buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,4 +566,10 @@ public void testDuplicateEmpty() {
566566
assertEquals(0, buf.numComponents());
567567
assertEquals(0, freeLater(buf.duplicate()).readableBytes());
568568
}
569+
570+
@Test(expected = UnsupportedOperationException.class)
571+
@Override
572+
public void testInternalNioBuffer() {
573+
super.testInternalNioBuffer();
574+
}
569575
}

buffer/src/test/java/io/netty/buffer/DuplicateByteBufTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.netty.buffer;
1717

18+
import org.junit.Ignore;
1819
import org.junit.Test;
1920

2021
import static org.junit.Assert.*;
@@ -42,4 +43,13 @@ protected ByteBuf[] components() {
4243
public void shouldNotAllowNullInConstructor() {
4344
new DuplicatedByteBuf(null);
4445
}
46+
47+
@Ignore
48+
@Test
49+
// Test which shows bug
50+
// https://github.com/netty/netty/issues/1802
51+
public void testInternalNioBuffer() {
52+
super.testInternalNioBuffer();
53+
}
54+
4555
}

buffer/src/test/java/io/netty/buffer/SlicedByteBufTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ protected ByteBuf[] components() {
4646
public void shouldNotAllowNullInConstructor() {
4747
new SlicedByteBuf(null, 0, 0);
4848
}
49+
50+
@Test(expected = IndexOutOfBoundsException.class)
51+
@Override
52+
public void testInternalNioBuffer() {
53+
super.testInternalNioBuffer();
54+
}
4955
}

0 commit comments

Comments
 (0)