Search in sources :

Example 86 with Server

use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.

the class TestCompressionEcho method tearDown.

@Override
protected void tearDown(Client client, Server server) throws Exception {
    for (Client compressionClient : _clients) {
        final FutureCallback<None> clientShutdownCallback = new FutureCallback<>();
        compressionClient.shutdown(clientShutdownCallback);
        clientShutdownCallback.get();
    }
    super.tearDown(client, server);
}
Also used : Client(com.linkedin.r2.transport.common.Client) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 87 with Server

use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.

the class TestGeneralEchoServiceTest 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<>();
    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));
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) FutureCallback(com.linkedin.common.callback.FutureCallback) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) ExecutionException(java.util.concurrent.ExecutionException) RestException(com.linkedin.r2.message.rest.RestException) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 88 with Server

use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.

the class Https2JettyServerProvider method createServer.

@Override
public Server createServer(ServerCreationContext context) {
    int sslPort = context.getPort();
    int httpPort = SslContextUtil.getHttpPortFromHttps(sslPort);
    return new HttpServerFactory(context.getFilterChain()).createHttpsH2cServer(httpPort, sslPort, SslContextUtil.KEY_STORE, SslContextUtil.KEY_STORE_PASSWORD, context.getContextPath(), context.getThreadPoolSize(), context.getTransportDispatcher(), _servletType, context.getServerTimeout(), _serverROS);
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory)

Example 89 with Server

use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.

the class TestLatencyInstrumentation method checkTimingKeyConsistency.

/**
 * Ensures that the set of recorded timing keys is "consistent", meaning that for any code path (denoted by key "A")
 * which is a subset of another code path (denoted by key "B"), the duration of key A must be less than that of key B.
 */
private void checkTimingKeyConsistency() {
    ArrayList<Map.Entry<TimingKey, TimingContextUtil.TimingContext>> entrySet = new ArrayList<>(_resultMap.entrySet());
    int size = entrySet.size();
    // (e.g. duration of "fwk/server/response" > duration of "fwk/server/response/restli")
    for (int i = 0; i < size; i++) {
        TimingKey keyA = entrySet.get(i).getKey();
        if (!keyA.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
            continue;
        }
        for (int j = 0; j < size; j++) {
            TimingKey keyB = entrySet.get(j).getKey();
            if (i == j || !keyB.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
                continue;
            }
            if (keyA.getName().contains(keyB.getName())) {
                TimingContextUtil.TimingContext contextA = entrySet.get(i).getValue();
                TimingContextUtil.TimingContext contextB = entrySet.get(j).getValue();
                String message = String.format("Expected %s (%.2fms) < %s (%.2fms)", keyA, contextA.getDurationNano() * NANOS_TO_MILLIS, keyB, contextB.getDurationNano() * NANOS_TO_MILLIS);
                Assert.assertTrue(contextA.getDurationNano() < contextB.getDurationNano(), message);
            }
        }
    }
}
Also used : TimingContextUtil(com.linkedin.r2.message.timing.TimingContextUtil) TimingKey(com.linkedin.r2.message.timing.TimingKey) ArrayList(java.util.ArrayList)

Example 90 with Server

use of com.linkedin.r2.transport.common.Server in project rest.li by linkedin.

the class TestLatencyInstrumentation method beforeMethod.

@BeforeMethod
public void beforeMethod(Object[] args) throws Exception {
    _countDownLatch = new CountDownLatch(1);
    _useStreaming = (boolean) args[0];
    _timingImportanceThreshold = (TimingImportance) args[3];
    final InstrumentationTrackingFilter instrumentationTrackingFilter = new InstrumentationTrackingFilter();
    final FilterChain filterChain = FilterChains.empty().addFirst(instrumentationTrackingFilter).addFirstRest(instrumentationTrackingFilter);
    // System.setProperty("test.useStreamCodecServer", "true"); // Uncomment this to test with server streaming codec in IDEA
    super.init(Collections.emptyList(), filterChain, false);
}
Also used : FilterChain(com.linkedin.r2.filter.FilterChain) CountDownLatch(java.util.concurrent.CountDownLatch) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Test (org.testng.annotations.Test)82 RestRequest (com.linkedin.r2.message.rest.RestRequest)52 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)50 RequestContext (com.linkedin.r2.message.RequestContext)49 URI (java.net.URI)43 RestResponse (com.linkedin.r2.message.rest.RestResponse)41 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)32 FutureCallback (com.linkedin.common.callback.FutureCallback)30 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)30 CountDownLatch (java.util.concurrent.CountDownLatch)24 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)23 RestException (com.linkedin.r2.message.rest.RestException)21 ExecutionException (java.util.concurrent.ExecutionException)21 None (com.linkedin.common.util.None)20 Server (org.eclipse.jetty.server.Server)20 ByteString (com.linkedin.data.ByteString)19 HttpServerBuilder (com.linkedin.r2.testutils.server.HttpServerBuilder)19 HashMap (java.util.HashMap)15 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)13 ArrayList (java.util.ArrayList)13