use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder 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.bridge.server.TransportDispatcherBuilder in project rest.li by linkedin.
the class TestHttpClient method configs.
@DataProvider
public Object[][] configs() {
Map<String, String> http1ClientProperties = new HashMap<>();
http1ClientProperties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, HttpProtocolVersion.HTTP_1_1.name());
http1ClientProperties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, Integer.toString(REQUEST_TIMEOUT));
Map<String, String> http2ClientProperties = new HashMap<>();
http2ClientProperties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, HttpProtocolVersion.HTTP_2.name());
http2ClientProperties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, Integer.toString(REQUEST_TIMEOUT));
TransportDispatcher dispatcher = new TransportDispatcherBuilder().addRestHandler(DISPATCHER_URI, new EchoHandler()).build();
return new Object[][] { { new HttpServerFactory().createH2cServer(PORT, dispatcher, REST_OVER_STREAM), new TransportClientAdapter(_clientFactory.getClient(http1ClientProperties), REST_OVER_STREAM) }, { new HttpServerFactory().createH2cServer(PORT, dispatcher, REST_OVER_STREAM), new TransportClientAdapter(_clientFactory.getClient(http2ClientProperties), REST_OVER_STREAM) }, { new HttpServerFactory().createH2cServer(PORT, dispatcher, NOT_REST_OVER_STREAM), new TransportClientAdapter(_clientFactory.getClient(http1ClientProperties), NOT_REST_OVER_STREAM) }, { new HttpServerFactory().createH2cServer(PORT, dispatcher, NOT_REST_OVER_STREAM), new TransportClientAdapter(_clientFactory.getClient(http2ClientProperties), NOT_REST_OVER_STREAM) } };
}
use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder in project rest.li by linkedin.
the class TestStreamRequest method getTransportDispatcher.
@Override
protected TransportDispatcher getTransportDispatcher() {
_scheduler = Executors.newSingleThreadScheduledExecutor();
_checkRequestHandler = new CheckRequestHandler(BYTE);
_rateLimitedRequestHandler = new RateLimitedRequestHandler(_scheduler, INTERVAL, BYTE);
return new TransportDispatcherBuilder().addStreamHandler(LARGE_URI, _checkRequestHandler).addStreamHandler(FOOBAR_URI, new CheckRequestHandler(BYTE)).addStreamHandler(RATE_LIMITED_URI, _rateLimitedRequestHandler).addStreamHandler(ERROR_RECEIVER_URI, new ThrowWhenReceivingRequestHandler()).build();
}
use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder in project rest.li by linkedin.
the class AbstractPerfServerFactory method createPureStreamServer.
public Server createPureStreamServer(int port, URI echoUri, final int msg_size, int numHeaders, int headerSize) {
String headerContent = new StringGenerator(headerSize).nextMessage();
StreamRequestHandler handler = new StreamRequestHandler() {
@Override
public void handleRequest(StreamRequest request, RequestContext requestContext, final Callback<StreamResponse> callback) {
request.getEntityStream().setReader(new PerfStreamReader<None>(new Callback<None>() {
@Override
public void onError(Throwable e) {
callback.onError(e);
}
@Override
public void onSuccess(None result) {
StreamResponseBuilder builder = new StreamResponseBuilder();
for (int i = 0; i < numHeaders; i++) {
builder.setHeader(STATIC_HEADER_PREFIX + i, headerContent);
}
callback.onSuccess(builder.build(EntityStreams.newEntityStream(new PerfStreamWriter(msg_size))));
}
}, None.none()));
}
};
final TransportDispatcher dispatcher = new TransportDispatcherBuilder().addStreamHandler(echoUri, handler).build();
return createServer(port, dispatcher, true);
}
use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder in project rest.li by linkedin.
the class TestClientShutdown method testShutdown.
@Test(dataProvider = "configs")
public void testShutdown(boolean clientROS, boolean serverROS, String protocolVersion) throws Exception {
_clientFactory = new HttpClientFactory();
Map<String, String> clientProperties = new HashMap<String, String>();
// very long shutdown timeout
clientProperties.put(HttpClientFactory.HTTP_SHUTDOWN_TIMEOUT, "60000");
clientProperties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocolVersion);
_client = new TransportClientAdapter(_clientFactory.getClient(clientProperties), clientROS);
TransportDispatcher dispatcher = new TransportDispatcherBuilder().addRestHandler(ECHO_URI, new EchoHandler()).build();
_server = new HttpServerFactory(HttpJettyServer.ServletType.RAP).createH2cServer(PORT, dispatcher, serverROS);
try {
_server.start();
RestRequestBuilder builder = new RestRequestBuilder(URI.create("http://localhost:" + PORT + ECHO_URI));
byte[] content = new byte[100];
builder.setEntity(content);
Future<RestResponse> future = _client.restRequest(builder.build());
RestResponse response = future.get(30, TimeUnit.SECONDS);
Assert.assertEquals(response.getEntity().copyBytes(), content);
final FutureCallback<None> clientShutdownCallback = new FutureCallback<None>();
_client.shutdown(clientShutdownCallback);
// we should catch those clients that do not shutdown properly in 5 seconds
clientShutdownCallback.get(5000, TimeUnit.MILLISECONDS);
final FutureCallback<None> factoryShutdownCallback = new FutureCallback<None>();
_clientFactory.shutdown(factoryShutdownCallback);
factoryShutdownCallback.get();
} finally {
if (_server != null) {
_server.stop();
_server.waitForStop();
}
}
}
Aggregations