Permalink
Browse files

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.
  • Loading branch information...
1 parent a0e375b commit 0bc30a123e88bc7b038e0c260937581097a903f7 @normanmaurer normanmaurer committed with normanmaurer Nov 3, 2016
Showing with 1,222 additions and 552 deletions.
  1. +153 −50 buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java
  2. +260 −122 buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java
  3. +65 −27 buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java
  4. +8 −5 buffer/src/test/java/io/netty/buffer/ByteProcessorTest.java
  5. +87 −37 buffer/src/test/java/io/netty/buffer/FixedCompositeByteBufTest.java
  6. +83 −34 buffer/src/test/java/io/netty/buffer/ReadOnlyDirectByteBufferBufTest.java
  7. +12 −10 codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java
  8. +6 −7 codec-http/src/test/java/io/netty/handler/codec/http/HttpObjectAggregatorTest.java
  9. +4 −5 codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java
  10. +47 −47 codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketFrameAggregatorTest.java
  11. +3 −3 codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00Test.java
  12. +2 −2 codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08Test.java
  13. +2 −2 codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker13Test.java
  14. +15 −5 ...http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java
  15. +4 −5 ...p/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionTestUtil.java
  16. +123 −61 codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyFrameDecoderTest.java
  17. +56 −29 codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyHeaderBlockRawDecoderTest.java
  18. +21 −8 codec-http/src/test/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecoderTest.java
  19. +2 −3 codec-http2/src/test/java/io/netty/handler/codec/http2/Http2CodecTest.java
  20. +21 −11 codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java
  21. +5 −3 codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexCodecTest.java
  22. +3 −3 codec/src/test/java/io/netty/handler/codec/ByteToMessageDecoderTest.java
  23. +45 −11 codec/src/test/java/io/netty/handler/codec/DelimiterBasedFrameDecoderTest.java
  24. +3 −2 codec/src/test/java/io/netty/handler/codec/LengthFieldBasedFrameDecoderTest.java
  25. +37 −11 codec/src/test/java/io/netty/handler/codec/LineBasedFrameDecoderTest.java
  26. +11 −6 codec/src/test/java/io/netty/handler/codec/ReplayingDecoderByteBufTest.java
  27. +31 −7 codec/src/test/java/io/netty/handler/codec/ReplayingDecoderTest.java
  28. +11 −3 codec/src/test/java/io/netty/handler/codec/compression/SnappyFrameDecoderTest.java
  29. +12 −4 codec/src/test/java/io/netty/handler/codec/compression/SnappyFrameEncoderTest.java
  30. +6 −3 codec/src/test/java/io/netty/handler/codec/frame/DelimiterBasedFrameDecoderTest.java
  31. +2 −3 codec/src/test/java/io/netty/handler/codec/frame/LengthFieldBasedFrameDecoderTest.java
  32. +15 −5 codec/src/test/java/io/netty/handler/codec/protobuf/ProtobufVarint32FrameDecoderTest.java
  33. +48 −7 codec/src/test/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrependerTest.java
  34. +6 −0 common/src/main/java/io/netty/util/ReferenceCountUtil.java
  35. +7 −4 handler/src/test/java/io/netty/handler/stream/ChunkedWriteHandlerTest.java
  36. +6 −7 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslGreetingTest.java
Oops, something went wrong.
Oops, something went wrong.
@@ -23,7 +23,6 @@
import java.util.Random;
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.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -99,36 +98,45 @@ public void notEqualsBufferUnderflow() {
@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
@@ -140,12 +148,15 @@ public void testWriteUtf8Surrogates() {
.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
@@ -155,12 +166,15 @@ public void testWriteUtf8InvalidOnlyTrailingSurrogate() {
.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
@@ -170,12 +184,15 @@ public void testWriteUtf8InvalidOnlyLeadingSurrogate() {
.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
@@ -186,12 +203,15 @@ public void testWriteUtf8InvalidSurrogatesSwitched() {
.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
@@ -202,12 +222,15 @@ public void testWriteUtf8InvalidTwoLeadingSurrogates() {
.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
@@ -218,62 +241,77 @@ public void testWriteUtf8InvalidTwoTrailingSurrogates() {
.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
public void testWriteUtf8InvalidEndOnLeadingSurrogate() {
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
public void testWriteUtf8InvalidEndOnTrailingSurrogate() {
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 testWriteUsAsciiString() {
AsciiString usAscii = new AsciiString("NettyRocks");
- ByteBuf buf = releaseLater(Unpooled.buffer(16));
+ ByteBuf buf = Unpooled.buffer(16);
buf.writeBytes(usAscii.toString().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 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) {
@@ -16,7 +16,6 @@
package io.netty.buffer;
-import static io.netty.util.ReferenceCountUtil.releaseLater;
import static org.junit.Assert.assertEquals;
import io.netty.util.ByteProcessor;
import io.netty.util.CharsetUtil;
@@ -26,8 +25,8 @@
public class ByteProcessorTest {
@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, ByteProcessor.FIND_CRLF));
@@ -41,12 +40,14 @@ public void testForward() {
assertEquals(24, buf.forEachByte(21, length - 21, ByteProcessor.FIND_LINEAR_WHITESPACE));
assertEquals(28, buf.forEachByte(24, length - 24, ByteProcessor.FIND_NON_LINEAR_WHITESPACE));
assertEquals(-1, buf.forEachByte(28, length - 28, ByteProcessor.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, ByteProcessor.FIND_LINEAR_WHITESPACE));
@@ -60,5 +61,7 @@ public void testBackward() {
assertEquals(5, buf.forEachByteDesc(0, 9, ByteProcessor.FIND_CRLF));
assertEquals(2, buf.forEachByteDesc(0, 6, ByteProcessor.FIND_NON_CRLF));
assertEquals(-1, buf.forEachByteDesc(0, 3, ByteProcessor.FIND_CRLF));
+
+ buf.release();
}
}
Oops, something went wrong.

0 comments on commit 0bc30a1

Please sign in to comment.