Search in sources :

Example 46 with EntityStream

use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.

the class TestStreamingCompression method testCompressThenDecompress.

private void testCompressThenDecompress(StreamingCompressor compressor, byte[] origin) throws CompressionException, ExecutionException, InterruptedException {
    ByteWriter writer = new ByteWriter(origin);
    EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
    EntityStream compressedStream = compressor.deflate(uncompressedStream);
    EntityStream decompressedStream = compressor.inflate(compressedStream);
    FutureCallback<byte[]> callback = new FutureCallback<>();
    decompressedStream.setReader(new ByteReader(callback));
    byte[] result = callback.get();
    Assert.assertEquals(result, origin);
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 47 with EntityStream

use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.

the class TestStreamingCompression method testCompress.

private void testCompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
    ByteWriter writer = new ByteWriter(uncompressed);
    EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
    EntityStream compressedStream = compressor.deflate(uncompressedStream);
    FutureCallback<byte[]> callback = new FutureCallback<>();
    compressedStream.setReader(new ByteReader(callback));
    byte[] result = callback.get();
    Assert.assertEquals(result, compressed);
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 48 with EntityStream

use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.

the class DispatcherRequestFilter method onStreamRequest.

@Override
public void onStreamRequest(StreamRequest req, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
    markOnRequestTimings(requestContext);
    Connector connector = null;
    try {
        final AtomicBoolean responded = new AtomicBoolean(false);
        TransportCallback<StreamResponse> callback = createStreamCallback(requestContext, nextFilter, responded);
        connector = new Connector(responded, nextFilter, requestContext, wireAttrs);
        req.getEntityStream().setReader(connector);
        EntityStream newStream = EntityStreams.newEntityStream(connector);
        _dispatcher.handleStreamRequest(req.builder().build(newStream), wireAttrs, requestContext, callback);
    } catch (Exception e) {
        nextFilter.onError(e, requestContext, new HashMap<>());
        if (connector != null) {
            connector.cancel();
        }
    }
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) BaseConnector(com.linkedin.r2.message.stream.entitystream.BaseConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) StreamResponse(com.linkedin.r2.message.stream.StreamResponse)

Example 49 with EntityStream

use of com.linkedin.r2.message.stream.entitystream.EntityStream in project rest.li by linkedin.

the class TestStreamingCompression method testCompress.

private void testCompress(StreamingCompressor compressor, byte[] uncompressed, byte[] compressed) throws CompressionException, ExecutionException, InterruptedException {
    ByteWriter writer = new ByteWriter(uncompressed);
    EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
    EntityStream compressedStream = compressor.deflate(uncompressedStream);
    FutureCallback<byte[]> callback = new FutureCallback<>();
    compressedStream.setReader(new ByteReader(callback));
    byte[] result = callback.get();
    Assert.assertEquals(result, compressed);
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 50 with EntityStream

use of com.linkedin.r2.message.stream.entitystream.EntityStream 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<>();
    uncompressedStream.setReader(new ByteReader(callback));
    byte[] result = callback.get();
    Assert.assertEquals(result, uncompressed);
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) FutureCallback(com.linkedin.common.callback.FutureCallback)

Aggregations

EntityStream (com.linkedin.r2.message.stream.entitystream.EntityStream)58 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)29 Test (org.testng.annotations.Test)29 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)27 CountDownLatch (java.util.concurrent.CountDownLatch)27 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)22 ByteString (com.linkedin.data.ByteString)11 StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)10 FutureCallback (com.linkedin.common.callback.FutureCallback)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AbstractServiceTest (test.r2.integ.clientserver.providers.AbstractServiceTest)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Callback (com.linkedin.common.callback.Callback)7 Client (com.linkedin.r2.transport.common.Client)7 BytesWriter (test.r2.integ.helper.BytesWriter)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 TimeoutException (java.util.concurrent.TimeoutException)6 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)5 None (com.linkedin.common.util.None)4 StreamEncodingType (com.linkedin.r2.filter.compression.streaming.StreamEncodingType)4