Add tests to try to track down some buffer issues

This commit is contained in:
Norman Maurer 2013-08-30 07:58:45 +02:00
parent 4a5c840271
commit 0007fb81ef
4 changed files with 50 additions and 0 deletions

View File

@ -1720,4 +1720,32 @@ public abstract class AbstractByteBufTest {
assertThat(lastIndex.get(), is(CAPACITY / 4));
}
@Test
public void testInternalNioBuffer() {
testInternalNioBuffer(128);
testInternalNioBuffer(1024);
testInternalNioBuffer(4 * 1024);
testInternalNioBuffer(64 * 1024);
testInternalNioBuffer(32 * 1024 * 1024);
testInternalNioBuffer(64 * 1024 * 1024);
}
private void testInternalNioBuffer(int a) {
ByteBuf buffer = freeLater(newBuffer(2));
ByteBuffer buf = buffer.internalNioBuffer(0, 1);
assertEquals(1, buf.remaining());
for (int i = 0; i < a; i++) {
buffer.writeByte(i);
}
buf = buffer.internalNioBuffer(0, a);
assertEquals(a, buf.remaining());
for (int i = 0; i < a; i++) {
assertEquals((byte) i, buf.get());
}
assertFalse(buf.hasRemaining());
}
}

View File

@ -566,4 +566,10 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
assertEquals(0, buf.numComponents());
assertEquals(0, freeLater(buf.duplicate()).readableBytes());
}
@Test(expected = UnsupportedOperationException.class)
@Override
public void testInternalNioBuffer() {
super.testInternalNioBuffer();
}
}

View File

@ -15,6 +15,7 @@
*/
package io.netty.buffer;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
@ -42,4 +43,13 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
public void shouldNotAllowNullInConstructor() {
new DuplicatedByteBuf(null);
}
@Ignore
@Test
// Test which shows bug
// https://github.com/netty/netty/issues/1802
public void testInternalNioBuffer() {
super.testInternalNioBuffer();
}
}

View File

@ -46,4 +46,10 @@ public class SlicedByteBufTest extends AbstractByteBufTest {
public void shouldNotAllowNullInConstructor() {
new SlicedByteBuf(null, 0, 0);
}
@Test(expected = IndexOutOfBoundsException.class)
@Override
public void testInternalNioBuffer() {
super.testInternalNioBuffer();
}
}