Search in sources :

Example 1 with Response

use of com.linkedin.restli.client.Response in project rest.li by linkedin.

the class TestMultiplexerIntegration method twoSequentialCalls.

@Test
public void twoSequentialCalls() throws Exception {
    GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
    FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
    GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(2L).build();
    FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
    MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
    getClient().sendRequest(multiplexedRequest);
    getClient().sendRequest(request1, directCallback1);
    getClient().sendRequest(request2, directCallback2);
    assertEqualResponses(muxCallback1, directCallback1);
    assertEqualResponses(muxCallback2, directCallback2);
}
Also used : Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) FutureCallback(com.linkedin.common.callback.FutureCallback) GreetingsCallbackBuilders(com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with Response

use of com.linkedin.restli.client.Response in project rest.li by linkedin.

the class TestMultiplexerIntegration method twoSequentialCallsWithOneError.

@Test
public void twoSequentialCallsWithOneError() throws Exception {
    GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
    FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
    GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(Long.MAX_VALUE).build();
    FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
    MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
    getClient().sendRequest(multiplexedRequest);
    getClient().sendRequest(request1, directCallback1);
    getClient().sendRequest(request2, directCallback2);
    assertEqualResponses(muxCallback1, directCallback1);
    assertEqualErrors(muxCallback2, directCallback2);
}
Also used : Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) FutureCallback(com.linkedin.common.callback.FutureCallback) GreetingsCallbackBuilders(com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 3 with Response

use of com.linkedin.restli.client.Response in project rest.li by linkedin.

the class TestMultiplexerIntegration method twoParallelCalls.

@Test
public void twoParallelCalls() throws Exception {
    GetRequest<Greeting> request1 = new GreetingsCallbackBuilders().get().id(1L).build();
    FutureCallback<Response<Greeting>> muxCallback1 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback1 = new FutureCallback<Response<Greeting>>();
    GetRequest<Greeting> request2 = new GreetingsCallbackBuilders().get().id(2L).build();
    FutureCallback<Response<Greeting>> muxCallback2 = new FutureCallback<Response<Greeting>>();
    FutureCallback<Response<Greeting>> directCallback2 = new FutureCallback<Response<Greeting>>();
    MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createParallelRequest().addRequest(request1, muxCallback1).addRequest(request2, muxCallback2).build();
    getClient().sendRequest(multiplexedRequest);
    getClient().sendRequest(request1, directCallback1);
    getClient().sendRequest(request2, directCallback2);
    assertEqualResponses(muxCallback1, directCallback1);
    assertEqualResponses(muxCallback2, directCallback2);
}
Also used : Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) FutureCallback(com.linkedin.common.callback.FutureCallback) GreetingsCallbackBuilders(com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 4 with Response

use of com.linkedin.restli.client.Response in project rest.li by linkedin.

the class TestGreetingsClient method test404Callback.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void test404Callback(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final Request<Greeting> request = builders.get().id(999L).build();
    getClient().sendRequest(request, new Callback<Response<Greeting>>() {

        @Override
        public void onError(Throwable e) {
            Assert.assertNotNull(e, "We should have gotten an error!");
            countDownLatch.countDown();
        }

        @Override
        public void onSuccess(Response<Greeting> result) {
            Assert.fail("We should not have received a success!");
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) OptionsResponse(com.linkedin.restli.common.OptionsResponse) IdResponse(com.linkedin.restli.common.IdResponse) Response(com.linkedin.restli.client.Response) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 5 with Response

use of com.linkedin.restli.client.Response in project rest.li by linkedin.

the class MockFailedResponseFutureBuilder method buildWithErrorResponse.

private ResponseFuture<V> buildWithErrorResponse(ProtocolVersion protocolVersion) {
    int status = (_errorResponse.hasStatus()) ? _errorResponse.getStatus() : DEFAULT_HTTP_STATUS;
    // create a RestLiResponseException and wrap it in an ExecutionException that will be thrown by the ResponseFuture
    RestLiResponseException restLiResponseException = new MockRestliResponseExceptionBuilder().setErrorResponse(_errorResponse).setStatus(HttpStatus.fromCode(status)).setCookies(getCookies() == null ? Collections.emptyList() : getCookies()).setHeaders(getHeaders() == null ? new HashMap<>() : getHeaders()).build();
    ExecutionException executionException = new ExecutionException(restLiResponseException);
    Future<Response<V>> responseFuture = buildFuture(null, executionException);
    return new ResponseFutureImpl<V>(responseFuture, _errorHandlingBehavior);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) Response(com.linkedin.restli.client.Response) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResponseFutureImpl(com.linkedin.restli.internal.client.ResponseFutureImpl)

Aggregations

Response (com.linkedin.restli.client.Response)11 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)8 Test (org.testng.annotations.Test)8 FutureCallback (com.linkedin.common.callback.FutureCallback)6 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)6 GreetingsCallbackBuilders (com.linkedin.restli.examples.greetings.client.GreetingsCallbackBuilders)6 CountDownLatch (java.util.concurrent.CountDownLatch)3 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 ErrorResponse (com.linkedin.restli.common.ErrorResponse)2 IdResponse (com.linkedin.restli.common.IdResponse)2 ResponseFutureImpl (com.linkedin.restli.internal.client.ResponseFutureImpl)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 Callback (com.linkedin.common.callback.Callback)1 HostSet (com.linkedin.d2.balancer.util.HostSet)1 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)1 ConsistentHashKeyMapperTest (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapperTest)1 FieldDef (com.linkedin.data.template.FieldDef)1