use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class TestDisruptor method testStreamLatencyDisrupt.
@Test
public void testStreamLatencyDisrupt() throws Exception {
final Map<String, String> properties = new HashMap<>();
final TransportClientFactory factory = new HttpClientFactory.Builder().build();
final TransportClient client = factory.getClient(properties);
final RequestContext requestContext = new RequestContext();
requestContext.putLocalAttr(DISRUPT_CONTEXT_KEY, DisruptContexts.delay(REQUEST_LATENCY));
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean success = new AtomicBoolean(false);
client.streamRequest(new StreamRequestBuilder(new URI(REQUEST_URI)).build(EntityStreams.emptyStream()), requestContext, new HashMap<>(), response -> {
success.set(!response.hasError() && response.getResponse() != null);
latch.countDown();
});
Assert.assertTrue(latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS), "Test execution timeout");
Assert.assertTrue(success.get(), "Unexpected transport response");
}
use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class D2ClientBuilder method createDefaultTransportClientFactories.
private Map<String, TransportClientFactory> createDefaultTransportClientFactories() {
final Map<String, TransportClientFactory> clientFactories = new HashMap<>();
TransportClientFactory transportClientFactory = new HttpClientFactory.Builder().build();
clientFactories.put("http", transportClientFactory);
clientFactories.put("https", transportClientFactory);
return clientFactories;
}
use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class LoadBalancerClientCli method getZKFSLoadBalancer.
public ZKFSLoadBalancer getZKFSLoadBalancer(String zkConnectString, String d2path, String d2ServicePath) throws Exception {
_tmpDir = createTempDirectory(_tmpdirName);
ZKFSComponentFactory componentFactory = new ZKFSComponentFactory();
if (d2ServicePath == null || d2ServicePath.isEmpty()) {
d2ServicePath = "services";
}
Map<String, TransportClientFactory> clientFactories = new HashMap<>();
clientFactories.put("http", new HttpClientFactory.Builder().build());
Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>();
loadBalancerStrategyFactories.put("random", new RandomLoadBalancerStrategyFactory());
loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV2", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV3", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV2_1", new DegraderLoadBalancerStrategyFactoryV3());
ZKFSTogglingLoadBalancerFactoryImpl factory = new ZKFSTogglingLoadBalancerFactoryImpl(componentFactory, TIMEOUT, TimeUnit.MILLISECONDS, d2path, _tmpDir.getAbsolutePath(), clientFactories, loadBalancerStrategyFactories, d2ServicePath, null, null, false);
return new ZKFSLoadBalancer(zkConnectString, SESSION_TIMEOUT, (int) TIMEOUT, factory, null, d2path);
}
use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testShutdown.
@Test(groups = { "small", "back-end" })
public void testShutdown() throws URISyntaxException, InterruptedException {
reset();
URI uri = URI.create("http://cluster-1/test");
TestListener listener = new TestListener();
List<String> schemes = new ArrayList<>();
Map<Integer, PartitionData> partitionData = new HashMap<>(1);
partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>();
uriData.put(uri, partitionData);
schemes.add("http");
_state.register(listener);
assertNull(listener.scheme);
assertNull(listener.strategy);
assertNull(listener.serviceName);
// set up state
_state.listenToCluster("cluster-1", new NullStateListenerCallback());
_state.listenToService("service-1", new NullStateListenerCallback());
_clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1", schemes));
_uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));
_serviceRegistry.put("service-1", new ServiceProperties("service-1", "cluster-1", "/test", Arrays.asList("random")));
TrackerClient client = _state.getClient("cluster-1", uri);
TestShutdownCallback callback = new TestShutdownCallback();
_state.shutdown(callback);
if (!callback.await(10, TimeUnit.SECONDS)) {
fail("unable to shut down state");
}
for (TransportClientFactory factory : _clientFactories.values()) {
SimpleLoadBalancerTest.DoNothingClientFactory f = (SimpleLoadBalancerTest.DoNothingClientFactory) factory;
assertEquals(f.getRunningClientCount(), 0, "Not all clients were shut down");
}
}
use of com.linkedin.r2.transport.common.TransportClientFactory in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testShutdownWithListener.
@Test(groups = { "small", "back-end" })
public void testShutdownWithListener() throws URISyntaxException, InterruptedException {
reset();
URI uri = URI.create("http://cluster-1/test");
TestListener listener = new TestListener();
List<String> schemes = new ArrayList<>();
Map<Integer, PartitionData> partitionData = new HashMap<>(1);
partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>();
uriData.put(uri, partitionData);
schemes.add("http");
_state.register(listener);
assertNull(listener.scheme);
assertNull(listener.strategy);
assertNull(listener.serviceName);
// set up state
_state.listenToCluster("cluster-1", new NullStateListenerCallback());
_state.listenToService("service-1", new NullStateListenerCallback());
List<String> strategyList = Arrays.asList("degraderV3");
_state.refreshServiceStrategies(new ServiceProperties("service-1", "cluster-1", "/test", strategyList, Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), Collections.<String, String>emptyMap(), schemes, Collections.<URI>emptySet()));
assertEquals(listener.scheme, "http");
assertNotNull(listener.strategy);
assertEquals(listener.serviceName, "service-1");
TrackerClient client = _state.getClient("cluster-1", uri);
TestShutdownCallback callback = new TestShutdownCallback();
_state.shutdown(callback);
if (!callback.await(10, TimeUnit.SECONDS)) {
fail("unable to shut down state");
}
for (TransportClientFactory factory : _clientFactories.values()) {
SimpleLoadBalancerTest.DoNothingClientFactory f = (SimpleLoadBalancerTest.DoNothingClientFactory) factory;
assertEquals(f.getRunningClientCount(), 0, "Not all clients were shut down");
}
assertNull(listener.scheme);
assertNull(listener.strategy);
assertNull(listener.serviceName);
}
Aggregations