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);
}
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);
}
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);
}
Aggregations