Search in sources :

Example 11 with ConsistentHashKeyMapper

use of com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper 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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) HostToKeyMapper(com.linkedin.d2.balancer.util.HostToKeyMapper) KeyMapper(com.linkedin.d2.balancer.KeyMapper) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) Test(org.testng.annotations.Test) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest)

Example 12 with ConsistentHashKeyMapper

use of com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper in project rest.li by linkedin.

the class TestScatterGather method testBuildSGKVRequests.

public static void testBuildSGKVRequests(int endPointsNum, int partitionNum, RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, RestException, ServiceUnavailableException {
    final int NUM_ENDPOINTS = endPointsNum;
    ConsistentHashKeyMapper mapper;
    if (partitionNum > 0) {
        mapper = getKeyToHostMapper(endPointsNum, partitionNum);
    } else {
        mapper = getKeyToHostMapper(endPointsNum);
    }
    ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(mapper);
    final int NUM_IDS = 100;
    Long[] ids = generateIds(NUM_IDS);
    Map<Long, Greeting> updates = generateUpdates(ids);
    testBuildSGGetKVRequests(NUM_ENDPOINTS, sg, ids);
    testBuildSGDeleteRequests(NUM_ENDPOINTS, sg, ids, builders);
    testBuildSGUpdateRequests(NUM_ENDPOINTS, sg, updates, builders);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)

Example 13 with ConsistentHashKeyMapper

use of com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper in project rest.li by linkedin.

the class TestScatterGather method testBuildSGEntityRequests.

public static void testBuildSGEntityRequests(int endPointsNum, int partitionNum, RootBuilderWrapper<Long, Greeting> builders) throws URISyntaxException, RestException, ServiceUnavailableException {
    final int NUM_ENDPOINTS = endPointsNum;
    ConsistentHashKeyMapper mapper;
    if (partitionNum > 0) {
        mapper = getKeyToHostMapper(endPointsNum, partitionNum);
    } else {
        mapper = getKeyToHostMapper(endPointsNum);
    }
    ScatterGatherBuilder<Greeting> sg = new ScatterGatherBuilder<Greeting>(mapper);
    final int NUM_IDS = 100;
    Long[] ids = generateIds(NUM_IDS);
    Map<Long, Greeting> updates = generateUpdates(ids);
    testBuildSGGetEntityRequests(NUM_ENDPOINTS, sg, ids);
    testBuildSGDeleteRequests(NUM_ENDPOINTS, sg, ids, builders);
    testBuildSGUpdateRequests(NUM_ENDPOINTS, sg, updates, builders);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)

Aggregations

ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)10 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)8 SimpleLoadBalancer (com.linkedin.d2.balancer.simple.SimpleLoadBalancer)6 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 KeyMapper (com.linkedin.d2.balancer.KeyMapper)3 LoadBalancerState (com.linkedin.d2.balancer.LoadBalancerState)3 PartitionedLoadBalancerTestState (com.linkedin.d2.balancer.PartitionedLoadBalancerTestState)3 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)3 HostToKeyMapper (com.linkedin.d2.balancer.util.HostToKeyMapper)3 PartitionAccessor (com.linkedin.d2.balancer.util.partitions.PartitionAccessor)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Callback (com.linkedin.common.callback.Callback)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1