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);
}
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");
}
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");
}
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);
}
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);
}
Aggregations