Search in sources :

Example 6 with PartitionedLoadBalancerTestState

use of com.linkedin.d2.balancer.PartitionedLoadBalancerTestState in project rest.li by linkedin.

the class TestAllPartitionsRequestBuilder method getKeyToHostMapper.

private ConsistentHashKeyMapper getKeyToHostMapper(int partitionNum, List<URI> expectedUris, RingFactory<URI> ringFactory) throws URISyntaxException {
    Map<URI, Map<Integer, PartitionData>> partitionDescriptions = new HashMap<URI, Map<Integer, PartitionData>>();
    for (int i = 0; i < partitionNum; i++) {
        final URI foo = new URI("http://foo" + i + ".com");
        expectedUris.add(foo);
        Map<Integer, PartitionData> foo1Data = new HashMap<Integer, PartitionData>();
        foo1Data.put(i, new PartitionData(1.0));
        partitionDescriptions.put(foo, foo1Data);
    }
    List<LoadBalancerState.SchemeStrategyPair> orderedStrategies = new ArrayList<LoadBalancerState.SchemeStrategyPair>();
    LoadBalancerStrategy strategy = new ConsistentHashKeyMapperTest.TestLoadBalancerStrategy(partitionDescriptions, ringFactory);
    orderedStrategies.add(new LoadBalancerState.SchemeStrategyPair("http", strategy));
    PartitionAccessor accessor = new ConsistentHashKeyMapperTest.TestPartitionAccessor();
    SimpleLoadBalancer balancer = new SimpleLoadBalancer(new PartitionedLoadBalancerTestState("clusterName", "serviceName", "path", "strategyName", partitionDescriptions, orderedStrategies, accessor));
    return new ConsistentHashKeyMapper(balancer, balancer);
}
Also used : SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) PartitionedLoadBalancerTestState(com.linkedin.d2.balancer.PartitionedLoadBalancerTestState) URI(java.net.URI) LoadBalancerState(com.linkedin.d2.balancer.LoadBalancerState) PartitionAccessor(com.linkedin.d2.balancer.util.partitions.PartitionAccessor) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

LoadBalancerState (com.linkedin.d2.balancer.LoadBalancerState)6 PartitionedLoadBalancerTestState (com.linkedin.d2.balancer.PartitionedLoadBalancerTestState)6 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)6 PartitionAccessor (com.linkedin.d2.balancer.util.partitions.PartitionAccessor)6 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 SimpleLoadBalancer (com.linkedin.d2.balancer.simple.SimpleLoadBalancer)4 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)4 Test (org.testng.annotations.Test)3 DegraderLoadBalancerStrategyConfig (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyConfig)2 DegraderLoadBalancerStrategyV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3)2 DefaultPartitionAccessor (com.linkedin.d2.balancer.util.partitions.DefaultPartitionAccessor)2 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1