Search in sources :

Example 46 with Response

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));
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) Test(org.testng.annotations.Test)

Example 47 with Response

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

the class AbstractCaptureFilterTest method testException.

@Test
public void testException() {
    final RestRequest req = request();
    final Exception ex = new Exception();
    FilterUtil.fireUntypedRequestError(getFilterChain(), req, ex);
    // Request / response should not be recorded
    Assert.assertNull(getDb().replay(req));
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) Test(org.testng.annotations.Test)

Example 48 with Response

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));
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) Test(org.testng.annotations.Test)

Example 49 with Response

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

the class AbstractReplayFilterTest method testReplayWithNoMatch.

@Test
public void testReplayWithNoMatch() {
    final RestRequest req = request();
    final RestResponse res = response();
    final CaptureLastCallFilter captureFilter = new CaptureLastCallFilter();
    final FilterChain fc = getFilterChain().addFirstRest(captureFilter);
    FilterUtil.fireUntypedRequestResponse(fc, req, res);
    Assert.assertEquals(res, captureFilter.getLastRes());
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) CaptureLastCallFilter(com.linkedin.r2.testutils.filter.CaptureLastCallFilter) RestResponse(com.linkedin.r2.message.rest.RestResponse) FilterChain(com.linkedin.r2.filter.FilterChain) Test(org.testng.annotations.Test)

Example 50 with Response

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

the class TestStreamEcho method testDelayedEcho.

@Test
public void testDelayedEcho() throws Exception {
    for (Client client : clients()) {
        RestRequest restRequest = new RestRequestBuilder(Bootstrap.createHttpURI(PORT, DELAYED_ECHO_URI)).setEntity("wei ni hao ma?".getBytes()).build();
        RestResponse response = client.restRequest(restRequest).get();
        Assert.assertEquals(response.getEntity().asString(Charset.defaultCharset()), "wei ni hao ma?");
    }
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) Client(com.linkedin.r2.transport.common.Client) Test(org.testng.annotations.Test)

Aggregations

RestResponse (com.linkedin.r2.message.rest.RestResponse)100 Test (org.testng.annotations.Test)95 RestRequest (com.linkedin.r2.message.rest.RestRequest)63 RequestContext (com.linkedin.r2.message.RequestContext)51 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)47 URI (java.net.URI)45 ByteString (com.linkedin.data.ByteString)42 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)37 RestException (com.linkedin.r2.message.rest.RestException)32 HashMap (java.util.HashMap)29 FutureCallback (com.linkedin.common.callback.FutureCallback)25 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)25 ExecutionException (java.util.concurrent.ExecutionException)25 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)24 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)22 CountDownLatch (java.util.concurrent.CountDownLatch)22 URISyntaxException (java.net.URISyntaxException)21 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)18 IOException (java.io.IOException)18 Map (java.util.Map)17