Search in sources :

Example 36 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 37 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)

Example 38 with TransportClient

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

the class TestHttpNettyStreamClient method testUnsupportedRestRequestHttp2.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testUnsupportedRestRequestHttp2() throws UnsupportedOperationException {
    TransportClient client = new HttpClientBuilder(_eventLoop, _scheduler).buildHttp2StreamClient();
    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)

Example 39 with TransportClient

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

the class PerfClients method httpPureStream.

public static PerfClient httpPureStream(URI uri, int numThreads, int numMsgs, int msgSize, int numHeaders, int headerSize) {
    final TransportClient transportClient = FACTORY.getClient(Collections.<String, String>emptyMap());
    final Client client = new TransportClientAdapter(transportClient, true);
    final Generator<StreamRequest> reqGen = new StreamRequestGenerator(uri, numMsgs, msgSize, numHeaders, headerSize);
    final ClientRunnableFactory crf = new StreamClientRunnableFactory(client, reqGen);
    return new FactoryClient(crf, numThreads);
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) Client(com.linkedin.r2.transport.common.Client) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Example 40 with TransportClient

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

the class SimpleLoadBalancerStrawMan method main.

public static void main(String[] args) throws URISyntaxException, ServiceUnavailableException {
    // define the load balancing strategies that we support (round robin, etc)
    Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>();
    loadBalancerStrategyFactories.put("rr", new RandomLoadBalancerStrategyFactory());
    loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
    // define the clients that we support (http, etc)
    Map<String, TransportClientFactory> clientFactories = new HashMap<>();
    clientFactories.put("http", new HttpClientFactory.Builder().build());
    // listen for service updates (could be a glu discovery client, zk discovery client,
    // config discovery client, etc)
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    MockStore<ServiceProperties> serviceRegistry = new MockStore<>();
    MockStore<ClusterProperties> clusterRegistry = new MockStore<>();
    MockStore<UriProperties> uriRegistry = new MockStore<>();
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
    // create the load balancer
    SimpleLoadBalancer loadBalancer = new SimpleLoadBalancer(state, executorService);
    final TransportClient tc = loadBalancer.getClient(new URIRequest("d2://browsemaps/52"), new RequestContext());
    final Client c = new TransportClientAdapter(tc, true);
    c.restRequest(null);
}
Also used : HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) MockStore(com.linkedin.d2.discovery.stores.mock.MockStore) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RequestContext(com.linkedin.r2.message.RequestContext) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) Client(com.linkedin.r2.transport.common.Client) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) URIRequest(com.linkedin.d2.balancer.util.URIRequest) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

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