Search in sources :

Example 16 with StreamResponseBuilder

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

the class TestMessages method testToStreamTransportCallbackStreamException.

@Test
public void testToStreamTransportCallbackStreamException() {
    TransportCallback<RestResponse> restCallback = response -> {
        Assert.assertTrue(response.hasError());
        Assert.assertNotNull(response.getError());
        Assert.assertTrue(response.getError() instanceof RestException);
        Assert.assertNotNull(response.getWireAttributes());
        Assert.assertEquals(response.getWireAttributes(), WIRE_ATTR);
    };
    TransportCallback<StreamResponse> streamCallback = Messages.toStreamTransportCallback(restCallback);
    StreamResponseBuilder builder = new StreamResponseBuilder();
    StreamResponse streamResponse = builder.build(EntityStreams.newEntityStream(new ByteStringWriter(DATA)));
    streamCallback.onResponse(TransportResponseImpl.error(new StreamException(streamResponse, new IllegalStateException()), WIRE_ATTR));
}
Also used : ByteStringWriter(com.linkedin.r2.message.stream.entitystream.ByteStringWriter) Callback(com.linkedin.common.callback.Callback) FullEntityReader(com.linkedin.r2.message.stream.entitystream.FullEntityReader) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) Messages(com.linkedin.r2.message.Messages) RestResponse(com.linkedin.r2.message.rest.RestResponse) EntityStreams(com.linkedin.r2.message.stream.entitystream.EntityStreams) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) Assert(org.testng.Assert) StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) ByteString(com.linkedin.data.ByteString) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) Map(java.util.Map) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) StreamException(com.linkedin.r2.message.stream.StreamException) RestException(com.linkedin.r2.message.rest.RestException) StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) RestResponse(com.linkedin.r2.message.rest.RestResponse) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) RestException(com.linkedin.r2.message.rest.RestException) ByteStringWriter(com.linkedin.r2.message.stream.entitystream.ByteStringWriter) StreamException(com.linkedin.r2.message.stream.StreamException) Test(org.testng.annotations.Test)

Aggregations

StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)16 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)11 StreamException (com.linkedin.r2.message.stream.StreamException)6 EntityStream (com.linkedin.r2.message.stream.entitystream.EntityStream)6 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)6 Map (java.util.Map)6 Test (org.testng.annotations.Test)6 Callback (com.linkedin.common.callback.Callback)5 HashMap (java.util.HashMap)5 ByteString (com.linkedin.data.ByteString)4 StreamEncodingType (com.linkedin.r2.filter.compression.streaming.StreamEncodingType)4 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)4 RequestContext (com.linkedin.r2.message.RequestContext)4 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)3 ByteStringWriter (com.linkedin.r2.message.stream.entitystream.ByteStringWriter)3 None (com.linkedin.common.util.None)2 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)2 Messages (com.linkedin.r2.message.Messages)2