use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestResponseCompression method testResponseCompression.
private void testResponseCompression(URI uri, long bytes, String acceptEncoding, final StreamingCompressor compressor) throws InterruptedException, TimeoutException, ExecutionException {
for (Client client : clients()) {
StreamRequestBuilder builder = new StreamRequestBuilder((Bootstrap.createHttpURI(PORT, uri)));
builder.addHeaderValue(HttpConstants.ACCEPT_ENCODING, acceptEncoding);
StreamRequest request = builder.build(EntityStreams.emptyStream());
final FutureCallback<StreamResponse> callback = new FutureCallback<StreamResponse>();
client.streamRequest(request, callback);
final StreamResponse response = callback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
final FutureCallback<None> readerCallback = new FutureCallback<None>();
final BytesReader reader = new BytesReader(BYTE, readerCallback);
final EntityStream decompressedStream = compressor.inflate(response.getEntityStream());
decompressedStream.setReader(reader);
readerCallback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(reader.getTotalBytes(), bytes);
Assert.assertTrue(reader.allBytesCorrect());
}
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testSnappyCompressor.
@Test
public void testSnappyCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new SnappyCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'a');
ByteArrayOutputStream out = new ByteArrayOutputStream();
SnappyFramedOutputStream snappy = new SnappyFramedOutputStream(out);
IOUtils.write(origin, snappy);
snappy.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testBzip2Compressor.
@Test
public void testBzip2Compressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new Bzip2Compressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
BZip2CompressorOutputStream bzip = new BZip2CompressorOutputStream(out);
IOUtils.write(origin, bzip);
bzip.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testDecompress.
private void testDecompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(compressed);
EntityStream compressedStream = EntityStreams.newEntityStream(writer);
EntityStream uncompressedStream = compressor.inflate(compressedStream);
FutureCallback<byte[]> callback = new FutureCallback<byte[]>();
uncompressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, uncompressed);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testSnappyCompressor.
@Test
public void testSnappyCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new SnappyCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'a');
ByteArrayOutputStream out = new ByteArrayOutputStream();
SnappyFramedOutputStream snappy = new SnappyFramedOutputStream(out);
IOUtils.write(origin, snappy);
snappy.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
Aggregations