Search in sources :

Example 41 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class TestMockFailedResponseFutureBuilder method testBuildWithEntityTreatServerErrorAsSuccess.

@Test
public void testBuildWithEntityTreatServerErrorAsSuccess() {
    ResponseFuture<Greeting> future = buildWithEntity(ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS);
    try {
        Response<Greeting> response = future.getResponse();
        Assert.assertEquals(response.getEntity(), new Greeting().setId(1L).setMessage("foo"));
        Assert.assertEquals(response.getStatus(), 500);
        Assert.assertEquals(response.getError().getStatus(), 500);
    } catch (RemoteInvocationException e) {
        Assert.fail("No exception should have been thrown!");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) Test(org.testng.annotations.Test)

Example 42 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class TestCompressionServer method testSearchWithoutDecompression.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCompressedResponsesBuilderDataProvider")
public void testSearchWithoutDecompression(RestClient client, String operationsForCompression, RootBuilderWrapper<Long, Greeting> builders, ProtocolVersion protocolVersion) throws RemoteInvocationException {
    Request<CollectionResponse<Greeting>> findRequest = builders.findBy("Search").setQueryParam("tone", Tone.FRIENDLY).build();
    RequestContext requestContext = new RequestContext();
    RequestContextUtil.turnOffResponseDecompression(requestContext);
    Map<String, Set<String>> methodsAndFamilies = getCompressionMethods(operationsForCompression);
    Set<String> methods = methodsAndFamilies.get("methods");
    Set<String> families = methodsAndFamilies.get("families");
    if (shouldCompress(families, methods, "finder:search")) {
        // The server sends a compressed response, but the client does not decompress it so it cannot read the response.
        try {
            client.sendRequest(findRequest, requestContext).getResponse();
            Assert.fail("Expected RemoteInvocationException, but getResponse() succeeded.");
        } catch (RemoteInvocationException e) {
            Assert.assertEquals(e.getCause().getMessage(), "Could not decode REST response");
        }
    } else {
        // The server doesn't compress the response in the first place, so the client can read the response.
        client.sendRequest(findRequest, requestContext).getResponse();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RequestContext(com.linkedin.r2.message.RequestContext) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) Test(org.testng.annotations.Test)

Example 43 with RemoteInvocationException

use of com.linkedin.r2.RemoteInvocationException in project rest.li by linkedin.

the class TestDebugRequestHandlers method testParseqTraceDebugDeleteRequestHandlerRaw.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testParseqTraceDebugDeleteRequestHandlerRaw(RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, ExecutionException, InterruptedException, RemoteInvocationException {
    Long newId = createNewGreetingOnTheServer(builders);
    RestRequest request = new RestRequestBuilder(new URI(URI_PREFIX + "greetingsPromise/" + newId + "/__debug/parseqtrace/raw")).setMethod("DELETE").setEntity(createNewGreetingBytes(newId)).build();
    sendRequestAndVerifyParseqTraceRaw(request);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)32 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)29 RestRequest (com.linkedin.r2.message.rest.RestRequest)13 RequestContext (com.linkedin.r2.message.RequestContext)10 HashMap (java.util.HashMap)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8 URI (java.net.URI)8 FutureCallback (com.linkedin.common.callback.FutureCallback)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)6 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)6 Callback (com.linkedin.common.callback.Callback)5 ByteString (com.linkedin.data.ByteString)5 RestException (com.linkedin.r2.message.rest.RestException)5 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)5 TimeoutException (java.util.concurrent.TimeoutException)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)4 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4