Search in sources :

Example 6 with RandomLoadBalancerStrategy

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));
    }
}
Also used : TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) HashMap(java.util.HashMap) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)6 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)5 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)5 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)5 RandomLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategy)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)4 URI (java.net.URI)4 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)3 RelativeLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy)3 DegraderLoadBalancerStrategyV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3)2 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)1 RangeBasedPartitionProperties (com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties)1 RequestContext (com.linkedin.r2.message.RequestContext)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1