use of com.linkedin.r2.transport.common.Client 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.r2.transport.common.Client 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.r2.transport.common.Client 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.r2.transport.common.Client in project rest.li by linkedin.
the class TestStreamRequest method testBackPressure.
@Test
public void testBackPressure() throws Exception {
for (Client client : clients()) {
final long totalBytes = SMALL_BYTES_NUM;
TimedBytesWriter writer = new TimedBytesWriter(totalBytes, BYTE);
EntityStream entityStream = EntityStreams.newEntityStream(writer);
StreamRequestBuilder builder = new StreamRequestBuilder(Bootstrap.createHttpURI(PORT, RATE_LIMITED_URI));
StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Callback<StreamResponse> callback = expectSuccessCallback(latch, status);
client.streamRequest(request, callback);
latch.await(60000, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), RestStatus.OK);
TimedBytesReader reader = _rateLimitedRequestHandler.getReader();
Assert.assertNotNull(reader);
Assert.assertEquals(totalBytes, reader.getTotalBytes());
Assert.assertTrue(reader.allBytesCorrect());
long clientSendTimespan = writer.getStopTime() - writer.getStartTime();
long serverReceiveTimespan = reader.getStopTime() - reader.getStartTime();
Assert.assertTrue(serverReceiveTimespan > 1000);
double diff = Math.abs(serverReceiveTimespan - clientSendTimespan);
double diffRatio = diff / clientSendTimespan;
// make it generous to reduce the chance occasional test failures
Assert.assertTrue(diffRatio < 0.2);
}
}
use of com.linkedin.r2.transport.common.Client in project rest.li by linkedin.
the class PerfClients method httpRest.
public static PerfClient httpRest(URI uri, int numThreads, int numMsgs, int msgSize, int numHeaders, int headerSize) {
final TransportClient transportClient = FACTORY.getClient(Collections.<String, String>emptyMap());
final Client client = new TransportClientAdapter(transportClient, PerfConfig.clientRestOverStream());
final Generator<RestRequest> reqGen = new RestRequestGenerator(uri, numMsgs, msgSize, numHeaders, headerSize);
final ClientRunnableFactory crf = new RestClientRunnableFactory(client, reqGen);
return new FactoryClient(crf, numThreads);
}
Aggregations