Simplify Bzip2 tests

Motivation:

Sometimes we have a 'build time out' error because tests for bzip2 codec take a long time.

Modifications:

Removed cycles from Bzip2EncoderTest.testCompression(byte[]) and Bzip2DecoderTest.testDecompression(byte[]).

Result:

Reduced time to test the 'codec' package by 30 percent.
This commit is contained in:
Idel Pivnitskiy 2014-07-22 13:34:40 +04:00 committed by Norman Maurer
parent 923a0e71ac
commit ca87cc887e
2 changed files with 28 additions and 26 deletions

View File

@ -199,11 +199,10 @@ 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());
ByteArrayOutputStream os = new ByteArrayOutputStream();
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, blockSize);
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, randomBlockSize());
bZip2Os.write(data);
bZip2Os.close();
@ -218,7 +217,6 @@ public class Bzip2DecoderTest {
uncompressed.release();
dataBuf.release();
}
}
@Test
public void testDecompressionOfSmallChunkOfData() throws Exception {
@ -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);
}
}

View File

@ -61,8 +61,7 @@ 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);
@ -72,7 +71,6 @@ public class Bzip2EncoderTest {
assertArrayEquals(data, uncompressed);
}
}
@Test
public void testCompressionOfSmallChunkOfData() throws Exception {
@ -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);
}
}