diff --git a/codec/src/test/java/io/netty/handler/codec/compression/Bzip2DecoderTest.java b/codec/src/test/java/io/netty/handler/codec/compression/Bzip2DecoderTest.java index 788b121199..02add87ccf 100644 --- a/codec/src/test/java/io/netty/handler/codec/compression/Bzip2DecoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/compression/Bzip2DecoderTest.java @@ -199,25 +199,23 @@ public class Bzip2DecoderTest { } private static void testDecompression(final byte[] data) throws Exception { - for (int blockSize = MIN_BLOCK_SIZE; blockSize <= MAX_BLOCK_SIZE; blockSize++) { - final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Decoder()); + final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Decoder()); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, blockSize); - bZip2Os.write(data); - bZip2Os.close(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, randomBlockSize()); + bZip2Os.write(data); + bZip2Os.close(); - ByteBuf compressed = Unpooled.wrappedBuffer(os.toByteArray()); - channel.writeInbound(compressed); + ByteBuf compressed = Unpooled.wrappedBuffer(os.toByteArray()); + channel.writeInbound(compressed); - ByteBuf uncompressed = readUncompressed(channel); - ByteBuf dataBuf = Unpooled.wrappedBuffer(data); + ByteBuf uncompressed = readUncompressed(channel); + ByteBuf dataBuf = Unpooled.wrappedBuffer(data); - assertEquals(dataBuf, uncompressed); + assertEquals(dataBuf, uncompressed); - uncompressed.release(); - dataBuf.release(); - } + uncompressed.release(); + dataBuf.release(); } @Test @@ -235,8 +233,7 @@ public class Bzip2DecoderTest { final byte[] data = BYTES_LARGE; ByteArrayOutputStream os = new ByteArrayOutputStream(); - BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, - rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1)); + BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, randomBlockSize()); bZip2Os.write(data); bZip2Os.close(); @@ -270,4 +267,8 @@ public class Bzip2DecoderTest { return uncompressed; } + + private static int randomBlockSize() { + return rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1); + } } diff --git a/codec/src/test/java/io/netty/handler/codec/compression/Bzip2EncoderTest.java b/codec/src/test/java/io/netty/handler/codec/compression/Bzip2EncoderTest.java index 295802e63f..710f6bb5e8 100644 --- a/codec/src/test/java/io/netty/handler/codec/compression/Bzip2EncoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/compression/Bzip2EncoderTest.java @@ -61,17 +61,15 @@ public class Bzip2EncoderTest { } private static void testCompression(final byte[] data) throws Exception { - for (int blockSize = MIN_BLOCK_SIZE; blockSize <= MAX_BLOCK_SIZE; blockSize++) { - final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(blockSize)); + final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(randomBlockSize())); - ByteBuf in = Unpooled.wrappedBuffer(data); - channel.writeOutbound(in); - channel.finish(); + ByteBuf in = Unpooled.wrappedBuffer(data); + channel.writeOutbound(in); + channel.finish(); - byte[] uncompressed = uncompress(channel, data.length); + byte[] uncompressed = uncompress(channel, data.length); - assertArrayEquals(data, uncompressed); - } + assertArrayEquals(data, uncompressed); } @Test @@ -86,8 +84,7 @@ public class Bzip2EncoderTest { @Test public void testCompressionOfBatchedFlowOfData() throws Exception { - final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder( - rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1))); + final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(randomBlockSize())); int written = 0, length = rand.nextInt(100); while (written + length < BYTES_LARGE.length) { @@ -134,4 +131,8 @@ public class Bzip2EncoderTest { return uncompressed; } + + private static int randomBlockSize() { + return rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1); + } }