use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class TestHttpsEcho method testHttpEcho.
/**
* Test that https-enabled server and client can speak plain HTTP as well.
*/
@Test
public void testHttpEcho() throws Exception {
final EchoService client = new RestEchoClient(Bootstrap.createHttpURI(Bootstrap.getEchoURI()), _client);
final String msg = "This is a simple http echo message";
final FutureCallback<String> callback = new FutureCallback<String>();
client.echo(msg, callback);
Assert.assertEquals(callback.get(), msg);
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class AbstractEchoServiceTest method testThrowingEchoService.
@Test
public void testThrowingEchoService() throws Exception {
final EchoService client = getEchoClient(_client, Bootstrap.getThrowingEchoURI());
final String msg = "This is a simple echo message";
final FutureCallback<String> callback = new FutureCallback<String>();
client.echo(msg, callback);
try {
callback.get();
Assert.fail("Should have thrown an exception");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof RemoteInvocationException);
}
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class AbstractEchoServiceTest method testBadRestURI.
@Test
public void testBadRestURI() {
final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
if (!(client instanceof RestEchoClient)) {
return;
}
final String msg = "This is a simple echo message";
final FutureCallback<String> callback = new FutureCallback<String>();
client.echo(msg, callback);
try {
callback.get();
Assert.fail("Should have thrown an exception");
} catch (Exception e) {
Assert.assertTrue(e instanceof ExecutionException);
Assert.assertTrue(e.getCause() instanceof RestException);
RestException re = (RestException) e.getCause();
Assert.assertEquals(re.getResponse().getStatus(), RestStatus.NOT_FOUND);
}
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class AbstractEchoServiceTest method testFilterChainOnException.
@Test
public void testFilterChainOnException() throws Exception {
final EchoService client = getEchoClient(_client, URI.create("/unknown-service"));
final String msg = "This is a simple echo message";
final FutureCallback<String> callback = new FutureCallback<String>();
client.echo(msg, callback);
try {
callback.get();
Assert.fail("Should have thrown an exception");
} catch (Exception e) {
// expected
}
// Make sure the server got its wire attribute
Assert.assertEquals(_serverCaptureFilter.getRequest().get(_toServerKey), _toServerValue);
// Make sure the client got its wire attribute, but not the server's wire attribute
Assert.assertEquals(_clientCaptureFilter.getResponse().get(_toClientKey), _toClientValue);
Assert.assertNull(_clientCaptureFilter.getResponse().get(_toServerKey));
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class TestMultiplexedCallback method testMixed.
@Test
public void testMixed() throws Exception {
FutureCallback<RestResponse> callback1 = new FutureCallback<RestResponse>();
FutureCallback<RestResponse> callback2 = new FutureCallback<RestResponse>();
ImmutableMap<Integer, Callback<RestResponse>> individualCallbacks = ImmutableMap.<Integer, Callback<RestResponse>>of(ID1, callback1, ID2, callback2);
FutureCallback<MultiplexedResponse> aggregatedCallback = new FutureCallback<MultiplexedResponse>();
TestRecord entity1 = fakeEntity(ID1);
IndividualResponse ir1 = fakeIndividualResponse(entity1);
IndividualResponse ir2 = fakeIndividualErrorResponse();
MultiplexedResponseContent responseContent = new MultiplexedResponseContent().setResponses(new IndividualResponseMap(ImmutableMap.of(Integer.toString(ID1), ir1, Integer.toString(ID2), ir2)));
MultiplexedCallback multiplexedCallback = new MultiplexedCallback(individualCallbacks, aggregatedCallback);
multiplexedCallback.onSuccess(fakeRestResponse(responseContent));
assertRestResponseEquals(callback1.get(), fakeRestResponse(entity1));
RestException actualError = (RestException) getError(callback2);
assertRestResponseEquals(actualError.getResponse(), fakeRestErrorResponse());
MultiplexedResponse multiplexedResponse = aggregatedCallback.get();
Assert.assertEquals(multiplexedResponse.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(multiplexedResponse.getHeaders(), HEADERS);
}
Aggregations