use of com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategy in project rest.li by linkedin.
the class RandomLoadBalancerTest method testRoundRobinBalancer.
@Test(groups = { "small", "back-end" })
public void testRoundRobinBalancer() {
RandomLoadBalancerStrategyFactory lbFactory = new RandomLoadBalancerStrategyFactory();
RandomLoadBalancerStrategy rrLoadBalancer = lbFactory.newLoadBalancer(null);
Map<Integer, PartitionData> partitionDataMap = new HashMap<>(2);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
TrackerClient trackerClient1 = Mockito.mock(TrackerClient.class);
TrackerClient trackerClient2 = Mockito.mock(TrackerClient.class);
Map<URI, TrackerClient> trackerClients = new HashMap<>();
URI uri1 = URI.create("http://cluster-1/test");
URI uri2 = URI.create("http://cluster-2/test");
trackerClients.put(uri1, trackerClient1);
trackerClients.put(uri2, trackerClient2);
// test balancer with two clients, both available
for (int i = 0; i < 100; ++i) {
assertNotNull(rrLoadBalancer.getTrackerClient(null, new RequestContext(), 0, DefaultPartitionAccessor.DEFAULT_PARTITION_ID, trackerClients));
}
}
Aggregations