Search in sources :

Example 16 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)

Example 17 with Response

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

the class TestQueryTunnel method testShouldQueryTunnel.

@Test
public void testShouldQueryTunnel() throws Exception {
    String longQuery = buildQuery(QUERY_TUNNEL_THRESHOLD);
    RestResponse response = getResponse(longQuery, new RequestContext());
    Assert.assertEquals(response.getStatus(), IS_TUNNELED_RESPONSE_CODE);
    Assert.assertEquals(response.getEntity().copyBytes(), longQuery.getBytes());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 18 with Response

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

the class TestQueryTunnel method testShouldNotQueryTunnel.

@Test
public void testShouldNotQueryTunnel() throws Exception {
    String shortQuery = buildQuery(QUERY_TUNNEL_THRESHOLD - 1);
    RestResponse response = getResponse(shortQuery, new RequestContext());
    Assert.assertEquals(response.getStatus(), IS_NOT_TUNNELED_RESPONSE_CODE);
    Assert.assertEquals(response.getEntity().copyBytes(), shortQuery.getBytes());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 19 with Response

use of com.linkedin.r2.message.Response 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());
    }
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) Client(com.linkedin.r2.transport.common.Client) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Example 20 with Response

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

the class TestResponseCompression method testEncodingNotAcceptable.

public void testEncodingNotAcceptable(String acceptEncoding) throws TimeoutException, InterruptedException {
    for (Client client : clients()) {
        StreamRequestBuilder builder = new StreamRequestBuilder((Bootstrap.createHttpURI(PORT, SMALL_URI)));
        if (acceptEncoding != null) {
            builder.addHeaderValue(HttpConstants.ACCEPT_ENCODING, acceptEncoding);
        }
        StreamRequest request = builder.build(EntityStreams.emptyStream());
        final FutureCallback<StreamResponse> callback = new FutureCallback<StreamResponse>();
        client.streamRequest(request, callback);
        try {
            final StreamResponse response = callback.get(60, TimeUnit.SECONDS);
            Assert.fail("Should have thrown exception when encoding is not acceptable");
        } catch (ExecutionException e) {
            Throwable t = e.getCause();
            Assert.assertTrue(t instanceof StreamException);
            StreamResponse response = ((StreamException) t).getResponse();
            Assert.assertEquals(response.getStatus(), HttpConstants.NOT_ACCEPTABLE);
        }
    }
}
Also used : StreamResponse(com.linkedin.r2.message.stream.StreamResponse) Client(com.linkedin.r2.transport.common.Client) ExecutionException(java.util.concurrent.ExecutionException) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) FutureCallback(com.linkedin.common.callback.FutureCallback) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) StreamException(com.linkedin.r2.message.stream.StreamException)

Aggregations

Test (org.testng.annotations.Test)155 RestResponse (com.linkedin.r2.message.rest.RestResponse)142 RestRequest (com.linkedin.r2.message.rest.RestRequest)101 RequestContext (com.linkedin.r2.message.RequestContext)95 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)87 URI (java.net.URI)77 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)66 ByteString (com.linkedin.data.ByteString)58 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)41 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)40 HashMap (java.util.HashMap)39 FutureCallback (com.linkedin.common.callback.FutureCallback)36 RestException (com.linkedin.r2.message.rest.RestException)36 CountDownLatch (java.util.concurrent.CountDownLatch)35 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)34 ExecutionException (java.util.concurrent.ExecutionException)32 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)27 Callback (com.linkedin.common.callback.Callback)25 IOException (java.io.IOException)24 Map (java.util.Map)24