Fix buffer leaks in tests
Motivation: While working on #6087 some buffer leaks showed up. Modifications: Correctly release buffers. Result: No more buffer leaks in memcache and stomp codec tests.
This commit is contained in:
parent
efeb4cd8cb
commit
39aefdfa06
@ -76,7 +76,7 @@ public class BinaryMemcacheDecoderTest {
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
channel.finish();
|
||||
channel.finishAndReleaseAll();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,6 +150,7 @@ public class BinaryMemcacheDecoderTest {
|
||||
while (incoming.isReadable()) {
|
||||
channel.writeInbound(incoming.readBytes(5));
|
||||
}
|
||||
incoming.release();
|
||||
|
||||
BinaryMemcacheRequest request = channel.readInbound();
|
||||
|
||||
@ -261,8 +262,13 @@ public class BinaryMemcacheDecoderTest {
|
||||
BinaryMemcacheRequest request = new DefaultBinaryMemcacheRequest(key, extras);
|
||||
|
||||
assertTrue(channel.writeOutbound(request));
|
||||
assertTrue(channel.writeInbound(channel.outboundMessages().toArray()));
|
||||
|
||||
for (;;) {
|
||||
ByteBuf buffer = channel.readOutbound();
|
||||
if (buffer == null) {
|
||||
break;
|
||||
}
|
||||
channel.writeInbound(buffer);
|
||||
}
|
||||
BinaryMemcacheRequest read = channel.readInbound();
|
||||
read.release();
|
||||
// tearDown will call "channel.finish()"
|
||||
|
@ -46,7 +46,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
channel.finish();
|
||||
channel.finishAndReleaseAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,8 +92,8 @@ public class BinaryMemcacheEncoderTest {
|
||||
|
||||
ByteBuf written = channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
|
||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
|
||||
written.skipBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readSlice(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@ -109,8 +109,8 @@ public class BinaryMemcacheEncoderTest {
|
||||
|
||||
ByteBuf written = channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
|
||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo("netty"));
|
||||
written.skipBytes(DEFAULT_HEADER_SIZE);
|
||||
assertThat(written.readSlice(keyLength).toString(CharsetUtil.UTF_8), equalTo("netty"));
|
||||
written.release();
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
written = channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(content1.content().readableBytes()));
|
||||
assertThat(
|
||||
written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
written.readSlice(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is("Netty")
|
||||
);
|
||||
written.release();
|
||||
@ -147,7 +147,7 @@ public class BinaryMemcacheEncoderTest {
|
||||
written = channel.readOutbound();
|
||||
assertThat(written.readableBytes(), is(content2.content().readableBytes()));
|
||||
assertThat(
|
||||
written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
written.readSlice(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||
is(" Rocks!")
|
||||
);
|
||||
written.release();
|
||||
|
@ -76,7 +76,7 @@ public class BinaryMemcacheObjectAggregatorTest {
|
||||
|
||||
assertThat(channel.readInbound(), nullValue());
|
||||
|
||||
channel.finish();
|
||||
assertFalse(channel.finish());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,12 +51,16 @@ public class StompSubframeEncoderTest {
|
||||
ByteBuf byteBuf = channel.readOutbound();
|
||||
assertNotNull(byteBuf);
|
||||
aggregatedBuffer.writeBytes(byteBuf);
|
||||
byteBuf.release();
|
||||
|
||||
byteBuf = channel.readOutbound();
|
||||
assertNotNull(byteBuf);
|
||||
aggregatedBuffer.writeBytes(byteBuf);
|
||||
byteBuf.release();
|
||||
|
||||
aggregatedBuffer.resetReaderIndex();
|
||||
String content = aggregatedBuffer.toString(CharsetUtil.UTF_8);
|
||||
assertEquals(StompTestConstants.CONNECT_FRAME, content);
|
||||
aggregatedBuffer.release();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user