use of com.linkedin.d2.balancer.util.hashing.URIMapperTestUtil in project rest.li by linkedin.
the class RingBasedURIMapperTest method testPartitionIdOverride.
@Test(dataProvider = "stickyPartitionPermutation")
public void testPartitionIdOverride(boolean sticky, boolean partitioned) throws Exception {
int partitionCount = partitioned ? 10 : 1;
int totalHostCount = 100;
HashRingProvider ringProvider = createStaticHashRingProvider(totalHostCount, partitionCount, getHashFunction(sticky));
PartitionInfoProvider infoProvider = createRangeBasedPartitionInfoProvider(partitionCount);
URIMapper mapper = new RingBasedUriMapper(ringProvider, infoProvider);
URIKeyPair<Integer> request = new URIKeyPair<>(new URI("d2://testService/1"), IntStream.range(0, partitionCount).boxed().collect(Collectors.toSet()));
if (partitioned) {
Assert.assertThrows(() -> mapper.mapUris(Arrays.asList(request, request)));
}
URIMappingResult<Integer> uriMapperResult = mapper.mapUris(Collections.singletonList(request));
Map<URI, Set<Integer>> mappedKeys = uriMapperResult.getMappedKeys();
Assert.assertTrue(uriMapperResult.getUnmappedKeys().isEmpty());
Assert.assertEquals(mappedKeys.size(), partitionCount);
Assert.assertEquals(mappedKeys.keySet().stream().map(URIMapperTestUtil::getPartitionIdForURI).collect(Collectors.toSet()).size(), partitionCount);
for (Set<Integer> keys : mappedKeys.values()) {
Assert.assertTrue(keys.isEmpty());
}
}
Aggregations