Search in sources :

Example 46 with TransportClient

use of com.linkedin.r2.transport.common.bridge.client.TransportClient in project rest.li by linkedin.

the class TestHttpClientFactory method testClientShutdownBeingCalledMultipleTimes.

@Test
public void testClientShutdownBeingCalledMultipleTimes() throws InterruptedException, ExecutionException, TimeoutException {
    HttpClientFactory factory = new HttpClientFactory.Builder().build();
    TransportClient client = factory.getClient(Collections.<String, Object>emptyMap());
    // first shutdown call
    FutureCallback<None> clientShutdown = new FutureCallback<>();
    client.shutdown(clientShutdown);
    clientShutdown.get(30, TimeUnit.SECONDS);
    // second shutdown call
    clientShutdown = new FutureCallback<>();
    client.shutdown(clientShutdown);
    try {
        clientShutdown.get(30, TimeUnit.SECONDS);
        Assert.fail("should have thrown exception on the second shutdown call.");
    } catch (ExecutionException ex) {
        Assert.assertTrue(ex.getCause() instanceof IllegalStateException);
    }
    FutureCallback<None> shutdownCallback = new FutureCallback<>();
    factory.shutdown(shutdownCallback);
    shutdownCallback.get(30, TimeUnit.SECONDS);
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) ExecutionException(java.util.concurrent.ExecutionException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 47 with TransportClient

use of com.linkedin.r2.transport.common.bridge.client.TransportClient in project rest.li by linkedin.

the class TestHttpNettyStreamClient method testUnsupportedRestRequest.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnsupportedRestRequest() throws UnsupportedOperationException {
    TransportClient client = new HttpClientBuilder(_eventLoop, _scheduler).buildStreamClient();
    client.restRequest(null, new RequestContext(), new HashMap<>(), null);
    Assert.fail("The Http Stream clients should throw UnsupportedOperationException when streamRequest is called");
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Aggregations

TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)46 HashMap (java.util.HashMap)28 RequestContext (com.linkedin.r2.message.RequestContext)22 URI (java.net.URI)21 Test (org.testng.annotations.Test)17 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)15 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)13 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)10 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)10 Map (java.util.Map)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 Callback (com.linkedin.common.callback.Callback)9 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)8 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)7 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 None (com.linkedin.common.util.None)6 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)6 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)6