Fix more memory leaks in buffer tests
This commit is contained in:
parent
0f351d2c47
commit
5fe2e7fc9d
@ -46,7 +46,7 @@ public abstract class AbstractByteBufTest {
|
||||
|
||||
private static final Queue<ByteBuf> freeLaterQueue = new ArrayDeque<ByteBuf>();
|
||||
|
||||
protected ByteBuf freeLater(ByteBuf buf) {
|
||||
protected static <T extends ByteBuf> T freeLater(T buf) {
|
||||
freeLaterQueue.add(buf);
|
||||
return buf;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
|
||||
@Test
|
||||
public void testRangedConsolidation() {
|
||||
CompositeByteBuf buf = compositeBuffer(Integer.MAX_VALUE);
|
||||
CompositeByteBuf buf = freeLater(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 }));
|
||||
@ -301,10 +301,10 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(wrappedBuffer(
|
||||
freeLater(wrappedBuffer(wrappedBuffer(
|
||||
new byte[] { 1 },
|
||||
new byte[] { 2 },
|
||||
new byte[] { 3 }).order(order)));
|
||||
new byte[] { 3 }).order(order))));
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
@ -314,10 +314,10 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(
|
||||
freeLater(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))));
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
@ -327,10 +327,10 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
|
||||
assertEquals(
|
||||
wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order)),
|
||||
wrappedBuffer(wrappedBuffer(
|
||||
freeLater(wrappedBuffer(wrappedBuffer(
|
||||
ByteBuffer.wrap(new byte[] { 1 }),
|
||||
ByteBuffer.wrap(new byte[] { 2 }),
|
||||
ByteBuffer.wrap(new byte[] { 3 }))));
|
||||
ByteBuffer.wrap(new byte[] { 3 })))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -342,8 +342,7 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }, new byte[1]).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 2 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 2 }).order(order));
|
||||
assertFalse(BufUtil.equals(a, b));
|
||||
|
||||
// Same content, same firstIndex, short length.
|
||||
@ -351,8 +350,7 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }, new byte[2]).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 2);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 2 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 2 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 3 }).order(order));
|
||||
assertTrue(BufUtil.equals(a, b));
|
||||
|
||||
@ -361,17 +359,15 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order));
|
||||
assertTrue(BufUtil.equals(a, b));
|
||||
|
||||
// Different content, same firstIndex, short length.
|
||||
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2 }, new byte[1]).order(order));
|
||||
b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] { 1, 2 }, new byte[1]).order(order)));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 4 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 4 }).order(order));
|
||||
assertFalse(BufUtil.equals(a, b));
|
||||
|
||||
// Different content, different firstIndex, short length.
|
||||
@ -379,19 +375,16 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 1);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order));
|
||||
assertFalse(BufUtil.equals(a, b));
|
||||
|
||||
// Same content, same firstIndex, long length.
|
||||
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));
|
||||
b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }, new byte[7])).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 7);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 4, 5, 6 }).order(order));
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 4, 5, 6 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order));
|
||||
assertTrue(BufUtil.equals(a, b));
|
||||
|
||||
// Same content, different firstIndex, long length.
|
||||
@ -399,17 +392,15 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
|
||||
assertTrue(BufUtil.equals(a, b));
|
||||
|
||||
// Different content, same firstIndex, long length.
|
||||
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));
|
||||
b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3, 4, 6 }, new byte[5])).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order));
|
||||
assertFalse(BufUtil.equals(a, b));
|
||||
|
||||
// Different content, different firstIndex, long length.
|
||||
@ -417,14 +408,13 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10).order(order));
|
||||
// to enable writeBytes
|
||||
b.writerIndex(b.writerIndex() - 5);
|
||||
b.writeBytes(
|
||||
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order));
|
||||
b.writeBytes(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order));
|
||||
assertFalse(BufUtil.equals(a, b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyBuffer() {
|
||||
ByteBuf b = wrappedBuffer(new byte[] {1, 2}, new byte[] {3, 4});
|
||||
ByteBuf b = freeLater(wrappedBuffer(new byte[]{1, 2}, new byte[]{3, 4}));
|
||||
b.readBytes(new byte[4]);
|
||||
b.readBytes(new byte[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user