use of com.linkedin.d2.balancer.simple.SimpleLoadBalancer in project rest.li by linkedin.
the class RetryClientTest method testRestException.
@Test
public void testRestException() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/bad"));
DynamicClient dynamicClient = new DynamicClient(balancer, null);
RetryClient client = new RetryClient(dynamicClient, 3);
URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
RestRequest restRequest = new RestRequestBuilder(uri).build();
TrackerClientTest.TestCallback<RestResponse> restCallback = new TrackerClientTest.TestCallback<RestResponse>();
RequestContext context = new RequestContext();
KeyMapper.TargetHostHints.setRequestContextTargetHost(context, URI.create("http://test.linkedin.com/bad"));
client.restRequest(restRequest, context, restCallback);
assertNull(restCallback.t);
assertNotNull(restCallback.e);
assertTrue(restCallback.e.getMessage().contains("exception happens"));
}
use of com.linkedin.d2.balancer.simple.SimpleLoadBalancer in project rest.li by linkedin.
the class RetryClientTest method testRetry.
@Test
public void testRetry() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/good"));
DynamicClient dynamicClient = new DynamicClient(balancer, null);
RetryClient client = new RetryClient(dynamicClient, 3);
URI uri = URI.create("d2://retryService?arg1arg2");
RestRequest restRequest = new RestRequestBuilder(uri).build();
TrackerClientTest.TestCallback<RestResponse> restCallback = new TrackerClientTest.TestCallback<RestResponse>();
client.restRequest(restRequest, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
}
use of com.linkedin.d2.balancer.simple.SimpleLoadBalancer in project rest.li by linkedin.
the class TestScatterGather method testScatterGatherEntityLoadBalancerIntegration.
@Test(dataProvider = "requestBuilderDataProvider")
public static void testScatterGatherEntityLoadBalancerIntegration(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
SimpleLoadBalancer loadBalancer = MockLBFactory.createLoadBalancer();
KeyMapper keyMapper = new ConsistentHashKeyMapper(loadBalancer, new TestPartitionInfoProvider());
try {
keyMapper.mapKeysV2(URI.create("http://badurischeme/"), new HashSet<String>());
Assert.fail("keyMapper should reject non-D2 URI scheme");
} catch (IllegalArgumentException e) {
//expected
}
ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(keyMapper);
final int NUM_IDS = 20;
Long[] requestIds = generateIds(NUM_IDS);
Collection<ScatterGatherBuilder.KVRequestInfo<Long, EntityResponse<Greeting>>> scatterGatherRequests = buildScatterGatherGetEntityRequests(sg, requestIds);
}
use of com.linkedin.d2.balancer.simple.SimpleLoadBalancer in project rest.li by linkedin.
the class MockLBFactory method createLoadBalancer.
static SimpleLoadBalancer createLoadBalancer() {
// define the load balancing strategies that we support (round robin, etc)
Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>>();
loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
Map<String, TransportClientFactory> clientFactories = new HashMap<String, TransportClientFactory>();
clientFactories.put("http", new HttpClientFactory());
SynchronousExecutorService executorService = new SynchronousExecutorService();
MockStore<ServiceProperties> serviceRegistry = new MockStore<ServiceProperties>();
MockStore<ClusterProperties> clusterRegistry = new MockStore<ClusterProperties>();
MockStore<UriProperties> uriRegistry = new MockStore<UriProperties>();
SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
state.listenToService("greetings", new LoadBalancerState.NullStateListenerCallback());
state.listenToService("groups", new LoadBalancerState.NullStateListenerCallback());
state.listenToCluster("testcluster", new LoadBalancerState.NullStateListenerCallback());
state.listenToCluster("badcluster", new LoadBalancerState.NullStateListenerCallback());
List<String> schemes = new ArrayList<String>();
schemes.add("http");
Map<String, Object> metadataProperties = new HashMap<String, Object>();
metadataProperties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PROPERTY, AllProtocolVersions.BASELINE_PROTOCOL_VERSION.toString());
serviceRegistry.put("greetings", new ServiceProperties("greetings", "testcluster", "/greetings", Arrays.asList("degrader"), Collections.<String, Object>emptyMap(), null, null, schemes, null, metadataProperties));
serviceRegistry.put("groups", new ServiceProperties("groups", "badcluster", "/groups", Arrays.asList("degrader"), Collections.<String, Object>emptyMap(), null, null, schemes, null, metadataProperties));
clusterRegistry.put("testcluster", new ClusterProperties("testcluster"));
clusterRegistry.put("badcluster", new ClusterProperties("badcluster"));
uriRegistry.put("testcluster", new UriProperties("testcluster", createUriData("http://localhost:1338")));
uriRegistry.put("badcluster", new UriProperties("badcluster", createUriData("http://localhost:1337")));
// create the load balancer
return new SimpleLoadBalancer(state);
}
Aggregations