Eliminate usage of releaseLater(...) to reduce memory usage during tests
Motiviation: We used ReferenceCountUtil.releaseLater(...) in our tests which simplifies a bit the releasing of ReferenceCounted objects. The problem with this is that while it simplifies stuff it increase memory usage a lot as memory may not be freed up in a timely manner. Modifications: - Deprecate releaseLater(...) - Remove usage of releaseLater(...) in tests. Result: Less memory needed to build netty while running the tests.
This commit is contained in:
parent
dbc080832e
commit
eff8413d9d
@ -44,7 +44,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.ReferenceCountUtil.*;
|
||||
import static io.netty.util.internal.EmptyArrays.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@ -873,7 +872,7 @@ public abstract class AbstractByteBufTest {
|
||||
@Test
|
||||
public void testRandomDirectBufferTransfer() {
|
||||
byte[] tmp = new byte[BLOCK_SIZE * 2];
|
||||
ByteBuf value = releaseLater(directBuffer(BLOCK_SIZE * 2));
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(tmp);
|
||||
value.setBytes(0, tmp, 0, value.capacity());
|
||||
@ -881,7 +880,7 @@ public abstract class AbstractByteBufTest {
|
||||
}
|
||||
|
||||
random.setSeed(seed);
|
||||
ByteBuf expectedValue = releaseLater(directBuffer(BLOCK_SIZE * 2));
|
||||
ByteBuf expectedValue = directBuffer(BLOCK_SIZE * 2);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(tmp);
|
||||
expectedValue.setBytes(0, tmp, 0, expectedValue.capacity());
|
||||
@ -891,6 +890,8 @@ public abstract class AbstractByteBufTest {
|
||||
assertEquals(expectedValue.getByte(j), value.getByte(j));
|
||||
}
|
||||
}
|
||||
value.release();
|
||||
expectedValue.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1037,7 +1038,7 @@ public abstract class AbstractByteBufTest {
|
||||
@Test
|
||||
public void testSequentialDirectBufferTransfer1() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ByteBuf value = releaseLater(directBuffer(BLOCK_SIZE * 2));
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -1051,7 +1052,7 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ByteBuf expectedValue = releaseLater(wrappedBuffer(expectedValueContent));
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
int valueOffset = random.nextInt(BLOCK_SIZE);
|
||||
@ -1065,12 +1066,14 @@ public abstract class AbstractByteBufTest {
|
||||
assertEquals(0, value.readerIndex());
|
||||
assertEquals(0, value.writerIndex());
|
||||
}
|
||||
value.release();
|
||||
expectedValue.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequentialDirectBufferTransfer2() {
|
||||
byte[] valueContent = new byte[BLOCK_SIZE * 2];
|
||||
ByteBuf value = releaseLater(directBuffer(BLOCK_SIZE * 2));
|
||||
ByteBuf value = directBuffer(BLOCK_SIZE * 2);
|
||||
buffer.writerIndex(0);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(valueContent);
|
||||
@ -1088,7 +1091,7 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
random.setSeed(seed);
|
||||
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
|
||||
ByteBuf expectedValue = releaseLater(wrappedBuffer(expectedValueContent));
|
||||
ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
|
||||
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
|
||||
random.nextBytes(expectedValueContent);
|
||||
value.setBytes(0, valueContent);
|
||||
@ -1104,6 +1107,8 @@ public abstract class AbstractByteBufTest {
|
||||
assertEquals(valueOffset, value.readerIndex());
|
||||
assertEquals(valueOffset + BLOCK_SIZE, value.writerIndex());
|
||||
}
|
||||
value.release();
|
||||
expectedValue.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1294,7 +1299,7 @@ public abstract class AbstractByteBufTest {
|
||||
for (int i = 0; i < buffer.capacity(); i += 4) {
|
||||
buffer.writeInt(i);
|
||||
}
|
||||
ByteBuf copy = releaseLater(copiedBuffer(buffer));
|
||||
ByteBuf copy = copiedBuffer(buffer);
|
||||
|
||||
// Make sure there's no effect if called when readerIndex is 0.
|
||||
buffer.readerIndex(CAPACITY / 4);
|
||||
@ -1334,6 +1339,7 @@ public abstract class AbstractByteBufTest {
|
||||
assertEquals(CAPACITY / 4 - 1, buffer.readerIndex());
|
||||
buffer.resetWriterIndex();
|
||||
assertEquals(CAPACITY / 3 - 1, buffer.writerIndex());
|
||||
copy.release();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1346,7 +1352,7 @@ public abstract class AbstractByteBufTest {
|
||||
for (int i = 0; i < buffer.capacity(); i ++) {
|
||||
buffer.writeByte((byte) i);
|
||||
}
|
||||
ByteBuf copy = releaseLater(copiedBuffer(buffer));
|
||||
ByteBuf copy = copiedBuffer(buffer);
|
||||
|
||||
// Discard the first (CAPACITY / 2 - 1) bytes.
|
||||
buffer.setIndex(CAPACITY / 2 - 1, CAPACITY - 1);
|
||||
@ -1356,6 +1362,7 @@ public abstract class AbstractByteBufTest {
|
||||
for (int i = 0; i < CAPACITY / 2; i ++) {
|
||||
assertEquals(copy.slice(CAPACITY / 2 - 1 + i, CAPACITY / 2 - i), buffer.slice(i, CAPACITY / 2 - i));
|
||||
}
|
||||
copy.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1412,7 +1419,7 @@ public abstract class AbstractByteBufTest {
|
||||
buffer.setIndex(readerIndex, writerIndex);
|
||||
|
||||
// Make sure all properties are copied.
|
||||
ByteBuf copy = releaseLater(buffer.copy());
|
||||
ByteBuf copy = buffer.copy();
|
||||
assertEquals(0, copy.readerIndex());
|
||||
assertEquals(buffer.readableBytes(), copy.writerIndex());
|
||||
assertEquals(buffer.readableBytes(), copy.capacity());
|
||||
@ -1426,6 +1433,7 @@ public abstract class AbstractByteBufTest {
|
||||
assertTrue(buffer.getByte(readerIndex) != copy.getByte(0));
|
||||
copy.setByte(1, (byte) (copy.getByte(1) + 1));
|
||||
assertTrue(buffer.getByte(readerIndex + 1) != copy.getByte(1));
|
||||
copy.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1559,9 +1567,11 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
ByteBuf copied = copiedBuffer("Hello, World!", CharsetUtil.ISO_8859_1);
|
||||
buffer.clear();
|
||||
buffer.writeBytes(releaseLater(copiedBuffer("Hello, World!", CharsetUtil.ISO_8859_1)));
|
||||
buffer.writeBytes(copied);
|
||||
assertEquals("Hello, World!", buffer.toString(CharsetUtil.ISO_8859_1));
|
||||
copied.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1644,8 +1654,8 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
ByteBuf elemA = releaseLater(buffer(15));
|
||||
ByteBuf elemB = releaseLater(directBuffer(15));
|
||||
ByteBuf elemA = buffer(15);
|
||||
ByteBuf elemB = directBuffer(15);
|
||||
elemA.writeBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 });
|
||||
elemB.writeBytes(new byte[] { 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9 });
|
||||
|
||||
@ -1654,9 +1664,10 @@ public abstract class AbstractByteBufTest {
|
||||
set.add(elemB);
|
||||
|
||||
assertEquals(2, set.size());
|
||||
assertTrue(set.contains(releaseLater(elemA.copy())));
|
||||
ByteBuf elemACopy = elemA.copy();
|
||||
assertTrue(set.contains(elemACopy));
|
||||
|
||||
ByteBuf elemBCopy = releaseLater(elemB.copy());
|
||||
ByteBuf elemBCopy = elemB.copy();
|
||||
assertTrue(set.contains(elemBCopy));
|
||||
|
||||
buffer.clear();
|
||||
@ -1671,6 +1682,10 @@ public abstract class AbstractByteBufTest {
|
||||
assertTrue(set.remove(buffer));
|
||||
assertFalse(set.contains(elemB));
|
||||
assertEquals(0, set.size());
|
||||
elemA.release();
|
||||
elemB.release();
|
||||
elemACopy.release();
|
||||
elemBCopy.release();
|
||||
}
|
||||
|
||||
// Test case for https://github.com/netty/netty/issues/325
|
||||
@ -1763,7 +1778,7 @@ public abstract class AbstractByteBufTest {
|
||||
}
|
||||
|
||||
private void testInternalNioBuffer(int a) {
|
||||
ByteBuf buffer = releaseLater(newBuffer(2));
|
||||
ByteBuf buffer = newBuffer(2);
|
||||
ByteBuffer buf = buffer.internalNioBuffer(0, 1);
|
||||
assertEquals(1, buf.remaining());
|
||||
|
||||
@ -1778,6 +1793,7 @@ public abstract class AbstractByteBufTest {
|
||||
assertEquals(data[i], buf.get());
|
||||
}
|
||||
assertFalse(buf.hasRemaining());
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1794,7 +1810,7 @@ public abstract class AbstractByteBufTest {
|
||||
final byte[] bytes = new byte[8];
|
||||
random.nextBytes(bytes);
|
||||
|
||||
final ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
final ByteBuf buffer = newBuffer(8);
|
||||
buffer.writeBytes(bytes);
|
||||
final CountDownLatch latch = new CountDownLatch(60000);
|
||||
final CyclicBarrier barrier = new CyclicBarrier(11);
|
||||
@ -1832,6 +1848,7 @@ public abstract class AbstractByteBufTest {
|
||||
}
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
barrier.await(5, TimeUnit.SECONDS);
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1848,7 +1865,7 @@ public abstract class AbstractByteBufTest {
|
||||
final byte[] bytes = new byte[8];
|
||||
random.nextBytes(bytes);
|
||||
|
||||
final ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
final ByteBuf buffer = newBuffer(8);
|
||||
buffer.writeBytes(bytes);
|
||||
final CountDownLatch latch = new CountDownLatch(60000);
|
||||
final CyclicBarrier barrier = new CyclicBarrier(11);
|
||||
@ -1886,6 +1903,7 @@ public abstract class AbstractByteBufTest {
|
||||
}
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
barrier.await(5, TimeUnit.SECONDS);
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1902,7 +1920,7 @@ public abstract class AbstractByteBufTest {
|
||||
final byte[] bytes = new byte[8];
|
||||
random.nextBytes(bytes);
|
||||
|
||||
final ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
final ByteBuf buffer = newBuffer(8);
|
||||
buffer.writeBytes(bytes);
|
||||
final AtomicReference<Throwable> cause = new AtomicReference<Throwable>();
|
||||
final CountDownLatch latch = new CountDownLatch(60000);
|
||||
@ -1941,20 +1959,25 @@ public abstract class AbstractByteBufTest {
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
barrier.await(5, TimeUnit.SECONDS);
|
||||
assertNull(cause.get());
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void readByteThrowsIndexOutOfBoundsException() {
|
||||
final ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
buffer.writeByte(0);
|
||||
assertEquals((byte) 0, buffer.readByte());
|
||||
buffer.readByte();
|
||||
final ByteBuf buffer = newBuffer(8);
|
||||
try {
|
||||
buffer.writeByte(0);
|
||||
assertEquals((byte) 0, buffer.readByte());
|
||||
buffer.readByte();
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("ForLoopThatDoesntUseLoopVariable")
|
||||
public void testNioBufferExposeOnlyRegion() {
|
||||
final ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
final ByteBuf buffer = newBuffer(8);
|
||||
byte[] data = new byte[8];
|
||||
random.nextBytes(data);
|
||||
buffer.writeBytes(data);
|
||||
@ -1966,6 +1989,7 @@ public abstract class AbstractByteBufTest {
|
||||
for (int i = 1; nioBuf.hasRemaining(); i++) {
|
||||
assertEquals(data[i], nioBuf.get());
|
||||
}
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
// See:
|
||||
@ -1973,9 +1997,10 @@ public abstract class AbstractByteBufTest {
|
||||
// - https://github.com/netty/netty/issues/2580
|
||||
@Test
|
||||
public void testLittleEndianWithExpand() {
|
||||
ByteBuf buffer = releaseLater(newBuffer(0)).order(LITTLE_ENDIAN);
|
||||
ByteBuf buffer = newBuffer(0).order(LITTLE_ENDIAN);
|
||||
buffer.writeInt(0x12345678);
|
||||
assertEquals("78563412", ByteBufUtil.hexDump(buffer));
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
private ByteBuf releasedBuffer() {
|
||||
@ -2066,17 +2091,32 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testGetBytesAfterRelease() {
|
||||
releasedBuffer().getBytes(0, releaseLater(buffer(8)));
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().getBytes(0, buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testGetBytesAfterRelease2() {
|
||||
releasedBuffer().getBytes(0, releaseLater(buffer()), 1);
|
||||
ByteBuf buffer = buffer();
|
||||
try {
|
||||
releasedBuffer().getBytes(0, buffer, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testGetBytesAfterRelease3() {
|
||||
releasedBuffer().getBytes(0, releaseLater(buffer()), 0, 1);
|
||||
ByteBuf buffer = buffer();
|
||||
try {
|
||||
releasedBuffer().getBytes(0, buffer, 0, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@ -2151,17 +2191,32 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testSetBytesAfterRelease() {
|
||||
releasedBuffer().setBytes(0, releaseLater(buffer()));
|
||||
ByteBuf buffer = buffer();
|
||||
try {
|
||||
releasedBuffer().setBytes(0, buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testSetBytesAfterRelease2() {
|
||||
releasedBuffer().setBytes(0, releaseLater(buffer()), 1);
|
||||
ByteBuf buffer = buffer();
|
||||
try {
|
||||
releasedBuffer().setBytes(0, buffer, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testSetBytesAfterRelease3() {
|
||||
releasedBuffer().setBytes(0, releaseLater(buffer()), 0, 1);
|
||||
ByteBuf buffer = buffer();
|
||||
try {
|
||||
releasedBuffer().setBytes(0, buffer, 0, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@ -2266,17 +2321,32 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testReadBytesAfterRelease2() {
|
||||
releasedBuffer().readBytes(releaseLater(buffer(8)));
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().readBytes(buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testReadBytesAfterRelease3() {
|
||||
releasedBuffer().readBytes(releaseLater(buffer(8), 1));
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().readBytes(buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testReadBytesAfterRelease4() {
|
||||
releasedBuffer().readBytes(releaseLater(buffer(8)), 0, 1);
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().readBytes(buffer, 0, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@ -2356,17 +2426,32 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testWriteBytesAfterRelease() {
|
||||
releasedBuffer().writeBytes(releaseLater(buffer(8)));
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().writeBytes(buffer);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testWriteBytesAfterRelease2() {
|
||||
releasedBuffer().writeBytes(releaseLater(copiedBuffer(new byte[8])), 1);
|
||||
ByteBuf buffer = copiedBuffer(new byte[8]);
|
||||
try {
|
||||
releasedBuffer().writeBytes(buffer, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
public void testWriteBytesAfterRelease3() {
|
||||
releasedBuffer().writeBytes(releaseLater(buffer(8)), 0, 1);
|
||||
ByteBuf buffer = buffer(8);
|
||||
try {
|
||||
releasedBuffer().writeBytes(buffer, 0, 1);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalReferenceCountException.class)
|
||||
@ -2512,12 +2597,13 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyNioBuffers() throws Exception {
|
||||
ByteBuf buffer = releaseLater(newBuffer(8));
|
||||
ByteBuf buffer = newBuffer(8);
|
||||
buffer.clear();
|
||||
assertFalse(buffer.isReadable());
|
||||
ByteBuffer[] nioBuffers = buffer.nioBuffers();
|
||||
assertEquals(1, nioBuffers.length);
|
||||
assertFalse(nioBuffers[0].hasRemaining());
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -2533,7 +2619,7 @@ public abstract class AbstractByteBufTest {
|
||||
private void testGetReadOnlyDst(boolean direct) {
|
||||
byte[] bytes = { 'a', 'b', 'c', 'd' };
|
||||
|
||||
ByteBuf buffer = releaseLater(newBuffer(bytes.length));
|
||||
ByteBuf buffer = newBuffer(bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
|
||||
ByteBuffer dst = direct ? ByteBuffer.allocateDirect(bytes.length) : ByteBuffer.allocate(bytes.length);
|
||||
@ -2545,6 +2631,7 @@ public abstract class AbstractByteBufTest {
|
||||
// expected
|
||||
}
|
||||
assertEquals(0, readOnlyDst.position());
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -28,7 +28,6 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.ReferenceCountUtil.*;
|
||||
import static io.netty.util.internal.EmptyArrays.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@ -96,8 +95,8 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
*/
|
||||
@Test
|
||||
public void testComponentAtOffset() {
|
||||
CompositeByteBuf buf = releaseLater((CompositeByteBuf) wrappedBuffer(new byte[]{1, 2, 3, 4, 5},
|
||||
new byte[]{4, 5, 6, 7, 8, 9, 26}));
|
||||
CompositeByteBuf buf = (CompositeByteBuf) wrappedBuffer(new byte[]{1, 2, 3, 4, 5},
|
||||
new byte[]{4, 5, 6, 7, 8, 9, 26});
|
||||
|
||||
//Ensure that a random place will be fine
|
||||
assertEquals(5, buf.componentAtOffset(2).capacity());
|
||||
@ -113,15 +112,17 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertNotNull(_buf.getByte(0));
|
||||
assertNotNull(_buf.getByte(_buf.readableBytes() - 1));
|
||||
}
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscardReadBytes3() {
|
||||
ByteBuf a, b;
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = releaseLater(wrappedBuffer(
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 5).order(order),
|
||||
wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 5, 5).order(order)));
|
||||
wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 5, 5).order(order));
|
||||
a.skipBytes(6);
|
||||
a.markReaderIndex();
|
||||
b.skipBytes(6);
|
||||
@ -152,11 +153,14 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
b.resetWriterIndex();
|
||||
assertEquals(a.writerIndex(), b.writerIndex());
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoConsolidation() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer(2));
|
||||
CompositeByteBuf buf = compositeBuffer(2);
|
||||
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 1 }));
|
||||
assertEquals(1, buf.numComponents());
|
||||
@ -170,11 +174,13 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertTrue(buf.hasArray());
|
||||
assertNotNull(buf.array());
|
||||
assertEquals(0, buf.arrayOffset());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompositeToSingleBuffer() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer(3));
|
||||
CompositeByteBuf buf = compositeBuffer(3);
|
||||
|
||||
buf.addComponent(wrappedBuffer(new byte[] {1, 2, 3}));
|
||||
assertEquals(1, buf.numComponents());
|
||||
@ -191,11 +197,13 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
byte[] bytes = nioBuffer.array();
|
||||
assertEquals(6, bytes.length);
|
||||
assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 6}, bytes);
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullConsolidation() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer(Integer.MAX_VALUE));
|
||||
CompositeByteBuf buf = compositeBuffer(Integer.MAX_VALUE);
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 1 }));
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 2, 3 }));
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 4, 5, 6 }));
|
||||
@ -205,11 +213,13 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertTrue(buf.hasArray());
|
||||
assertNotNull(buf.array());
|
||||
assertEquals(0, buf.arrayOffset());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRangedConsolidation() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer(Integer.MAX_VALUE));
|
||||
CompositeByteBuf buf = compositeBuffer(Integer.MAX_VALUE);
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 1 }));
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 2, 3 }));
|
||||
buf.addComponent(wrappedBuffer(new byte[] { 4, 5, 6 }));
|
||||
@ -220,23 +230,27 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertEquals(wrappedBuffer(new byte[] { 1 }), buf.component(0));
|
||||
assertEquals(wrappedBuffer(new byte[] { 2, 3, 4, 5, 6 }), buf.component(1));
|
||||
assertEquals(wrappedBuffer(new byte[] { 7, 8, 9, 10 }), buf.component(2));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompositeWrappedBuffer() {
|
||||
ByteBuf header = releaseLater(buffer(12)).order(order);
|
||||
ByteBuf payload = releaseLater(buffer(512)).order(order);
|
||||
ByteBuf header = buffer(12).order(order);
|
||||
ByteBuf payload = buffer(512).order(order);
|
||||
|
||||
header.writeBytes(new byte[12]);
|
||||
payload.writeBytes(new byte[512]);
|
||||
|
||||
ByteBuf buffer = releaseLater(wrappedBuffer(header, payload));
|
||||
ByteBuf buffer = wrappedBuffer(header, payload);
|
||||
|
||||
assertEquals(12, header.readableBytes());
|
||||
assertEquals(512, payload.readableBytes());
|
||||
|
||||
assertEquals(12 + 512, buffer.readableBytes());
|
||||
assertEquals(2, buffer.nioBufferCount());
|
||||
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -244,222 +258,323 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
ByteBuf a, b;
|
||||
// XXX Same tests with several buffers in wrappedCheckedBuffer
|
||||
// Different length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1 }).order(order),
|
||||
wrappedBuffer(new byte[] { 2 }).order(order)));
|
||||
wrappedBuffer(new byte[] { 2 }).order(order));
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Same content, same firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[]{1}).order(order),
|
||||
wrappedBuffer(new byte[]{2}).order(order),
|
||||
wrappedBuffer(new byte[]{3}).order(order)));
|
||||
wrappedBuffer(new byte[]{3}).order(order));
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Same content, different firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 2).order(order),
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order)));
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order));
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Different content, same firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1, 2 }).order(order),
|
||||
wrappedBuffer(new byte[] { 4 }).order(order)));
|
||||
wrappedBuffer(new byte[] { 4 }).order(order));
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Different content, different firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 2).order(order),
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order)));
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order));
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Same content, same firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 }).order(order),
|
||||
wrappedBuffer(new byte[] { 4, 5, 6 }).order(order),
|
||||
wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order)));
|
||||
wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order));
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Same content, different firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5).order(order),
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order)));
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Different content, same firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1, 2, 3, 4, 6 }).order(order),
|
||||
wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order)));
|
||||
wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order));
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
// Different content, different firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order));
|
||||
b = releaseLater(wrappedBuffer(
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5).order(order),
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order)));
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order));
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrappedBuffer() {
|
||||
|
||||
assertEquals(16, wrappedBuffer(wrappedBuffer(ByteBuffer.allocateDirect(16))).capacity());
|
||||
ByteBuf a = wrappedBuffer(wrappedBuffer(ByteBuffer.allocateDirect(16)));
|
||||
assertEquals(16, a.capacity());
|
||||
a.release();
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(wrappedBuffer(new byte[][] { new byte[] { 1, 2, 3 } }).order(order)));
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
ByteBuf b = wrappedBuffer(wrappedBuffer(new byte[][] { new byte[] { 1, 2, 3 } }).order(order));
|
||||
assertEquals(a, b);
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
releaseLater(wrappedBuffer(wrappedBuffer(
|
||||
new byte[] { 1 },
|
||||
new byte[] { 2 },
|
||||
new byte[] { 3 }).order(order))));
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(new ByteBuf[] {
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)
|
||||
}));
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = wrappedBuffer(wrappedBuffer(
|
||||
new byte[] { 1 },
|
||||
new byte[] { 2 },
|
||||
new byte[] { 3 }).order(order));
|
||||
assertEquals(a, b);
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
releaseLater(wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1 }).order(order),
|
||||
wrappedBuffer(new byte[] { 2 }).order(order),
|
||||
wrappedBuffer(new byte[] { 3 }).order(order))));
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(wrappedBuffer(new ByteBuffer[] {
|
||||
ByteBuffer.wrap(new byte[] { 1, 2, 3 })
|
||||
})));
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = wrappedBuffer(new ByteBuf[] {
|
||||
wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)
|
||||
});
|
||||
assertEquals(a, b);
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
releaseLater(wrappedBuffer(wrappedBuffer(
|
||||
ByteBuffer.wrap(new byte[] { 1 }),
|
||||
ByteBuffer.wrap(new byte[] { 2 }),
|
||||
ByteBuffer.wrap(new byte[] { 3 })))));
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 1 }).order(order),
|
||||
wrappedBuffer(new byte[] { 2 }).order(order),
|
||||
wrappedBuffer(new byte[] { 3 }).order(order));
|
||||
assertEquals(a, b);
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 })).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new ByteBuffer[] {
|
||||
ByteBuffer.wrap(new byte[] { 1, 2, 3 })
|
||||
}));
|
||||
assertEquals(a, b);
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
|
||||
a = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order));
|
||||
b = wrappedBuffer(wrappedBuffer(
|
||||
ByteBuffer.wrap(new byte[] { 1 }),
|
||||
ByteBuffer.wrap(new byte[] { 2 }),
|
||||
ByteBuffer.wrap(new byte[] { 3 })));
|
||||
assertEquals(a, b);
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrittenBuffersEquals() {
|
||||
//XXX Same tests than testEquals with written AggregateChannelBuffers
|
||||
ByteBuf a, b;
|
||||
ByteBuf a, b, c;
|
||||
// Different length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(wrappedBuffer(new byte[] { 1 }, new byte[1])).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }, new byte[1])).order(order);
|
||||
c = wrappedBuffer(new byte[] { 2 }).order(order);
|
||||
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 2 })).order(order));
|
||||
b.writeBytes(c);
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Same content, same firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(wrappedBuffer(new byte[] { 1 }, new byte[2]))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }, new byte[2])).order(order);
|
||||
c = wrappedBuffer(new byte[] { 2 }).order(order);
|
||||
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 2);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 2 })).order(order));
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 3 })).order(order));
|
||||
b.writeBytes(c);
|
||||
c.release();
|
||||
c = wrappedBuffer(new byte[] { 3 }).order(order);
|
||||
|
||||
b.writeBytes(c);
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Same content, different firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3)).order(order);
|
||||
c = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1)).order(order));
|
||||
b.writeBytes(c);
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Different content, same firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(wrappedBuffer(new byte[] { 1, 2 }, new byte[1])).order(order)));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2 }, new byte[1])).order(order);
|
||||
c = wrappedBuffer(new byte[] { 4 }).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 4 })).order(order));
|
||||
b.writeBytes(c);
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Different content, different firstIndex, short length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3)).order(order);
|
||||
c = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1)).order(order));
|
||||
b.writeBytes(c);
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Same content, same firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(wrappedBuffer(new byte[] { 1, 2, 3 }, new byte[7]))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }, new byte[7])).order(order);
|
||||
c = wrappedBuffer(new byte[] { 4, 5, 6 }).order(order);
|
||||
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 7);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 4, 5, 6 })).order(order));
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 7, 8, 9, 10 })).order(order));
|
||||
b.writeBytes(c);
|
||||
c.release();
|
||||
c = wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order);
|
||||
b.writeBytes(c);
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Same content, different firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10)).order(order);
|
||||
c = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(releaseLater(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5)).order(order));
|
||||
b.writeBytes(c);
|
||||
assertTrue(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Different content, same firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3, 4, 6 }, new byte[5])).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3, 4, 6 }, new byte[5])).order(order);
|
||||
c = wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(releaseLater(wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 })).order(order));
|
||||
b.writeBytes(c);
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
|
||||
// Different content, different firstIndex, long length.
|
||||
a = releaseLater(wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })).order(order);
|
||||
b = releaseLater(wrappedBuffer(releaseLater(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10))).order(order));
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
|
||||
b = wrappedBuffer(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10)).order(order);
|
||||
c = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order);
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(releaseLater(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5)).order(order));
|
||||
b.writeBytes(c);
|
||||
assertFalse(ByteBufUtil.equals(a, b));
|
||||
|
||||
a.release();
|
||||
b.release();
|
||||
c.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyBuffer() {
|
||||
ByteBuf b = releaseLater(wrappedBuffer(new byte[]{1, 2}, new byte[]{3, 4}));
|
||||
ByteBuf b = wrappedBuffer(new byte[]{1, 2}, new byte[]{3, 4});
|
||||
b.readBytes(new byte[4]);
|
||||
b.readBytes(EMPTY_BYTES);
|
||||
b.release();
|
||||
}
|
||||
|
||||
// Test for https://github.com/netty/netty/issues/1060
|
||||
@Test
|
||||
public void testReadWithEmptyCompositeBuffer() {
|
||||
ByteBuf buf = releaseLater(compositeBuffer());
|
||||
ByteBuf buf = compositeBuffer();
|
||||
int n = 65;
|
||||
for (int i = 0; i < n; i ++) {
|
||||
buf.writeByte(1);
|
||||
assertEquals(1, buf.readByte());
|
||||
}
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComponentMustBeSlice() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(buffer(4).setIndex(1, 3));
|
||||
assertThat(buf.component(0), is(instanceOf(SlicedByteBuf.class)));
|
||||
assertThat(buf.component(0).capacity(), is(2));
|
||||
assertThat(buf.component(0).maxCapacity(), is(2));
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -468,7 +583,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
ByteBuf c2 = buffer().writeByte(2).retain();
|
||||
ByteBuf c3 = buffer().writeByte(3).retain(2);
|
||||
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
assertThat(buf.refCnt(), is(1));
|
||||
buf.addComponents(c1, c2, c3);
|
||||
|
||||
@ -485,6 +600,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
c3.release(2);
|
||||
c2.release();
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -529,7 +645,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
ByteBuf c2 = buffer().writeByte(2).retain();
|
||||
ByteBuf c3 = buffer().writeByte(3).retain(2);
|
||||
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
assertThat(buf.refCnt(), is(1));
|
||||
|
||||
List<ByteBuf> components = new ArrayList<ByteBuf>();
|
||||
@ -547,11 +663,12 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
c3.release(2);
|
||||
c2.release();
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedLayout() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(
|
||||
compositeBuffer()
|
||||
.addComponent(wrappedBuffer(new byte[]{1, 2}))
|
||||
@ -563,39 +680,50 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertThat(nioBuffers[0].get(), is((byte) 2));
|
||||
assertThat(nioBuffers[1].remaining(), is(1));
|
||||
assertThat(nioBuffers[1].get(), is((byte) 3));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveLastComponent() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
|
||||
assertEquals(1, buf.numComponents());
|
||||
buf.removeComponent(0);
|
||||
assertEquals(0, buf.numComponents());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyEmpty() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
assertEquals(0, buf.numComponents());
|
||||
assertEquals(0, releaseLater(buf.copy()).readableBytes());
|
||||
|
||||
ByteBuf copy = buf.copy();
|
||||
assertEquals(0, copy.readableBytes());
|
||||
|
||||
buf.release();
|
||||
copy.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateEmpty() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
assertEquals(0, buf.numComponents());
|
||||
assertEquals(0, releaseLater(buf.duplicate()).readableBytes());
|
||||
assertEquals(0, buf.duplicate().readableBytes());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveLastComponentWithOthersLeft() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
|
||||
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
|
||||
assertEquals(2, buf.numComponents());
|
||||
buf.removeComponent(1);
|
||||
assertEquals(1, buf.numComponents());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -632,7 +760,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
}
|
||||
|
||||
private static void testGatheringWrites(ByteBuf buf1, ByteBuf buf2) throws Exception {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(buf1.writeBytes(new byte[]{1, 2}));
|
||||
buf.addComponent(buf2.writeBytes(new byte[]{1, 2}));
|
||||
buf.writerIndex(3);
|
||||
@ -645,6 +773,8 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
byte[] data = new byte[2];
|
||||
buf.getBytes(1, data);
|
||||
assertArrayEquals(data, channel.writtenBytes());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -714,7 +844,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
}
|
||||
|
||||
private static void testGatheringWritesPartial(ByteBuf buf1, ByteBuf buf2, boolean slice) throws Exception {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf1.writeBytes(new byte[]{1, 2, 3, 4});
|
||||
buf2.writeBytes(new byte[]{1, 2, 3, 4});
|
||||
if (slice) {
|
||||
@ -744,6 +874,8 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
buf.getBytes(1, data);
|
||||
}
|
||||
assertArrayEquals(data, channel.writtenBytes());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -757,7 +889,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
}
|
||||
|
||||
private static void testGatheringWritesSingleBuf(ByteBuf buf1) throws Exception {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
buf.addComponent(buf1.writeBytes(new byte[]{1, 2, 3, 4}));
|
||||
buf.writerIndex(3);
|
||||
buf.readerIndex(1);
|
||||
@ -768,6 +900,8 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
byte[] data = new byte[2];
|
||||
buf.getBytes(1, data);
|
||||
assertArrayEquals(data, channel.writtenBytes());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -778,7 +912,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
@Test
|
||||
public void testisDirectMultipleBufs() {
|
||||
CompositeByteBuf buf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf buf = compositeBuffer();
|
||||
assertFalse(buf.isDirect());
|
||||
|
||||
buf.addComponent(directBuffer().writeByte(1));
|
||||
@ -789,12 +923,14 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
buf.addComponent(buffer().writeByte(1));
|
||||
assertFalse(buf.isDirect());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
// See https://github.com/netty/netty/issues/1976
|
||||
@Test
|
||||
public void testDiscardSomeReadBytes() {
|
||||
CompositeByteBuf cbuf = releaseLater(compositeBuffer());
|
||||
CompositeByteBuf cbuf = compositeBuffer();
|
||||
int len = 8 * 4;
|
||||
for (int i = 0; i < len; i += 4) {
|
||||
ByteBuf buf = buffer().writeInt(i);
|
||||
@ -807,6 +943,8 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
cbuf.readByte();
|
||||
|
||||
cbuf.discardSomeReadBytes();
|
||||
|
||||
cbuf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -19,14 +19,12 @@ package io.netty.buffer;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ByteBufProcessorTest {
|
||||
@Test
|
||||
public void testForward() {
|
||||
final ByteBuf buf = releaseLater(
|
||||
Unpooled.copiedBuffer("abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", CharsetUtil.ISO_8859_1));
|
||||
final ByteBuf buf = Unpooled.copiedBuffer("abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", CharsetUtil.ISO_8859_1);
|
||||
final int length = buf.readableBytes();
|
||||
|
||||
assertEquals(3, buf.forEachByte(0, length, ByteBufProcessor.FIND_CRLF));
|
||||
@ -40,12 +38,13 @@ public class ByteBufProcessorTest {
|
||||
assertEquals(24, buf.forEachByte(21, length - 21, ByteBufProcessor.FIND_LINEAR_WHITESPACE));
|
||||
assertEquals(28, buf.forEachByte(24, length - 24, ByteBufProcessor.FIND_NON_LINEAR_WHITESPACE));
|
||||
assertEquals(-1, buf.forEachByte(28, length - 28, ByteBufProcessor.FIND_LINEAR_WHITESPACE));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackward() {
|
||||
final ByteBuf buf = releaseLater(
|
||||
Unpooled.copiedBuffer("abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", CharsetUtil.ISO_8859_1));
|
||||
final ByteBuf buf = Unpooled.copiedBuffer("abc\r\n\ndef\r\rghi\n\njkl\0\0mno \t\tx", CharsetUtil.ISO_8859_1);
|
||||
final int length = buf.readableBytes();
|
||||
|
||||
assertEquals(27, buf.forEachByteDesc(0, length, ByteBufProcessor.FIND_LINEAR_WHITESPACE));
|
||||
@ -59,5 +58,7 @@ public class ByteBufProcessorTest {
|
||||
assertEquals(5, buf.forEachByteDesc(0, 9, ByteBufProcessor.FIND_CRLF));
|
||||
assertEquals(2, buf.forEachByteDesc(0, 6, ByteBufProcessor.FIND_NON_CRLF));
|
||||
assertEquals(-1, buf.forEachByteDesc(0, 3, ByteBufProcessor.FIND_CRLF));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package io.netty.buffer;
|
||||
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.EOFException;
|
||||
@ -31,7 +30,7 @@ public class ByteBufStreamTest {
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(0, 65536));
|
||||
ByteBuf buf = Unpooled.buffer(0, 65536);
|
||||
|
||||
try {
|
||||
new ByteBufOutputStream(null);
|
||||
@ -177,6 +176,8 @@ public class ByteBufStreamTest {
|
||||
}
|
||||
|
||||
assertEquals(buf.readerIndex(), in.readBytes());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -21,7 +21,6 @@ import org.junit.Test;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static io.netty.buffer.Unpooled.unreleasableBuffer;
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@ -31,36 +30,45 @@ public class ByteBufUtilTest {
|
||||
@Test
|
||||
public void testWriteUsAscii() {
|
||||
String usAscii = "NettyRocks";
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(usAscii.getBytes(CharsetUtil.US_ASCII));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeAscii(buf2, usAscii);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteUsAsciiWrapped() {
|
||||
String usAscii = "NettyRocks";
|
||||
ByteBuf buf = unreleasableBuffer(releaseLater(Unpooled.buffer(16)));
|
||||
ByteBuf buf = unreleasableBuffer(Unpooled.buffer(16));
|
||||
assertWrapped(buf);
|
||||
buf.writeBytes(usAscii.getBytes(CharsetUtil.US_ASCII));
|
||||
ByteBuf buf2 = unreleasableBuffer(releaseLater(Unpooled.buffer(16)));
|
||||
ByteBuf buf2 = unreleasableBuffer(Unpooled.buffer(16));
|
||||
assertWrapped(buf2);
|
||||
ByteBufUtil.writeAscii(buf2, usAscii);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.unwrap().release();
|
||||
buf2.unwrap().release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteUtf8() {
|
||||
String usAscii = "Some UTF-8 like äÄ∏ŒŒ";
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(usAscii.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, usAscii);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,12 +80,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uDC00')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,12 +98,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uDC00')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -102,12 +116,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uD800')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,12 +135,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uD800')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -134,12 +154,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uD800')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -150,12 +173,15 @@ public class ByteBufUtilTest {
|
||||
.append('\uDC00')
|
||||
.append('b')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -163,12 +189,15 @@ public class ByteBufUtilTest {
|
||||
String surrogateString = new StringBuilder(2)
|
||||
.append('\uD800')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -176,25 +205,31 @@ public class ByteBufUtilTest {
|
||||
String surrogateString = new StringBuilder(2)
|
||||
.append('\uDC00')
|
||||
.toString();
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf = Unpooled.buffer(16);
|
||||
buf.writeBytes(surrogateString.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf buf2 = Unpooled.buffer(16);
|
||||
ByteBufUtil.writeUtf8(buf2, surrogateString);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteUtf8Wrapped() {
|
||||
String usAscii = "Some UTF-8 like äÄ∏ŒŒ";
|
||||
ByteBuf buf = unreleasableBuffer(releaseLater(Unpooled.buffer(16)));
|
||||
ByteBuf buf = unreleasableBuffer(Unpooled.buffer(16));
|
||||
assertWrapped(buf);
|
||||
buf.writeBytes(usAscii.getBytes(CharsetUtil.UTF_8));
|
||||
ByteBuf buf2 = unreleasableBuffer(releaseLater(Unpooled.buffer(16)));
|
||||
ByteBuf buf2 = unreleasableBuffer(Unpooled.buffer(16));
|
||||
assertWrapped(buf2);
|
||||
ByteBufUtil.writeUtf8(buf2, usAscii);
|
||||
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
private static void assertWrapped(ByteBuf buf) {
|
||||
|
@ -33,6 +33,7 @@ import static io.netty.buffer.Unpooled.buffer;
|
||||
import static io.netty.buffer.Unpooled.compositeBuffer;
|
||||
import static io.netty.buffer.Unpooled.directBuffer;
|
||||
import static io.netty.buffer.Unpooled.unmodifiableBuffer;
|
||||
import static io.netty.buffer.Unpooled.wrappedBuffer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -65,98 +66,148 @@ public class FixedCompositeByteBufTest {
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBoolean() {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setBoolean(0, true);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setBoolean(0, true);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetByte() {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setByte(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setByte(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesWithByteBuf() {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setBytes(0, Unpooled.wrappedBuffer(new byte[4]));
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
ByteBuf src = wrappedBuffer(new byte[4]);
|
||||
try {
|
||||
buf.setBytes(0, src);
|
||||
} finally {
|
||||
buf.release();
|
||||
src.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesWithByteBuffer() {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setBytes(0, ByteBuffer.wrap(new byte[4]));
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setBytes(0, ByteBuffer.wrap(new byte[4]));
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesWithInputStream() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setBytes(0, new ByteArrayInputStream(new byte[4]), 4);
|
||||
public void testSetBytesWithInputStream() throws IOException {
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setBytes(0, new ByteArrayInputStream(new byte[4]), 4);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesWithChannel() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setBytes(0, new ScatteringByteChannel() {
|
||||
@Override
|
||||
public long read(ByteBuffer[] dsts, int offset, int length) {
|
||||
return 0;
|
||||
}
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setBytes(0, new ScatteringByteChannel() {
|
||||
@Override
|
||||
public long read(ByteBuffer[] dsts, int offset, int length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long read(ByteBuffer[] dsts) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long read(ByteBuffer[] dsts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ByteBuffer dst) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int read(ByteBuffer dst) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}, 4);
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}, 4);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetChar() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setChar(0, 'b');
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setChar(0, 'b');
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetDouble() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setDouble(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setDouble(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetFloat() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setFloat(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setFloat(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetInt() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setInt(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setInt(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetLong() {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setLong(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setLong(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetMedium() throws IOException {
|
||||
ByteBuf buf = newBuffer(Unpooled.wrappedBuffer(new byte[8]));
|
||||
buf.setMedium(0, 1);
|
||||
ByteBuf buf = newBuffer(wrappedBuffer(new byte[8]));
|
||||
try {
|
||||
buf.setMedium(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -23,8 +23,6 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ReadOnlyBufferException;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
|
||||
public class ReadOnlyDirectByteBufferBufTest {
|
||||
|
||||
protected ByteBuf buffer(ByteBuffer buffer) {
|
||||
@ -37,62 +35,95 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConstructWithWritable() {
|
||||
releaseLater(buffer(allocate(1)));
|
||||
buffer(allocate(1));
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetByte() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setByte(0, 1);
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setByte(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetInt() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setInt(0, 1);
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setInt(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetShort() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setShort(0, 1);
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setShort(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetMedium() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setMedium(0, 1);
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setMedium(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetLong() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setLong(0, 1);
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setLong(0, 1);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesViaArray() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setBytes(0, "test".getBytes());
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setBytes(0, "test".getBytes());
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesViaBuffer() {
|
||||
ByteBuf buf = releaseLater(buffer(allocate(8).asReadOnlyBuffer()));
|
||||
buf.setBytes(0, Unpooled.copyInt(1));
|
||||
ByteBuf buf = buffer(allocate(8).asReadOnlyBuffer());
|
||||
ByteBuf copy = Unpooled.copyInt(1);
|
||||
try {
|
||||
buf.setBytes(0, copy);
|
||||
} finally {
|
||||
buf.release();
|
||||
copy.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ReadOnlyBufferException.class)
|
||||
public void testSetBytesViaStream() throws IOException {
|
||||
ByteBuf buf = releaseLater(buffer(ByteBuffer.allocateDirect(8).asReadOnlyBuffer()));
|
||||
buf.setBytes(0, new ByteArrayInputStream("test".getBytes()), 2);
|
||||
buf.release();
|
||||
ByteBuf buf = buffer(ByteBuffer.allocateDirect(8).asReadOnlyBuffer());
|
||||
try {
|
||||
buf.setBytes(0, new ByteArrayInputStream("test".getBytes()), 2);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReadByte() {
|
||||
ByteBuf buf = releaseLater(buffer(
|
||||
((ByteBuffer) allocate(2).put(new byte[] { (byte) 1, (byte) 2 }).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(
|
||||
((ByteBuffer) allocate(2).put(new byte[] { (byte) 1, (byte) 2 }).flip()).asReadOnlyBuffer());
|
||||
|
||||
Assert.assertEquals(1, buf.getByte(0));
|
||||
Assert.assertEquals(2, buf.getByte(1));
|
||||
@ -100,11 +131,13 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
Assert.assertEquals(1, buf.readByte());
|
||||
Assert.assertEquals(2, buf.readByte());
|
||||
Assert.assertFalse(buf.isReadable());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReadInt() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(8).putInt(1).putInt(2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(8).putInt(1).putInt(2).flip()).asReadOnlyBuffer());
|
||||
|
||||
Assert.assertEquals(1, buf.getInt(0));
|
||||
Assert.assertEquals(2, buf.getInt(4));
|
||||
@ -112,12 +145,14 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
Assert.assertEquals(1, buf.readInt());
|
||||
Assert.assertEquals(2, buf.readInt());
|
||||
Assert.assertFalse(buf.isReadable());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReadShort() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(8)
|
||||
.putShort((short) 1).putShort((short) 2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(8)
|
||||
.putShort((short) 1).putShort((short) 2).flip()).asReadOnlyBuffer());
|
||||
|
||||
Assert.assertEquals(1, buf.getShort(0));
|
||||
Assert.assertEquals(2, buf.getShort(2));
|
||||
@ -125,12 +160,14 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
Assert.assertEquals(1, buf.readShort());
|
||||
Assert.assertEquals(2, buf.readShort());
|
||||
Assert.assertFalse(buf.isReadable());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReadLong() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(16)
|
||||
.putLong(1).putLong(2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(16)
|
||||
.putLong(1).putLong(2).flip()).asReadOnlyBuffer());
|
||||
|
||||
Assert.assertEquals(1, buf.getLong(0));
|
||||
Assert.assertEquals(2, buf.getLong(8));
|
||||
@ -138,37 +175,47 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
Assert.assertEquals(1, buf.readLong());
|
||||
Assert.assertEquals(2, buf.readLong());
|
||||
Assert.assertFalse(buf.isReadable());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(16).putLong(1).putLong(2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf copy = releaseLater(buf.copy());
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(16).putLong(1).putLong(2).flip()).asReadOnlyBuffer());
|
||||
ByteBuf copy = buf.copy();
|
||||
|
||||
Assert.assertEquals(buf, copy);
|
||||
|
||||
buf.release();
|
||||
copy.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyWithOffset() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(16).putLong(1).putLong(2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf copy = releaseLater(buf.copy(1, 9));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(16).putLong(1).putLong(2).flip()).asReadOnlyBuffer());
|
||||
ByteBuf copy = buf.copy(1, 9);
|
||||
|
||||
Assert.assertEquals(buf.slice(1, 9), copy);
|
||||
|
||||
buf.release();
|
||||
copy.release();
|
||||
}
|
||||
|
||||
// Test for https://github.com/netty/netty/issues/1708
|
||||
@Test
|
||||
public void testWrapBufferWithNonZeroPosition() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(16)
|
||||
.putLong(1).flip().position(1)).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(16)
|
||||
.putLong(1).flip().position(1)).asReadOnlyBuffer());
|
||||
|
||||
ByteBuf slice = buf.slice();
|
||||
Assert.assertEquals(buf, slice);
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapBufferRoundTrip() {
|
||||
ByteBuf buf = releaseLater(buffer(((ByteBuffer) allocate(16).putInt(1).putInt(2).flip()).asReadOnlyBuffer()));
|
||||
ByteBuf buf = buffer(((ByteBuffer) allocate(16).putInt(1).putInt(2).flip()).asReadOnlyBuffer());
|
||||
|
||||
Assert.assertEquals(1, buf.readInt());
|
||||
|
||||
@ -176,5 +223,7 @@ public class ReadOnlyDirectByteBufferBufTest {
|
||||
|
||||
// Ensure this can be accessed without throwing a BufferUnderflowException
|
||||
Assert.assertEquals(2, nioBuffer.getInt());
|
||||
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
@ -40,7 +41,6 @@ import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.release;
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@ -115,7 +115,9 @@ public class HttpClientCodecTest {
|
||||
|
||||
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
|
||||
"http://localhost/")));
|
||||
assertNotNull(releaseLater(ch.readOutbound()));
|
||||
ByteBuf buffer = (ByteBuf) ch.readOutbound();
|
||||
assertNotNull(buffer);
|
||||
buffer.release();
|
||||
try {
|
||||
ch.finish();
|
||||
fail();
|
||||
@ -129,15 +131,15 @@ public class HttpClientCodecTest {
|
||||
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
|
||||
EmbeddedChannel ch = new EmbeddedChannel(codec);
|
||||
|
||||
ch.writeOutbound(releaseLater(
|
||||
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")));
|
||||
assertNotNull(releaseLater(ch.readOutbound()));
|
||||
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
|
||||
ByteBuf buffer = (ByteBuf) ch.readOutbound();
|
||||
assertNotNull(buffer);
|
||||
buffer.release();
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(releaseLater(
|
||||
Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)));
|
||||
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpResponse.class));
|
||||
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'first'
|
||||
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'second'
|
||||
ch.writeInbound(Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
|
||||
assertThat(ch.readInbound(), instanceOf(HttpResponse.class));
|
||||
((HttpContent) ch.readInbound()).release(); // Chunk 'first'
|
||||
((HttpContent) ch.readInbound()).release(); // Chunk 'second'
|
||||
assertNull(ch.readInbound());
|
||||
|
||||
try {
|
||||
|
@ -27,9 +27,15 @@ import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class HttpObjectAggregatorTest {
|
||||
|
||||
@ -110,9 +116,9 @@ public class HttpObjectAggregatorTest {
|
||||
EmbeddedChannel embedder = new EmbeddedChannel(aggr);
|
||||
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
|
||||
HttpMethod.GET, "http://localhost");
|
||||
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk3 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test3", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk3 = new DefaultHttpContent(Unpooled.copiedBuffer("test3", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk4 = LastHttpContent.EMPTY_LAST_CONTENT;
|
||||
|
||||
assertFalse(embedder.writeInbound(message));
|
||||
@ -136,7 +142,7 @@ public class HttpObjectAggregatorTest {
|
||||
}
|
||||
assertFalse(embedder.writeInbound(chunk3.copy()));
|
||||
assertFalse(embedder.writeInbound(chunk4.copy()));
|
||||
embedder.finish();
|
||||
assertFalse(embedder.finish());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@ -219,8 +225,8 @@ public class HttpObjectAggregatorTest {
|
||||
HttpHeaders.set100ContinueExpected(message, true);
|
||||
HttpHeaders.setContentLength(message, 16);
|
||||
|
||||
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk3 = LastHttpContent.EMPTY_LAST_CONTENT;
|
||||
|
||||
// Send a request with 100-continue + large Content-Length header value.
|
||||
@ -314,8 +320,8 @@ public class HttpObjectAggregatorTest {
|
||||
HttpHeaders.set100ContinueExpected(message, true);
|
||||
HttpHeaders.setContentLength(message, 16);
|
||||
|
||||
HttpContent chunk1 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk2 = releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII)));
|
||||
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("some", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
|
||||
HttpContent chunk3 = LastHttpContent.EMPTY_LAST_CONTENT;
|
||||
|
||||
// Send a request with 100-continue + large Content-Length header value.
|
||||
|
@ -35,8 +35,11 @@ import org.junit.Test;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/** {@link HttpPostRequestDecoder} test case. */
|
||||
public class HttpPostRequestDecoderTest {
|
||||
@ -83,8 +86,8 @@ public class HttpPostRequestDecoderTest {
|
||||
// Create decoder instance to test.
|
||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||
|
||||
decoder.offer(releaseLater(new DefaultHttpContent(Unpooled.copiedBuffer(body, CharsetUtil.UTF_8))));
|
||||
decoder.offer(releaseLater(new DefaultHttpContent(Unpooled.EMPTY_BUFFER)));
|
||||
decoder.offer(new DefaultHttpContent(Unpooled.copiedBuffer(body, CharsetUtil.UTF_8)));
|
||||
decoder.offer(new DefaultHttpContent(Unpooled.EMPTY_BUFFER));
|
||||
|
||||
// Validate it's enough chunks to decode upload.
|
||||
assertTrue(decoder.hasNext());
|
||||
@ -253,8 +256,8 @@ public class HttpPostRequestDecoderTest {
|
||||
aSmallBuf.writeBytes(aBytes, 0, split);
|
||||
aLargeBuf.writeBytes(aBytes, split, aBytes.length - split);
|
||||
|
||||
aDecoder.offer(releaseLater(new DefaultHttpContent(aSmallBuf)));
|
||||
aDecoder.offer(releaseLater(new DefaultHttpContent(aLargeBuf)));
|
||||
aDecoder.offer(new DefaultHttpContent(aSmallBuf));
|
||||
aDecoder.offer(new DefaultHttpContent(aLargeBuf));
|
||||
|
||||
aDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||
|
||||
|
@ -26,50 +26,47 @@ import org.junit.Test;
|
||||
|
||||
|
||||
public class WebSocketFrameAggregatorTest {
|
||||
private final ByteBuf content1 = ReferenceCountUtil.releaseLater(
|
||||
Unpooled.copiedBuffer("Content1", CharsetUtil.UTF_8));
|
||||
private final ByteBuf content2 = ReferenceCountUtil.releaseLater(
|
||||
Unpooled.copiedBuffer("Content2", CharsetUtil.UTF_8));
|
||||
private final ByteBuf content3 = ReferenceCountUtil.releaseLater(
|
||||
Unpooled.copiedBuffer("Content3", CharsetUtil.UTF_8));
|
||||
private final ByteBuf aggregatedContent = ReferenceCountUtil.releaseLater(
|
||||
Unpooled.buffer().writeBytes(content1.duplicate())
|
||||
.writeBytes(content2.duplicate()).writeBytes(content3.duplicate()));
|
||||
private static final byte[] content1 = "Content1".getBytes(CharsetUtil.UTF_8);
|
||||
private static final byte[] content2 = "Content2".getBytes(CharsetUtil.UTF_8);
|
||||
private static final byte[] content3 = "Content3".getBytes(CharsetUtil.UTF_8);
|
||||
private static final byte[] aggregatedContent = new byte[content1.length + content2.length + content3.length];
|
||||
static {
|
||||
System.arraycopy(content1, 0, aggregatedContent, 0, content1.length);
|
||||
System.arraycopy(content2, 0, aggregatedContent, content1.length, content2.length);
|
||||
System.arraycopy(content3, 0, aggregatedContent, content1.length + content2.length, content3.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregationBinary() {
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new WebSocketFrameAggregator(Integer.MAX_VALUE));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, content1.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, content1.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new PingWebSocketFrame(content1.copy()));
|
||||
channel.writeInbound(new PongWebSocketFrame(content1.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, content3.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
channel.writeInbound(new PingWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
||||
|
||||
Assert.assertTrue(channel.finish());
|
||||
|
||||
BinaryWebSocketFrame frame = (BinaryWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame.isFinalFragment());
|
||||
Assert.assertEquals(1, frame.rsv());
|
||||
Assert.assertEquals(content1, frame.content());
|
||||
frame.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame.content()));
|
||||
|
||||
PingWebSocketFrame frame2 = (PingWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame2.isFinalFragment());
|
||||
Assert.assertEquals(0, frame2.rsv());
|
||||
Assert.assertEquals(content1, frame2.content());
|
||||
frame2.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
|
||||
|
||||
PongWebSocketFrame frame3 = (PongWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame3.isFinalFragment());
|
||||
Assert.assertEquals(0, frame3.rsv());
|
||||
Assert.assertEquals(content1, frame3.content());
|
||||
frame3.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
|
||||
|
||||
BinaryWebSocketFrame frame4 = (BinaryWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame4.isFinalFragment());
|
||||
Assert.assertEquals(0, frame4.rsv());
|
||||
Assert.assertEquals(aggregatedContent, frame4.content());
|
||||
frame4.release();
|
||||
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
||||
|
||||
Assert.assertNull(channel.readInbound());
|
||||
}
|
||||
@ -77,38 +74,34 @@ public class WebSocketFrameAggregatorTest {
|
||||
@Test
|
||||
public void testAggregationText() {
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new WebSocketFrameAggregator(Integer.MAX_VALUE));
|
||||
channel.writeInbound(new TextWebSocketFrame(true, 1, content1.copy()));
|
||||
channel.writeInbound(new TextWebSocketFrame(false, 0, content1.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new PingWebSocketFrame(content1.copy()));
|
||||
channel.writeInbound(new PongWebSocketFrame(content1.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, content3.copy()));
|
||||
channel.writeInbound(new TextWebSocketFrame(true, 1, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new TextWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
channel.writeInbound(new PingWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
||||
|
||||
Assert.assertTrue(channel.finish());
|
||||
|
||||
TextWebSocketFrame frame = (TextWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame.isFinalFragment());
|
||||
Assert.assertEquals(1, frame.rsv());
|
||||
Assert.assertEquals(content1, frame.content());
|
||||
frame.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame.content()));
|
||||
|
||||
PingWebSocketFrame frame2 = (PingWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame2.isFinalFragment());
|
||||
Assert.assertEquals(0, frame2.rsv());
|
||||
Assert.assertEquals(content1, frame2.content());
|
||||
frame2.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
|
||||
|
||||
PongWebSocketFrame frame3 = (PongWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame3.isFinalFragment());
|
||||
Assert.assertEquals(0, frame3.rsv());
|
||||
Assert.assertEquals(content1, frame3.content());
|
||||
frame3.release();
|
||||
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
|
||||
|
||||
TextWebSocketFrame frame4 = (TextWebSocketFrame) channel.readInbound();
|
||||
Assert.assertTrue(frame4.isFinalFragment());
|
||||
Assert.assertEquals(0, frame4.rsv());
|
||||
Assert.assertEquals(aggregatedContent, frame4.content());
|
||||
frame4.release();
|
||||
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
||||
|
||||
Assert.assertNull(channel.readInbound());
|
||||
}
|
||||
@ -116,27 +109,27 @@ public class WebSocketFrameAggregatorTest {
|
||||
@Test
|
||||
public void textFrameTooBig() throws Exception {
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new WebSocketFrameAggregator(8));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, content1.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, content1.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||
try {
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
Assert.fail();
|
||||
} catch (TooLongFrameException e) {
|
||||
// expected
|
||||
}
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content2)));
|
||||
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, content1.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, content1.copy()));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(true, 1, Unpooled.wrappedBuffer(content1)));
|
||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||
try {
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
Assert.fail();
|
||||
} catch (TooLongFrameException e) {
|
||||
// expected
|
||||
}
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, content2.copy()));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content2)));
|
||||
for (;;) {
|
||||
Object msg = channel.readInbound();
|
||||
if (msg == null) {
|
||||
@ -146,4 +139,11 @@ public class WebSocketFrameAggregatorTest {
|
||||
}
|
||||
channel.finish();
|
||||
}
|
||||
|
||||
private static byte[] toBytes(ByteBuf buf) {
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
buf.release();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.LastHttpContent;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -51,8 +50,8 @@ public class WebSocketServerHandshaker00Test {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(
|
||||
new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
|
||||
|
||||
FullHttpRequest req = ReferenceCountUtil.releaseLater(new DefaultFullHttpRequest(
|
||||
HTTP_1_1, HttpMethod.GET, "/chat", Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII)));
|
||||
FullHttpRequest req = new DefaultFullHttpRequest(
|
||||
HTTP_1_1, HttpMethod.GET, "/chat", Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII));
|
||||
|
||||
req.headers().set(Names.HOST, "server.example.com");
|
||||
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
|
||||
@ -84,5 +83,6 @@ public class WebSocketServerHandshaker00Test {
|
||||
|
||||
Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII));
|
||||
content.release();
|
||||
req.release();
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ public class WebSocketServerHandshaker08Test {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(
|
||||
new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
|
||||
|
||||
FullHttpRequest req = ReferenceCountUtil.releaseLater(
|
||||
new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat"));
|
||||
FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat");
|
||||
req.headers().set(Names.HOST, "server.example.com");
|
||||
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
|
||||
req.headers().set(Names.CONNECTION, "Upgrade");
|
||||
@ -81,5 +80,6 @@ public class WebSocketServerHandshaker08Test {
|
||||
Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
|
||||
}
|
||||
ReferenceCountUtil.release(res);
|
||||
req.release();
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ public class WebSocketServerHandshaker13Test {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(
|
||||
new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
|
||||
|
||||
FullHttpRequest req = ReferenceCountUtil.releaseLater(
|
||||
new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat"));
|
||||
FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat");
|
||||
req.headers().set(Names.HOST, "server.example.com");
|
||||
req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase());
|
||||
req.headers().set(Names.CONNECTION, "Upgrade");
|
||||
@ -81,5 +80,6 @@ public class WebSocketServerHandshaker13Test {
|
||||
Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
|
||||
}
|
||||
ReferenceCountUtil.release(res);
|
||||
req.release();
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ public class WebSocketServerProtocolHandlerTest {
|
||||
EmbeddedChannel ch = createChannel(new MockOutboundHandler());
|
||||
ChannelHandlerContext handshakerCtx = ch.pipeline().context(WebSocketServerProtocolHandshakeHandler.class);
|
||||
writeUpgradeRequest(ch);
|
||||
assertEquals(SWITCHING_PROTOCOLS, ReferenceCountUtil.releaseLater(responses.remove()).getStatus());
|
||||
FullHttpResponse response = responses.remove();
|
||||
assertEquals(SWITCHING_PROTOCOLS, response.getStatus());
|
||||
response.release();
|
||||
assertNotNull(WebSocketServerProtocolHandler.getHandshaker(handshakerCtx.channel()));
|
||||
}
|
||||
|
||||
@ -63,10 +65,15 @@ public class WebSocketServerProtocolHandlerTest {
|
||||
EmbeddedChannel ch = createChannel();
|
||||
|
||||
writeUpgradeRequest(ch);
|
||||
assertEquals(SWITCHING_PROTOCOLS, ReferenceCountUtil.releaseLater(responses.remove()).getStatus());
|
||||
|
||||
FullHttpResponse response = responses.remove();
|
||||
assertEquals(SWITCHING_PROTOCOLS, response.getStatus());
|
||||
response.release();
|
||||
|
||||
ch.writeInbound(new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/test"));
|
||||
assertEquals(FORBIDDEN, ReferenceCountUtil.releaseLater(responses.remove()).getStatus());
|
||||
response = responses.remove();
|
||||
assertEquals(FORBIDDEN, response.getStatus());
|
||||
response.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -82,9 +89,10 @@ public class WebSocketServerProtocolHandlerTest {
|
||||
|
||||
ch.writeInbound(httpRequestWithEntity);
|
||||
|
||||
FullHttpResponse response = ReferenceCountUtil.releaseLater(responses.remove());
|
||||
FullHttpResponse response = responses.remove();
|
||||
assertEquals(BAD_REQUEST, response.getStatus());
|
||||
assertEquals("not a WebSocket handshake request: missing upgrade", getResponseMessage(response));
|
||||
response.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -101,9 +109,10 @@ public class WebSocketServerProtocolHandlerTest {
|
||||
|
||||
ch.writeInbound(httpRequest);
|
||||
|
||||
FullHttpResponse response = ReferenceCountUtil.releaseLater(responses.remove());
|
||||
FullHttpResponse response = responses.remove();
|
||||
assertEquals(BAD_REQUEST, response.getStatus());
|
||||
assertEquals("not a WebSocket request: missing key", getResponseMessage(response));
|
||||
response.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -17,7 +17,6 @@ package io.netty.handler.codec.spdy;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -143,7 +142,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 1024;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||
for (int i = 0; i < 256; i ++) {
|
||||
buf.writeInt(RANDOM.nextInt());
|
||||
@ -153,6 +152,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -161,7 +161,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||
|
||||
delegate.readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
||||
@ -169,6 +169,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -177,7 +178,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0x01; // FLAG_FIN
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||
|
||||
delegate.readDataFrame(streamId, true, Unpooled.EMPTY_BUFFER);
|
||||
@ -185,6 +186,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -193,7 +195,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = (byte) 0xFE; // should ignore any unknown flags
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||
|
||||
delegate.readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
||||
@ -201,6 +203,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -209,7 +212,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||
|
||||
delegate.readFrameError((String) anyObject());
|
||||
@ -217,6 +220,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -226,7 +230,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(2 * (SPDY_HEADER_SIZE + length)));
|
||||
ByteBuf buf = Unpooled.buffer(2 * (SPDY_HEADER_SIZE + length));
|
||||
encodeDataFrameHeader(buf, streamId1, flags, length);
|
||||
encodeDataFrameHeader(buf, streamId2, flags, length);
|
||||
|
||||
@ -236,6 +240,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -247,7 +252,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -260,6 +265,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -271,7 +277,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -284,6 +290,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -295,7 +302,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -308,6 +315,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -319,7 +327,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = 0; // independent of all other streams
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -332,6 +340,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -343,7 +352,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -356,6 +365,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -367,7 +377,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||
buf.writeInt(associatedToStreamId | 0x80000000); // should ignore reserved bit
|
||||
@ -380,6 +390,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -390,7 +401,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -400,6 +411,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -411,7 +423,7 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
@ -423,6 +435,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -435,14 +448,14 @@ public class SpdyFrameDecoderTest {
|
||||
int associatedToStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
byte priority = (byte) (RANDOM.nextInt() & 0x07);
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length + headerBlockLength));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length + headerBlockLength);
|
||||
encodeControlFrameHeader(buf, type, flags, length + headerBlockLength);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(associatedToStreamId);
|
||||
buf.writeByte(priority << 5);
|
||||
buf.writeByte(0);
|
||||
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(headerBlockLength));
|
||||
ByteBuf headerBlock = Unpooled.buffer(headerBlockLength);
|
||||
for (int i = 0; i < 256; i ++) {
|
||||
headerBlock.writeInt(RANDOM.nextInt());
|
||||
}
|
||||
@ -456,6 +469,8 @@ public class SpdyFrameDecoderTest {
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
assertFalse(headerBlock.isReadable());
|
||||
buf.release();
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -465,7 +480,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -475,6 +490,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -484,7 +500,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -494,6 +510,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -503,7 +520,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -513,6 +530,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -522,7 +540,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||
|
||||
@ -532,6 +550,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -540,7 +559,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 0; // invalid length
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
|
||||
delegate.readFrameError((String) anyObject());
|
||||
@ -548,6 +567,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -557,7 +577,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = 0; // invalid stream identifier
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -566,6 +586,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -576,7 +597,7 @@ public class SpdyFrameDecoderTest {
|
||||
int headerBlockLength = 1024;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length + headerBlockLength));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length + headerBlockLength);
|
||||
encodeControlFrameHeader(buf, type, flags, length + headerBlockLength);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -594,6 +615,8 @@ public class SpdyFrameDecoderTest {
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
assertFalse(headerBlock.isReadable());
|
||||
buf.release();
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -604,7 +627,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -614,6 +637,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -624,7 +648,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||
buf.writeInt(statusCode);
|
||||
@ -634,6 +658,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -644,7 +669,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -654,6 +679,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -664,7 +690,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -674,6 +700,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -684,7 +711,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = 0; // invalid stream identifier
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -694,6 +721,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -704,7 +732,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
int statusCode = 0; // invalid status code
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -714,6 +742,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -726,7 +755,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -743,6 +772,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -752,7 +782,7 @@ public class SpdyFrameDecoderTest {
|
||||
int numSettings = 0;
|
||||
int length = 8 * numSettings + 4;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
|
||||
@ -762,6 +792,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -771,7 +802,7 @@ public class SpdyFrameDecoderTest {
|
||||
int numSettings = 0;
|
||||
int length = 8 * numSettings + 4;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
|
||||
@ -781,6 +812,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -793,7 +825,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -810,6 +842,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -822,7 +855,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -839,6 +872,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -848,7 +882,7 @@ public class SpdyFrameDecoderTest {
|
||||
int numSettings = 0;
|
||||
int length = 8 * numSettings + 4;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
|
||||
@ -858,6 +892,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -870,7 +905,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -887,6 +922,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -899,7 +935,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(numSettings);
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -913,6 +949,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -925,7 +962,7 @@ public class SpdyFrameDecoderTest {
|
||||
int id = RANDOM.nextInt() & 0x00FFFFFF;
|
||||
int value = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(0); // invalid num_settings
|
||||
for (int i = 0; i < numSettings; i++) {
|
||||
@ -939,6 +976,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -947,7 +985,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = (byte) 0xFF;
|
||||
int length = 8;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeLong(RANDOM.nextLong());
|
||||
|
||||
@ -955,6 +993,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -963,13 +1002,14 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = (byte) 0xFF;
|
||||
int length = 0;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
|
||||
replay(delegate);
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -979,7 +1019,7 @@ public class SpdyFrameDecoderTest {
|
||||
int segment = 4;
|
||||
int length = 2 * segment;
|
||||
|
||||
ByteBuf header = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE));
|
||||
ByteBuf header = Unpooled.buffer(SPDY_HEADER_SIZE);
|
||||
ByteBuf segment1 = Unpooled.buffer(segment);
|
||||
ByteBuf segment2 = Unpooled.buffer(segment);
|
||||
encodeControlFrameHeader(header, type, flags, length);
|
||||
@ -994,6 +1034,9 @@ public class SpdyFrameDecoderTest {
|
||||
assertFalse(header.isReadable());
|
||||
assertFalse(segment1.isReadable());
|
||||
assertFalse(segment2.isReadable());
|
||||
header.release();
|
||||
segment1.release();
|
||||
segment2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1003,7 +1046,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int id = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(id);
|
||||
|
||||
@ -1012,6 +1055,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1021,7 +1065,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int id = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(id);
|
||||
|
||||
@ -1030,6 +1074,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1039,7 +1084,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 8; // invalid length
|
||||
int id = RANDOM.nextInt();
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(id);
|
||||
|
||||
@ -1048,6 +1093,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1058,7 +1104,7 @@ public class SpdyFrameDecoderTest {
|
||||
int lastGoodStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(lastGoodStreamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -1068,6 +1114,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1078,7 +1125,7 @@ public class SpdyFrameDecoderTest {
|
||||
int lastGoodStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(lastGoodStreamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -1088,6 +1135,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1098,7 +1146,7 @@ public class SpdyFrameDecoderTest {
|
||||
int lastGoodStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(lastGoodStreamId | 0x80000000); // should ignore reserved bit
|
||||
buf.writeInt(statusCode);
|
||||
@ -1108,6 +1156,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1118,7 +1167,7 @@ public class SpdyFrameDecoderTest {
|
||||
int lastGoodStreamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int statusCode = RANDOM.nextInt() | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(lastGoodStreamId);
|
||||
buf.writeInt(statusCode);
|
||||
@ -1128,6 +1177,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1137,7 +1187,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -1147,6 +1197,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1156,7 +1207,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -1166,6 +1217,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1175,7 +1227,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -1185,6 +1237,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1194,7 +1247,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||
|
||||
@ -1204,6 +1257,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1212,7 +1266,7 @@ public class SpdyFrameDecoderTest {
|
||||
byte flags = 0;
|
||||
int length = 0; // invalid length
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
|
||||
delegate.readFrameError((String) anyObject());
|
||||
@ -1220,6 +1274,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1229,7 +1284,7 @@ public class SpdyFrameDecoderTest {
|
||||
int length = 4;
|
||||
int streamId = 0; // invalid stream identifier
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
@ -1238,6 +1293,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1248,11 +1304,11 @@ public class SpdyFrameDecoderTest {
|
||||
int headerBlockLength = 1024;
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length + headerBlockLength);
|
||||
buf.writeInt(streamId);
|
||||
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(headerBlockLength));
|
||||
ByteBuf headerBlock = Unpooled.buffer(headerBlockLength);
|
||||
for (int i = 0; i < 256; i ++) {
|
||||
headerBlock.writeInt(RANDOM.nextInt());
|
||||
}
|
||||
@ -1266,6 +1322,8 @@ public class SpdyFrameDecoderTest {
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
assertFalse(headerBlock.isReadable());
|
||||
buf.release();
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1296,7 +1354,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int deltaWindowSize = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(deltaWindowSize);
|
||||
@ -1306,6 +1364,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1316,7 +1375,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int deltaWindowSize = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||
buf.writeInt(deltaWindowSize | 0x80000000); // should ignore reserved bit
|
||||
@ -1326,6 +1385,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1336,7 +1396,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int deltaWindowSize = RANDOM.nextInt() & 0x7FFFFFFF | 0x01;
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(deltaWindowSize);
|
||||
@ -1346,6 +1406,7 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1356,7 +1417,7 @@ public class SpdyFrameDecoderTest {
|
||||
int streamId = RANDOM.nextInt() & 0x7FFFFFFF;
|
||||
int deltaWindowSize = 0; // invalid delta window size
|
||||
|
||||
ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer(SPDY_HEADER_SIZE + length));
|
||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||
encodeControlFrameHeader(buf, type, flags, length);
|
||||
buf.writeInt(streamId);
|
||||
buf.writeInt(deltaWindowSize);
|
||||
@ -1366,5 +1427,6 @@ public class SpdyFrameDecoderTest {
|
||||
decoder.decode(buf);
|
||||
verify(delegate);
|
||||
assertFalse(buf.isReadable());
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package io.netty.handler.codec.spdy;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -52,18 +51,19 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyHeaderBlock() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.EMPTY_BUFFER);
|
||||
ByteBuf headerBlock = Unpooled.EMPTY_BUFFER;
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
decoder.endHeaderBlock(frame);
|
||||
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroNameValuePairs() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(4));
|
||||
ByteBuf headerBlock = Unpooled.buffer(4);
|
||||
headerBlock.writeInt(0);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
decoder.endHeaderBlock(frame);
|
||||
@ -71,22 +71,24 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertFalse(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNameValuePairs() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(4));
|
||||
ByteBuf headerBlock = Unpooled.buffer(4);
|
||||
headerBlock.writeInt(-1);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneNameValuePair() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(21));
|
||||
ByteBuf headerBlock = Unpooled.buffer(21);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -101,11 +103,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingNameLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(4));
|
||||
ByteBuf headerBlock = Unpooled.buffer(4);
|
||||
headerBlock.writeInt(1);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
decoder.endHeaderBlock(frame);
|
||||
@ -113,11 +116,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroNameLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8));
|
||||
ByteBuf headerBlock = Unpooled.buffer(8);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(0);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
@ -125,11 +129,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeNameLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8));
|
||||
ByteBuf headerBlock = Unpooled.buffer(8);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(-1);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
@ -137,11 +142,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingName() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8));
|
||||
ByteBuf headerBlock = Unpooled.buffer(8);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
@ -150,11 +156,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalNameOnlyNull() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(18));
|
||||
ByteBuf headerBlock = Unpooled.buffer(18);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeByte(0);
|
||||
@ -165,11 +172,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingValueLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(12));
|
||||
ByteBuf headerBlock = Unpooled.buffer(12);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -179,11 +187,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroValueLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf headerBlock = Unpooled.buffer(16);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -197,11 +206,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals("", frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeValueLength() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf headerBlock = Unpooled.buffer(16);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -211,11 +221,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingValue() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(16));
|
||||
ByteBuf headerBlock = Unpooled.buffer(16);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -226,11 +237,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalValueOnlyNull() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(17));
|
||||
ByteBuf headerBlock = Unpooled.buffer(17);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -241,11 +253,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalValueStartsWithNull() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(22));
|
||||
ByteBuf headerBlock = Unpooled.buffer(22);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -257,11 +270,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalValueEndsWithNull() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(22));
|
||||
ByteBuf headerBlock = Unpooled.buffer(22);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -273,11 +287,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleValues() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(27));
|
||||
ByteBuf headerBlock = Unpooled.buffer(27);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -295,11 +310,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertEquals(2, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().getAll(name).get(0));
|
||||
assertEquals(value, frame.headers().getAll(name).get(1));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleValuesEndsWithNull() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(28));
|
||||
ByteBuf headerBlock = Unpooled.buffer(28);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -316,11 +332,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalValueMultipleNulls() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(28));
|
||||
ByteBuf headerBlock = Unpooled.buffer(28);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -335,11 +352,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertFalse(headerBlock.isReadable());
|
||||
assertTrue(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingNextNameValuePair() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(21));
|
||||
ByteBuf headerBlock = Unpooled.buffer(21);
|
||||
headerBlock.writeInt(2);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -354,11 +372,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleNames() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(38));
|
||||
ByteBuf headerBlock = Unpooled.buffer(38);
|
||||
headerBlock.writeInt(2);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -376,11 +395,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtraData() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(22));
|
||||
ByteBuf headerBlock = Unpooled.buffer(22);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -395,11 +415,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDecodes() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(21));
|
||||
ByteBuf headerBlock = Unpooled.buffer(21);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -419,18 +440,19 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContinueAfterInvalidHeaders() throws Exception {
|
||||
ByteBuf numHeaders = ReferenceCountUtil.releaseLater(Unpooled.buffer(4));
|
||||
ByteBuf numHeaders = Unpooled.buffer(4);
|
||||
numHeaders.writeInt(1);
|
||||
|
||||
ByteBuf nameBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8));
|
||||
ByteBuf nameBlock = Unpooled.buffer(8);
|
||||
nameBlock.writeInt(4);
|
||||
nameBlock.writeBytes(nameBytes);
|
||||
|
||||
ByteBuf valueBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(9));
|
||||
ByteBuf valueBlock = Unpooled.buffer(9);
|
||||
valueBlock.writeInt(5);
|
||||
valueBlock.writeBytes(valueBytes);
|
||||
|
||||
@ -447,11 +469,14 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
numHeaders.release();
|
||||
nameBlock.release();
|
||||
valueBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncatedHeaderName() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(maxHeaderSize + 18));
|
||||
ByteBuf headerBlock = Unpooled.buffer(maxHeaderSize + 18);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(maxHeaderSize + 1);
|
||||
for (int i = 0; i < maxHeaderSize + 1; i++) {
|
||||
@ -466,11 +491,12 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.isTruncated());
|
||||
assertFalse(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTruncatedHeaderValue() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(maxHeaderSize + 13));
|
||||
ByteBuf headerBlock = Unpooled.buffer(maxHeaderSize + 13);
|
||||
headerBlock.writeInt(1);
|
||||
headerBlock.writeInt(4);
|
||||
headerBlock.writeBytes(nameBytes);
|
||||
@ -485,5 +511,6 @@ public class SpdyHeaderBlockRawDecoderTest {
|
||||
assertTrue(frame.isTruncated());
|
||||
assertFalse(frame.isInvalid());
|
||||
assertEquals(0, frame.headers().names().size());
|
||||
headerBlock.release();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package io.netty.handler.codec.spdy;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -56,7 +55,7 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
|
||||
@Test
|
||||
public void testHeaderBlock() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(37));
|
||||
ByteBuf headerBlock = Unpooled.buffer(37);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x15); // little-endian length (21)
|
||||
@ -78,11 +77,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeaderBlockMultipleDecodes() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(37));
|
||||
ByteBuf headerBlock = Unpooled.buffer(37);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x15); // little-endian length (21)
|
||||
@ -109,11 +110,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
assertTrue(frame.headers().contains(name));
|
||||
assertEquals(1, frame.headers().getAll(name).size());
|
||||
assertEquals(value, frame.headers().get(name));
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLargeHeaderName() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8220));
|
||||
ByteBuf headerBlock = Unpooled.buffer(8220);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x0c); // little-endian length (8204)
|
||||
@ -134,11 +137,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
assertFalse(frame.isInvalid());
|
||||
assertFalse(frame.isTruncated());
|
||||
assertEquals(1, frame.headers().names().size());
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLargeHeaderValue() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(8220));
|
||||
ByteBuf headerBlock = Unpooled.buffer(8220);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x0c); // little-endian length (8204)
|
||||
@ -161,11 +166,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
assertFalse(frame.isTruncated());
|
||||
assertEquals(1, frame.headers().names().size());
|
||||
assertEquals(8191, frame.headers().get("n").length());
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test(expected = SpdyProtocolException.class)
|
||||
public void testHeaderBlockExtraData() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(37));
|
||||
ByteBuf headerBlock = Unpooled.buffer(37);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x15); // little-endian length (21)
|
||||
@ -183,11 +190,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
headerBlock.writeByte(0xc9); // adler-32 checksum
|
||||
headerBlock.writeByte(0); // Data following zlib stream
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test(expected = SpdyProtocolException.class)
|
||||
public void testHeaderBlockInvalidDictionary() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(7));
|
||||
ByteBuf headerBlock = Unpooled.buffer(7);
|
||||
headerBlock.writeByte(0x78);
|
||||
headerBlock.writeByte(0x3f);
|
||||
headerBlock.writeByte(0x01); // Unknown dictionary
|
||||
@ -196,11 +205,13 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
headerBlock.writeByte(0x04); // Unknown dictionary
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
|
||||
@Test(expected = SpdyProtocolException.class)
|
||||
public void testHeaderBlockInvalidDeflateBlock() throws Exception {
|
||||
ByteBuf headerBlock = ReferenceCountUtil.releaseLater(Unpooled.buffer(11));
|
||||
ByteBuf headerBlock = Unpooled.buffer(11);
|
||||
headerBlock.writeBytes(zlibHeader);
|
||||
headerBlock.writeByte(0); // Non-compressed block
|
||||
headerBlock.writeByte(0x00); // little-endian length (0)
|
||||
@ -208,5 +219,7 @@ public class SpdyHeaderBlockZlibDecoderTest {
|
||||
headerBlock.writeByte(0x00); // invalid one's compliment
|
||||
headerBlock.writeByte(0x00); // invalid one's compliment
|
||||
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
|
||||
|
||||
headerBlock.release();
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class ByteToMessageDecoderTest {
|
||||
*/
|
||||
@Test
|
||||
public void testInternalBufferClearReadAll() {
|
||||
final ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer().writeBytes(new byte[] {'a'}));
|
||||
final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a'});
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
@ -109,7 +109,7 @@ public class ByteToMessageDecoderTest {
|
||||
*/
|
||||
@Test
|
||||
public void testInternalBufferClearReadPartly() {
|
||||
final ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer().writeBytes(new byte[] {'a', 'b'}));
|
||||
final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a', 'b'});
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
@ -134,7 +134,7 @@ public class ByteToMessageDecoderTest {
|
||||
@Test
|
||||
public void testFireChannelReadCompleteOnInactive() throws InterruptedException {
|
||||
final BlockingQueue<Integer> queue = new LinkedBlockingDeque<Integer>();
|
||||
final ByteBuf buf = ReferenceCountUtil.releaseLater(Unpooled.buffer().writeBytes(new byte[] {'a', 'b'}));
|
||||
final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[] {'a', 'b'});
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
|
@ -24,7 +24,6 @@ import org.junit.Test;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DelimiterBasedFrameDecoderTest {
|
||||
@ -34,10 +33,17 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new DelimiterBasedFrameDecoder(8192, true,
|
||||
Delimiters.lineDelimiter()));
|
||||
ch.writeInbound(Unpooled.copiedBuffer("TestLine\r\ng\r\n", Charset.defaultCharset()));
|
||||
assertEquals("TestLine", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
assertEquals("g", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("TestLine", buf.toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("g", buf2.toString(Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -47,10 +53,17 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
ch.writeInbound(Unpooled.copiedBuffer("Test", Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(Unpooled.copiedBuffer("Line\r\ng\r\n", Charset.defaultCharset()));
|
||||
assertEquals("TestLine", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
assertEquals("g", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("TestLine", buf.toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("g", buf2.toString(Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,10 +71,17 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new DelimiterBasedFrameDecoder(8192, false,
|
||||
Delimiters.lineDelimiter()));
|
||||
ch.writeInbound(Unpooled.copiedBuffer("TestLine\r\ng\r\n", Charset.defaultCharset()));
|
||||
assertEquals("TestLine\r\n", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
assertEquals("g\r\n", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("TestLine\r\n", buf.toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("g\r\n", buf2.toString(Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,10 +91,17 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
ch.writeInbound(Unpooled.copiedBuffer("Test", Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(Unpooled.copiedBuffer("Line\r\ng\r\n", Charset.defaultCharset()));
|
||||
assertEquals("TestLine\r\n", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
assertEquals("g\r\n", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("TestLine\r\n", buf.toString(Charset.defaultCharset()));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("g\r\n", buf2.toString(Charset.defaultCharset()));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -83,11 +110,18 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
new DelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter()));
|
||||
|
||||
ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));
|
||||
assertEquals("first", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
assertEquals("second", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("first", buf.toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("second", buf2.toString(CharsetUtil.US_ASCII));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
ReferenceCountUtil.release(ch.readInbound());
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
|
||||
public class LengthFieldBasedFrameDecoderTest {
|
||||
|
||||
@ -55,7 +54,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
||||
|
||||
@Test
|
||||
public void testDiscardTooLongFrame2() {
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer());
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
buf.writeInt(32);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
buf.writeByte(i);
|
||||
@ -81,5 +80,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
||||
|
||||
Assert.assertNull(channel.readInbound());
|
||||
channel.finish();
|
||||
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -32,12 +31,19 @@ public class LineBasedFrameDecoderTest {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(8192, true, false));
|
||||
|
||||
ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));
|
||||
assertEquals("first", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
assertEquals("second", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("first", buf.toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("second", buf2.toString(CharsetUtil.US_ASCII));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
|
||||
ReferenceCountUtil.release(ch.readInbound());
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -45,11 +51,18 @@ public class LineBasedFrameDecoderTest {
|
||||
EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(8192, false, false));
|
||||
|
||||
ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));
|
||||
assertEquals("first\r\n", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
assertEquals("second\n", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("first\r\n", buf.toString(CharsetUtil.US_ASCII));
|
||||
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals("second\n", buf2.toString(CharsetUtil.US_ASCII));
|
||||
assertNull(ch.readInbound());
|
||||
ch.finish();
|
||||
ReferenceCountUtil.release(ch.readInbound());
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -63,9 +76,13 @@ public class LineBasedFrameDecoderTest {
|
||||
assertThat(e, is(instanceOf(TooLongFrameException.class)));
|
||||
}
|
||||
|
||||
assertThat(releaseLater((ByteBuf) ch.readInbound()),
|
||||
is(releaseLater(copiedBuffer("first\n", CharsetUtil.US_ASCII))));
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
ByteBuf buf2 = copiedBuffer("first\n", CharsetUtil.US_ASCII);
|
||||
assertThat(buf, is(buf2));
|
||||
assertThat(ch.finish(), is(false));
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -80,9 +97,13 @@ public class LineBasedFrameDecoderTest {
|
||||
assertThat(e, is(instanceOf(TooLongFrameException.class)));
|
||||
}
|
||||
|
||||
assertThat(releaseLater((ByteBuf) ch.readInbound()),
|
||||
is(releaseLater(copiedBuffer("first\r\n", CharsetUtil.US_ASCII))));
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII);
|
||||
assertThat(buf, is(buf2));
|
||||
assertThat(ch.finish(), is(false));
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -98,8 +119,13 @@ public class LineBasedFrameDecoderTest {
|
||||
|
||||
assertThat(ch.writeInbound(copiedBuffer("890", CharsetUtil.US_ASCII)), is(false));
|
||||
assertThat(ch.writeInbound(copiedBuffer("123\r\nfirst\r\n", CharsetUtil.US_ASCII)), is(true));
|
||||
assertThat(releaseLater((ByteBuf) ch.readInbound()),
|
||||
is(releaseLater(copiedBuffer("first\r\n", CharsetUtil.US_ASCII))));
|
||||
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII);
|
||||
assertThat(buf, is(buf2));
|
||||
assertThat(ch.finish(), is(false));
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.Signal;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ReplayingDecoderByteBufTest {
|
||||
@ -31,8 +30,8 @@ public class ReplayingDecoderByteBufTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetUnsignedByte() {
|
||||
ReplayingDecoderByteBuf buffer = new ReplayingDecoderByteBuf(releaseLater(Unpooled.copiedBuffer("TestBuffer",
|
||||
CharsetUtil.ISO_8859_1)));
|
||||
ByteBuf buf = Unpooled.copiedBuffer("TestBuffer", CharsetUtil.ISO_8859_1);
|
||||
ReplayingDecoderByteBuf buffer = new ReplayingDecoderByteBuf(buf);
|
||||
|
||||
boolean error;
|
||||
int i = 0;
|
||||
@ -47,6 +46,8 @@ public class ReplayingDecoderByteBufTest {
|
||||
|
||||
assertTrue(error);
|
||||
assertEquals(10, i);
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,8 +55,8 @@ public class ReplayingDecoderByteBufTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetByte() {
|
||||
ReplayingDecoderByteBuf buffer = new ReplayingDecoderByteBuf(releaseLater(Unpooled.copiedBuffer("TestBuffer",
|
||||
CharsetUtil.ISO_8859_1)));
|
||||
ByteBuf buf = Unpooled.copiedBuffer("TestBuffer", CharsetUtil.ISO_8859_1);
|
||||
ReplayingDecoderByteBuf buffer = new ReplayingDecoderByteBuf(buf);
|
||||
|
||||
boolean error;
|
||||
int i = 0;
|
||||
@ -70,6 +71,8 @@ public class ReplayingDecoderByteBufTest {
|
||||
|
||||
assertTrue(error);
|
||||
assertEquals(10, i);
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +80,7 @@ public class ReplayingDecoderByteBufTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetBoolean() {
|
||||
ByteBuf buf = releaseLater(Unpooled.buffer(10));
|
||||
ByteBuf buf = Unpooled.buffer(10);
|
||||
while (buf.isWritable()) {
|
||||
buf.writeBoolean(true);
|
||||
}
|
||||
@ -96,6 +99,8 @@ public class ReplayingDecoderByteBufTest {
|
||||
|
||||
assertTrue(error);
|
||||
assertEquals(10, i);
|
||||
|
||||
buf.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ReplayingDecoderTest {
|
||||
@ -45,7 +44,13 @@ public class ReplayingDecoderTest {
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));
|
||||
assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), releaseLater(ch.readInbound()));
|
||||
|
||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' });
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
|
||||
// Truncated input
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
|
||||
@ -78,8 +83,13 @@ public class ReplayingDecoderTest {
|
||||
|
||||
// "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n'}));
|
||||
assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' })),
|
||||
releaseLater(ch.readInbound()));
|
||||
|
||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' });
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
|
||||
ch.finish();
|
||||
assertNull(ch.readInbound());
|
||||
@ -101,12 +111,26 @@ public class ReplayingDecoderTest {
|
||||
|
||||
// "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n' , 'B', '\n'}));
|
||||
assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] {'C' })), releaseLater(ch.readInbound()));
|
||||
|
||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'C'});
|
||||
ByteBuf buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
|
||||
assertNull("Must be null as it must only decode one frame", ch.readInbound());
|
||||
|
||||
ch.read();
|
||||
ch.finish();
|
||||
assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] {'B' })), releaseLater(ch.readInbound()));
|
||||
|
||||
buf = Unpooled.wrappedBuffer(new byte[] {'B'});
|
||||
buf2 = (ByteBuf) ch.readInbound();
|
||||
assertEquals(buf, buf2);
|
||||
|
||||
buf.release();
|
||||
buf2.release();
|
||||
|
||||
assertNull(ch.readInbound());
|
||||
}
|
||||
|
||||
@ -185,7 +209,7 @@ public class ReplayingDecoderTest {
|
||||
@Test
|
||||
public void testFireChannelReadCompleteOnInactive() throws InterruptedException {
|
||||
final BlockingQueue<Integer> queue = new LinkedBlockingDeque<Integer>();
|
||||
final ByteBuf buf = releaseLater(Unpooled.buffer().writeBytes(new byte[]{'a', 'b'}));
|
||||
final ByteBuf buf = Unpooled.buffer().writeBytes(new byte[]{'a', 'b'});
|
||||
EmbeddedChannel channel = new EmbeddedChannel(new ReplayingDecoder<Integer>() {
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,6 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SnappyFramedDecoderTest {
|
||||
@ -109,7 +108,11 @@ public class SnappyFramedDecoderTest {
|
||||
channel.writeInbound(in);
|
||||
|
||||
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 'n', 'e', 't', 't', 'y' });
|
||||
assertEquals(releaseLater(expected), releaseLater(channel.readInbound()));
|
||||
ByteBuf actual = (ByteBuf) channel.readInbound();
|
||||
assertEquals(expected, actual);
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -125,7 +128,12 @@ public class SnappyFramedDecoderTest {
|
||||
channel.writeInbound(in);
|
||||
|
||||
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 'n', 'e', 't', 't', 'y' });
|
||||
assertEquals(releaseLater(expected), releaseLater(channel.readInbound()));
|
||||
ByteBuf actual = (ByteBuf) channel.readInbound();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
// The following two tests differ in only the checksum provided for the literal
|
||||
|
@ -22,7 +22,6 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SnappyFramedEncoderTest {
|
||||
@ -46,8 +45,11 @@ public class SnappyFramedEncoderTest {
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
ByteBuf actual = (ByteBuf) channel.readOutbound();
|
||||
assertEquals(expected, actual);
|
||||
|
||||
assertEquals(releaseLater(expected), releaseLater(channel.readOutbound()));
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -67,8 +69,11 @@ public class SnappyFramedEncoderTest {
|
||||
'n', 'e', 't', 't', 'y',
|
||||
0x3a, 0x05, 0x00
|
||||
});
|
||||
ByteBuf actual = (ByteBuf) channel.readOutbound();
|
||||
assertEquals(expected, actual);
|
||||
|
||||
assertEquals(releaseLater(expected), releaseLater(channel.readOutbound()));
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -96,8 +101,11 @@ public class SnappyFramedEncoderTest {
|
||||
}
|
||||
actual.addComponent(true, m);
|
||||
}
|
||||
assertEquals(releaseLater(expected), releaseLater(actual));
|
||||
in.release();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DelimiterBasedFrameDecoderTest {
|
||||
@ -45,8 +44,10 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
}
|
||||
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
|
||||
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +65,10 @@ public class DelimiterBasedFrameDecoderTest {
|
||||
}
|
||||
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 }));
|
||||
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||
|
||||
buf.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LengthFieldBasedFrameDecoderTest {
|
||||
@ -43,7 +42,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
||||
}
|
||||
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' }));
|
||||
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||
buf.release();
|
||||
}
|
||||
@ -63,7 +62,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
||||
}
|
||||
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
|
||||
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
|
||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
||||
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
|
||||
buf.release();
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
@ -42,10 +41,17 @@ public class ProtobufVarint32FrameDecoderTest {
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
ch.writeInbound(wrappedBuffer(b, 1, 2));
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
ch.writeInbound(wrappedBuffer(b, 3, b.length - 3));
|
||||
assertThat(
|
||||
releaseLater((ByteBuf) ch.readInbound()),
|
||||
is(releaseLater(wrappedBuffer(new byte[] { 1, 1, 1, 1 }))));
|
||||
|
||||
assertTrue(ch.writeInbound(wrappedBuffer(b, 3, b.length - 3)));
|
||||
|
||||
ByteBuf expected = wrappedBuffer(new byte[] { 1, 1, 1, 1 });
|
||||
ByteBuf actual = (ByteBuf) ch.readInbound();
|
||||
|
||||
assertThat(expected, is(actual));
|
||||
assertFalse(ch.finish());
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -60,7 +66,17 @@ public class ProtobufVarint32FrameDecoderTest {
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
ch.writeInbound(wrappedBuffer(b, 127, 600));
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
ch.writeInbound(wrappedBuffer(b, 727, b.length - 727));
|
||||
assertThat(releaseLater((ByteBuf) ch.readInbound()), is(releaseLater(wrappedBuffer(b, 2, b.length - 2))));
|
||||
|
||||
assertFalse(ch.writeInbound(wrappedBuffer(b, 127, 600)));
|
||||
assertThat(ch.readInbound(), is(nullValue()));
|
||||
assertTrue(ch.writeInbound(wrappedBuffer(b, 727, b.length - 727)));
|
||||
|
||||
ByteBuf expected = wrappedBuffer(b, 2, b.length - 2);
|
||||
ByteBuf actual = (ByteBuf) ch.readInbound();
|
||||
assertThat(expected, is(actual));
|
||||
assertTrue(ch.finishAndReleaseAll());
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ProtobufVarint32LengthFieldPrependerTest {
|
||||
@ -37,8 +35,15 @@ public class ProtobufVarint32LengthFieldPrependerTest {
|
||||
@Test
|
||||
public void testTinyEncode() {
|
||||
byte[] b = { 4, 1, 1, 1, 1 };
|
||||
ch.writeOutbound(wrappedBuffer(b, 1, b.length - 1));
|
||||
assertThat(releaseLater((ByteBuf) ch.readOutbound()), is(releaseLater(wrappedBuffer(b))));
|
||||
assertTrue(ch.writeOutbound(wrappedBuffer(b, 1, b.length - 1)));
|
||||
ByteBuf expected = wrappedBuffer(b);
|
||||
ByteBuf actual = (ByteBuf) ch.readOutbound();
|
||||
assertEquals(expected, actual);
|
||||
|
||||
assertFalse(ch.finish());
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -49,7 +54,15 @@ public class ProtobufVarint32LengthFieldPrependerTest {
|
||||
}
|
||||
b[0] = -2;
|
||||
b[1] = 15;
|
||||
ch.writeOutbound(wrappedBuffer(b, 2, b.length - 2));
|
||||
assertThat(releaseLater((ByteBuf) ch.readOutbound()), is(releaseLater(wrappedBuffer(b))));
|
||||
assertTrue(ch.writeOutbound(wrappedBuffer(b, 2, b.length - 2)));
|
||||
|
||||
ByteBuf expected = wrappedBuffer(b);
|
||||
ByteBuf actual = (ByteBuf) ch.readOutbound();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
assertFalse(ch.finish());
|
||||
|
||||
expected.release();
|
||||
actual.release();
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,10 @@ public final class ReferenceCountUtil {
|
||||
* Schedules the specified object to be released when the caller thread terminates. Note that this operation is
|
||||
* intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the
|
||||
* intended use case.
|
||||
*
|
||||
* @deprecated this may introduce a lot of memory usage so it is generally preferable to manually release objects.
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> T releaseLater(T msg) {
|
||||
return releaseLater(msg, 1);
|
||||
}
|
||||
@ -117,7 +120,10 @@ public final class ReferenceCountUtil {
|
||||
* Schedules the specified object to be released when the caller thread terminates. Note that this operation is
|
||||
* intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the
|
||||
* intended use case.
|
||||
*
|
||||
* @deprecated this may introduce a lot of memory usage so it is generally preferable to manually release objects.
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> T releaseLater(T msg, int decrement) {
|
||||
if (msg instanceof ReferenceCounted) {
|
||||
ThreadDeathWatcher.watch(Thread.currentThread(), new ReleasingTask((ReferenceCounted) msg, decrement));
|
||||
|
@ -30,8 +30,9 @@ import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ChunkedWriteHandlerTest {
|
||||
private static final byte[] BYTES = new byte[1024 * 64];
|
||||
@ -103,7 +104,7 @@ public class ChunkedWriteHandlerTest {
|
||||
|
||||
ChunkedInput<ByteBuf> input = new ChunkedInput<ByteBuf>() {
|
||||
private boolean done;
|
||||
private final ByteBuf buffer = releaseLater(Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1));
|
||||
private final ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.ISO_8859_1);
|
||||
|
||||
@Override
|
||||
public boolean isEndOfInput() throws Exception {
|
||||
@ -112,7 +113,7 @@ public class ChunkedWriteHandlerTest {
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
// NOOP
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,8 +143,12 @@ public class ChunkedWriteHandlerTest {
|
||||
// the listener should have been notified
|
||||
assertTrue(listenerNotified.get());
|
||||
|
||||
assertEquals(releaseLater(buffer), releaseLater(ch.readOutbound()));
|
||||
ByteBuf buffer2 = (ByteBuf) ch.readOutbound();
|
||||
assertEquals(buffer, buffer2);
|
||||
assertNull(ch.readOutbound());
|
||||
|
||||
buffer.release();
|
||||
buffer2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -18,7 +18,6 @@ package io.netty.testsuite.transport.socket;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
@ -33,7 +32,6 @@ import io.netty.handler.ssl.SslHandler;
|
||||
import io.netty.handler.ssl.SslHandshakeCompletionEvent;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import org.junit.Test;
|
||||
@ -52,7 +50,9 @@ import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SocketSslGreetingTest extends AbstractSocketTest {
|
||||
@ -62,7 +62,6 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
|
||||
private static final LogLevel LOG_LEVEL = LogLevel.TRACE;
|
||||
private static final File CERT_FILE;
|
||||
private static final File KEY_FILE;
|
||||
private final ByteBuf greeting = ReferenceCountUtil.releaseLater(Unpooled.buffer().writeByte('a'));
|
||||
|
||||
static {
|
||||
SelfSignedCertificate ssc;
|
||||
@ -163,14 +162,15 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
private static class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
|
||||
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
|
||||
assertEquals(greeting, buf);
|
||||
assertEquals('a', buf.readByte());
|
||||
assertFalse(buf.isReadable());
|
||||
latch.countDown();
|
||||
ctx.close();
|
||||
}
|
||||
@ -187,7 +187,7 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class ServerHandler extends SimpleChannelInboundHandler<String> {
|
||||
private static class ServerHandler extends SimpleChannelInboundHandler<String> {
|
||||
volatile Channel channel;
|
||||
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
|
||||
|
||||
@ -200,7 +200,7 @@ public class SocketSslGreetingTest extends AbstractSocketTest {
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
throws Exception {
|
||||
channel = ctx.channel();
|
||||
channel.writeAndFlush(greeting.duplicate().retain());
|
||||
channel.writeAndFlush(ctx.alloc().buffer().writeByte('a'));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user