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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations