use of com.linkedin.d2.balancer.LoadBalancer 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);
}
use of com.linkedin.d2.balancer.LoadBalancer 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<>(keyMapper);
final int NUM_IDS = 20;
Long[] requestIds = generateIds(NUM_IDS);
Collection<ScatterGatherBuilder.KVRequestInfo<Long, EntityResponse<Greeting>>> scatterGatherRequests = buildScatterGatherGetEntityRequests(sg, requestIds);
}
Aggregations