Permalink
Browse files

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.
  • Loading branch information...
1 parent efeb4cd commit 39aefdfa06f89ae69cdb42481bdea2194ad2b62c @normanmaurer normanmaurer committed with normanmaurer Dec 2, 2016
@@ -76,7 +76,7 @@ public void setup() throws Exception {
@After
public void teardown() throws Exception {
- channel.finish();
+ channel.finishAndReleaseAll();
}
/**
@@ -150,6 +150,7 @@ public void shouldHandleNonUniformNetworkBatches() {
while (incoming.isReadable()) {
channel.writeInbound(incoming.readBytes(5));
}
+ incoming.release();
BinaryMemcacheRequest request = channel.readInbound();
@@ -261,8 +262,13 @@ public void shouldRetainCurrentMessageWhenSendingItOut() {
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 void setup() throws Exception {
@After
public void teardown() throws Exception {
- channel.finish();
+ channel.finishAndReleaseAll();
}
@Test
@@ -92,8 +92,8 @@ public void shouldEncodeExtras() {
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 void shouldEncodeKey() {
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,15 +139,15 @@ public void shouldEncodeContent() {
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();
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 void shouldAggregateChunksOnDecode() {
assertThat(channel.readInbound(), nullValue());
- channel.finish();
+ assertFalse(channel.finish());
}
@Test
@@ -51,12 +51,16 @@ public void testFrameAndContentEncoding() {
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();
}
}

0 comments on commit 39aefdf

Please sign in to comment.