Search in sources :

Example 11 with PartitionInfoProvider

use of com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider in project rest.li by linkedin.

the class URIMapperTestUtil method createRangeBasedPartitionInfoProvider.

/**
 * Create a mock PartitionInfoProvider that returns {@link RangeBasedPartitionAccessor} for testing
 */
public static PartitionInfoProvider createRangeBasedPartitionInfoProvider(int partitionCount) throws ServiceUnavailableException {
    PartitionInfoProvider infoProvider = Mockito.mock(PartitionInfoProvider.class);
    RangeBasedPartitionProperties properties = new RangeBasedPartitionProperties(PARTITION_KEY_REGEX, 0, 1, partitionCount);
    RangeBasedPartitionAccessor accessor = new RangeBasedPartitionAccessor(properties);
    Mockito.when(infoProvider.getPartitionAccessor(anyObject())).thenReturn(accessor);
    return infoProvider;
}
Also used : PartitionInfoProvider(com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider) RangeBasedPartitionAccessor(com.linkedin.d2.balancer.util.partitions.RangeBasedPartitionAccessor) RangeBasedPartitionProperties(com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties)

Example 12 with PartitionInfoProvider

use of com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider in project rest.li by linkedin.

the class URIMapperTestUtil method createHashBasedPartitionInfoProvider.

/**
 * Create a mock PartitionInfoProvider that returns {@link HashBasedPartitionAccessor} for testing
 */
public static PartitionInfoProvider createHashBasedPartitionInfoProvider(int partitionCount, String regex) throws ServiceUnavailableException {
    PartitionInfoProvider infoProvider = Mockito.mock(PartitionInfoProvider.class);
    HashBasedPartitionProperties properties = new HashBasedPartitionProperties(regex, partitionCount, HashBasedPartitionProperties.HashAlgorithm.MODULO);
    HashBasedPartitionAccessor accessor = new HashBasedPartitionAccessor(properties);
    Mockito.when(infoProvider.getPartitionAccessor(anyObject())).thenReturn(accessor);
    return infoProvider;
}
Also used : PartitionInfoProvider(com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider) HashBasedPartitionProperties(com.linkedin.d2.balancer.properties.HashBasedPartitionProperties) HashBasedPartitionAccessor(com.linkedin.d2.balancer.util.partitions.HashBasedPartitionAccessor)

Example 13 with PartitionInfoProvider

use of com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider in project rest.li by linkedin.

the class TestRestLiScatterGather method getURIMapper.

private static URIMapper getURIMapper(boolean sticky, boolean partitioned, String regex) throws ServiceUnavailableException {
    int partitionCount = partitioned ? 10 : 1;
    int totalHostCount = 100;
    HashRingProvider ringProvider = createStaticHashRingProvider(totalHostCount, partitionCount, getHashFunction(sticky));
    PartitionInfoProvider infoProvider = createHashBasedPartitionInfoProvider(partitionCount, regex);
    return new RingBasedUriMapper(ringProvider, infoProvider);
}
Also used : HashRingProvider(com.linkedin.d2.balancer.util.hashing.HashRingProvider) URIMapperTestUtil.createStaticHashRingProvider(com.linkedin.d2.balancer.util.hashing.URIMapperTestUtil.createStaticHashRingProvider) URIMapperTestUtil.createHashBasedPartitionInfoProvider(com.linkedin.d2.balancer.util.hashing.URIMapperTestUtil.createHashBasedPartitionInfoProvider) PartitionInfoProvider(com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider) RingBasedUriMapper(com.linkedin.d2.balancer.util.hashing.RingBasedUriMapper)

Aggregations

PartitionInfoProvider (com.linkedin.d2.balancer.util.partitions.PartitionInfoProvider)13 URIMapper (com.linkedin.d2.balancer.URIMapper)10 Test (org.testng.annotations.Test)10 URIKeyPair (com.linkedin.d2.balancer.util.URIKeyPair)9 URI (java.net.URI)9 HashSet (java.util.HashSet)7 Set (java.util.Set)7 URIRequest (com.linkedin.d2.balancer.util.URIRequest)3 Request (com.linkedin.r2.message.Request)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PartitionAccessException (com.linkedin.d2.balancer.util.partitions.PartitionAccessException)2 ArrayList (java.util.ArrayList)2 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 HashBasedPartitionProperties (com.linkedin.d2.balancer.properties.HashBasedPartitionProperties)1 RangeBasedPartitionProperties (com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties)1 URIMappingResult (com.linkedin.d2.balancer.util.URIMappingResult)1 HashRingProvider (com.linkedin.d2.balancer.util.hashing.HashRingProvider)1 RingBasedUriMapper (com.linkedin.d2.balancer.util.hashing.RingBasedUriMapper)1 URIMapperTestUtil (com.linkedin.d2.balancer.util.hashing.URIMapperTestUtil)1