Search in sources :

Example 1 with URIMapperTestUtil

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());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PartitionInfoProvider(com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider) URI(java.net.URI) URIKeyPair(com.linkedin.d2.balancer.util.URIKeyPair) URIMapper(com.linkedin.d2.balancer.URIMapper) Test(org.testng.annotations.Test)

Aggregations

URIMapper (com.linkedin.d2.balancer.URIMapper)1 URIKeyPair (com.linkedin.d2.balancer.util.URIKeyPair)1 PartitionInfoProvider (com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1