use of com.linkedin.d2.balancer.util.hashing.StaticRingProvider in project rest.li by linkedin.
the class TestScatterGather method getKeyToHostMapper.
private static ConsistentHashKeyMapper getKeyToHostMapper(int n, int partitionNum) throws URISyntaxException {
Map<URI, Integer> endpoints = new HashMap<URI, Integer>();
for (int ii = 0; ii < n; ++ii) {
endpoints.put(new URI("test" + String.valueOf(ii)), 100);
}
final int partitionSize = endpoints.size() / partitionNum;
List<Map<URI, Integer>> mapList = new ArrayList<Map<URI, Integer>>();
int count = 0;
for (final URI uri : endpoints.keySet()) {
final int index = count / partitionSize;
if (index == mapList.size()) {
mapList.add(new HashMap<URI, Integer>());
}
Map<URI, Integer> map = mapList.get(index);
map.put(uri, endpoints.get(uri));
count++;
}
List<Ring<URI>> rings = new ArrayList<Ring<URI>>();
for (final Map<URI, Integer> map : mapList) {
final ConsistentHashRing<URI> ring = new ConsistentHashRing<URI>(map);
rings.add(ring);
}
return new ConsistentHashKeyMapper(new StaticRingProvider(rings), new TestPartitionInfoProvider());
}
Aggregations