From fbf1bdbef15a21aa31b01119003190a55e88eb6b Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 3 Jul 2014 17:51:15 +0900 Subject: [PATCH] Fix the build timeout when 'leak' profile is active Motivation: AbstractByteBufTest.testInternalBuffer() uses writeByte() operations to populate the sample data. Usually, this isn't a problem, but it starts to take a lot of time when the resource leak detection level gets higher. In our CI machine, testInternalBuffer() takes more than 30 minutes, causing the build timeout when the 'leak' profile is active (paranoid level resource detection.) Modification: Populate the sample data using ThreadLocalRandom.nextBytes() instead of using millions of writeByte() operations. Result: Test runs much faster when leak detection level is high. --- .../test/java/io/netty/buffer/AbstractByteBufTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java b/buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java index 23560dbe08..a72ebefae5 100644 --- a/buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java @@ -17,6 +17,7 @@ package io.netty.buffer; import io.netty.util.CharsetUtil; import io.netty.util.IllegalReferenceCountException; +import io.netty.util.internal.ThreadLocalRandom; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -1742,15 +1743,15 @@ public abstract class AbstractByteBufTest { ByteBuffer buf = buffer.internalNioBuffer(0, 1); assertEquals(1, buf.remaining()); - for (int i = 0; i < a; i++) { - buffer.writeByte(i); - } + byte[] data = new byte[a]; + ThreadLocalRandom.current().nextBytes(data); + buffer.writeBytes(data); buf = buffer.internalNioBuffer(0, a); assertEquals(a, buf.remaining()); for (int i = 0; i < a; i++) { - assertEquals((byte) i, buf.get()); + assertEquals(data[i], buf.get()); } assertFalse(buf.hasRemaining()); }