use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class TestMessages method testToStreamTransportCallbackSuccess.
@Test
public void testToStreamTransportCallbackSuccess() {
TransportCallback<RestResponse> restCallback = response -> {
Assert.assertFalse(response.hasError());
Assert.assertNotNull(response.getResponse());
Assert.assertSame(response.getResponse().getEntity(), DATA);
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.success(streamResponse, WIRE_ATTR));
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class TestClientRequestFinalizerFilter method testExistingRequestFinalizerManager.
@Test
public void testExistingRequestFinalizerManager() {
final RequestFinalizerManagerImpl manager = new RequestFinalizerManagerImpl(null, null);
final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
manager.registerRequestFinalizer((request, response, requestContext1, throwable) -> atomicBoolean.set(true));
_requestContext.putLocalAttr(R2Constants.CLIENT_REQUEST_FINALIZER_MANAGER_REQUEST_CONTEXT_KEY, manager);
_filterChain.onRestRequest(null, _requestContext, null);
registerRequestFinalizer();
_filterChain.onRestResponse(null, _requestContext, null);
assertExecutionOrders();
Assert.assertTrue(atomicBoolean.get(), "Expected the request finalizer registered before reaching the" + "ClientRequestFinalizerFilter to still be invoked.");
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class TestRequestFinalizerDispatcher method testExistingRequestFinalizerManager.
@Test
public void testExistingRequestFinalizerManager() {
when(_restTransportResponse.getResponse()).thenReturn(_restResponse);
final RequestContext requestContext = new RequestContext();
final RequestFinalizerManagerImpl manager = new RequestFinalizerManagerImpl(null, requestContext);
final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
manager.registerRequestFinalizer((request, response, requestContext1, throwable) -> atomicBoolean.set(true));
requestContext.putLocalAttr(R2Constants.SERVER_REQUEST_FINALIZER_MANAGER_REQUEST_CONTEXT_KEY, manager);
final TestTransportCallback<RestResponse> transportCallback = new TestTransportCallback<>(false);
_outerDispatcher.handleRestRequest(null, null, requestContext, transportCallback);
Assert.assertEquals(_outerDispatcher._executionOrder, 1);
Assert.assertEquals(_innerDispatcher._executionOrder, 2);
Assert.assertEquals(_innerDispatcher._transportCallback._executionOrder, 3);
Assert.assertEquals(_outerDispatcher._transportCallback._executionOrder, 4);
Assert.assertEquals(transportCallback._executionOrder, 5);
Assert.assertEquals(_requestFinalizer._executionOrder, 6, "Expected request to be finalized after the callback.");
Assert.assertTrue(atomicBoolean.get(), "Expected the request finalizer registered before reaching the" + "RequestFinalizerDispatcher to still be invoked.");
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class AbstractCaptureFilterTest method testTwoDifferentRequests.
@Test
public void testTwoDifferentRequests() {
final RestRequest req1 = request();
final RestRequest req2 = req1.builder().setEntity("This is a different request".getBytes()).build();
final RestResponse res1 = response();
final RestResponse res2 = res1.builder().setEntity("This is a different response".getBytes()).build();
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req1, res1);
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req2, res2);
// Should have created two separate entries
Assert.assertEquals(res1, getDb().<Response>replay(req1));
Assert.assertEquals(res2, getDb().<Response>replay(req2));
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class AbstractCaptureFilterTest method testInitialCapture.
@Test
public void testInitialCapture() {
final RestRequest req = request();
final RestResponse res = response();
Assert.assertNull(getDb().replay(req));
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req, res);
Assert.assertEquals(res, getDb().<Response>replay(req));
}
Aggregations