use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.
the class LoadBalancerEchoServer method startServer.
public void startServer() throws IOException, InterruptedException, URISyntaxException {
final RestDispatcher restDispatcher = new RestDispatcher();
final TransportDispatcherBuilder dispatcherBuilder = new TransportDispatcherBuilder();
for (String validPath : _validPaths) {
dispatcherBuilder.addRestHandler(URI.create(validPath), restDispatcher);
}
final TransportDispatcher dispatcher = dispatcherBuilder.build();
// start the server
if (_scheme.equals("http")) {
_server = getHttpServer(dispatcher);
}
_server.start();
}
use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.
the class ProfileClientExample method sendTraffic.
private static void sendTraffic(Map<String, Map<String, Long>> trafficProportion, D2Client d2Client, Long delay) throws Exception {
for (Map.Entry<String, Map<String, Long>> d2Service : trafficProportion.entrySet()) {
for (Map.Entry<String, Long> partition : d2Service.getValue().entrySet()) {
final URI uri = new URI("d2://" + d2Service.getKey() + "?partitionId=" + partition.getKey());
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri).setMethod("get");
if (delay != null) {
requestBuilder.setHeader("delay", delay.toString());
}
RestRequest request = requestBuilder.build();
Long queryPerSecond = partition.getValue();
for (int i = 0; i < queryPerSecond; i++) {
// we don't care about the result from the server after all,
// you can see the traffic hits the echo server from stdout
d2Client.restRequest(request, new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
System.err.println("URI = " + uri.toString() + " didn't get any response");
}
@Override
public void onSuccess(RestResponse result) {
System.out.println("URI = " + uri.toString() + " was served by " + result.getEntity().asString("UTF-8"));
}
});
}
}
}
}
use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.
the class ExampleD2Client method sendTraffic.
private static void sendTraffic(Map<String, Long> trafficProportion, D2Client d2Client) throws URISyntaxException {
for (Map.Entry<String, Long> entry : trafficProportion.entrySet()) {
URI uri = new URI("d2://" + entry.getKey());
RestRequest request = new RestRequestBuilder(uri).setMethod("get").build();
for (long i = 0; i < entry.getValue(); i++) {
// we don't care about the result from the server after all,
// you can see the traffic hits the echo server from stdout
d2Client.restRequest(request);
}
}
}
use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.
the class AbstractClient method restRequest.
@Override
public void restRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
StreamRequest streamRequest = Messages.toStreamRequest(request);
// IS_FULL_REQUEST flag, if set true, would result in the request being sent without using chunked transfer encoding
// This is needed as the legacy R2 server (before 2.8.0) does not support chunked transfer encoding.
requestContext.putLocalAttr(R2Constants.IS_FULL_REQUEST, true);
// here we add back the content-length header for the response because some client code depends on this header
streamRequest(streamRequest, requestContext, Messages.toStreamCallback(callback, true));
}
use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.
the class TestServerTimeoutAsyncEvent method testFilterThrowButShouldNotTimeout.
@Test
public void testFilterThrowButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(getHttpUri(BUGGY_FILTER_URI)).setEntity(new byte[10240]).build();
_client.restRequest(request);
Future<RestResponse> futureResponse = _client.restRequest(request);
// if server times out, our second request would fail with TimeoutException because it's blocked by first one
try {
futureResponse.get(ASYNC_EVENT_TIMEOUT / 2, TimeUnit.MILLISECONDS);
Assert.fail("Should fail with ExecutionException");
} catch (ExecutionException ex) {
Assert.assertTrue(ex.getCause() instanceof RestException);
RestException restException = (RestException) ex.getCause();
Assert.assertTrue(restException.getResponse().getEntity().asString("UTF8").contains("Buggy filter throws."));
}
}
Aggregations