Search in sources :

Example 1 with TransportDispatcherBuilder

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();
}
Also used : TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 2 with TransportDispatcherBuilder

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) } };
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) HashMap(java.util.HashMap) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) ByteString(com.linkedin.data.ByteString) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) DataProvider(org.testng.annotations.DataProvider)

Example 3 with TransportDispatcherBuilder

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();
}
Also used : TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 4 with TransportDispatcherBuilder

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);
}
Also used : StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) PerfStreamWriter(test.r2.perf.PerfStreamWriter) StreamRequestHandler(com.linkedin.r2.transport.common.StreamRequestHandler) Callback(com.linkedin.common.callback.Callback) StringGenerator(test.r2.perf.StringGenerator) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 5 with TransportDispatcherBuilder

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();
        }
    }
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) HashMap(java.util.HashMap) RestResponse(com.linkedin.r2.message.rest.RestResponse) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Aggregations

TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)9 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)8 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)6 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)3 None (com.linkedin.common.util.None)2 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)2 HashMap (java.util.HashMap)2 Callback (com.linkedin.common.callback.Callback)1 FutureCallback (com.linkedin.common.callback.FutureCallback)1 ByteString (com.linkedin.data.ByteString)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)1 StreamRequestHandler (com.linkedin.r2.transport.common.StreamRequestHandler)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 DataProvider (org.testng.annotations.DataProvider)1