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:
parent
e3795330bf
commit
0062a871f4
|
@ -199,25 +199,23 @@ public class Bzip2DecoderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testDecompression(final byte[] data) throws Exception {
|
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();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, blockSize);
|
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, randomBlockSize());
|
||||||
bZip2Os.write(data);
|
bZip2Os.write(data);
|
||||||
bZip2Os.close();
|
bZip2Os.close();
|
||||||
|
|
||||||
ByteBuf compressed = Unpooled.wrappedBuffer(os.toByteArray());
|
ByteBuf compressed = Unpooled.wrappedBuffer(os.toByteArray());
|
||||||
channel.writeInbound(compressed);
|
channel.writeInbound(compressed);
|
||||||
|
|
||||||
ByteBuf uncompressed = readUncompressed(channel);
|
ByteBuf uncompressed = readUncompressed(channel);
|
||||||
ByteBuf dataBuf = Unpooled.wrappedBuffer(data);
|
ByteBuf dataBuf = Unpooled.wrappedBuffer(data);
|
||||||
|
|
||||||
assertEquals(dataBuf, uncompressed);
|
assertEquals(dataBuf, uncompressed);
|
||||||
|
|
||||||
uncompressed.release();
|
uncompressed.release();
|
||||||
dataBuf.release();
|
dataBuf.release();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -235,8 +233,7 @@ public class Bzip2DecoderTest {
|
||||||
final byte[] data = BYTES_LARGE;
|
final byte[] data = BYTES_LARGE;
|
||||||
|
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os,
|
BZip2CompressorOutputStream bZip2Os = new BZip2CompressorOutputStream(os, randomBlockSize());
|
||||||
rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1));
|
|
||||||
bZip2Os.write(data);
|
bZip2Os.write(data);
|
||||||
bZip2Os.close();
|
bZip2Os.close();
|
||||||
|
|
||||||
|
@ -270,4 +267,8 @@ public class Bzip2DecoderTest {
|
||||||
|
|
||||||
return uncompressed;
|
return uncompressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int randomBlockSize() {
|
||||||
|
return rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,17 +61,15 @@ public class Bzip2EncoderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testCompression(final byte[] data) throws Exception {
|
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(randomBlockSize()));
|
||||||
final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(blockSize));
|
|
||||||
|
|
||||||
ByteBuf in = Unpooled.wrappedBuffer(data);
|
ByteBuf in = Unpooled.wrappedBuffer(data);
|
||||||
channel.writeOutbound(in);
|
channel.writeOutbound(in);
|
||||||
channel.finish();
|
channel.finish();
|
||||||
|
|
||||||
byte[] uncompressed = uncompress(channel, data.length);
|
byte[] uncompressed = uncompress(channel, data.length);
|
||||||
|
|
||||||
assertArrayEquals(data, uncompressed);
|
assertArrayEquals(data, uncompressed);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -86,8 +84,7 @@ public class Bzip2EncoderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompressionOfBatchedFlowOfData() throws Exception {
|
public void testCompressionOfBatchedFlowOfData() throws Exception {
|
||||||
final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(
|
final EmbeddedChannel channel = new EmbeddedChannel(new Bzip2Encoder(randomBlockSize()));
|
||||||
rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1)));
|
|
||||||
|
|
||||||
int written = 0, length = rand.nextInt(100);
|
int written = 0, length = rand.nextInt(100);
|
||||||
while (written + length < BYTES_LARGE.length) {
|
while (written + length < BYTES_LARGE.length) {
|
||||||
|
@ -134,4 +131,8 @@ public class Bzip2EncoderTest {
|
||||||
|
|
||||||
return uncompressed;
|
return uncompressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int randomBlockSize() {
|
||||||
|
return rand.nextInt(MIN_BLOCK_SIZE, MAX_BLOCK_SIZE + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user