Search in sources :

Example 6 with HashBasedPartitionProperties

use of com.linkedin.d2.balancer.properties.HashBasedPartitionProperties in project rest.li by linkedin.

the class PartitionPropertiesConverterTest method testHashMD5PartitionProperties.

@Test
public void testHashMD5PartitionProperties() {
    final String partitionKeyRegex = "/foo/bar/(\\d+)";
    final int partitionCount = 8;
    final HashBasedPartitionProperties.HashAlgorithm hashAlgorithm = HashBasedPartitionProperties.HashAlgorithm.MD5;
    PartitionProperties partitionProperties = new HashBasedPartitionProperties(partitionKeyRegex, partitionCount, hashAlgorithm);
    D2ClusterPartitionConfiguration.PartitionTypeSpecificData data = new D2ClusterPartitionConfiguration.PartitionTypeSpecificData();
    data.setHashAlgorithm(com.linkedin.d2.HashAlgorithm.MD5);
    D2ClusterPartitionConfiguration partitionConfig = new D2ClusterPartitionConfiguration().setType(PartitionTypeEnum.HASH).setPartitionKeyRegex(partitionKeyRegex).setPartitionCount(partitionCount).setPartitionTypeSpecificData(data);
    Assert.assertEquals(PartitionPropertiesConverter.toProperties(partitionConfig), partitionProperties);
    Assert.assertEquals(PartitionPropertiesConverter.toConfig(partitionProperties), partitionConfig);
}
Also used : PartitionProperties(com.linkedin.d2.balancer.properties.PartitionProperties) RangedPartitionProperties(com.linkedin.d2.RangedPartitionProperties) NullPartitionProperties(com.linkedin.d2.balancer.properties.NullPartitionProperties) HashBasedPartitionProperties(com.linkedin.d2.balancer.properties.HashBasedPartitionProperties) RangeBasedPartitionProperties(com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties) HashBasedPartitionProperties(com.linkedin.d2.balancer.properties.HashBasedPartitionProperties) D2ClusterPartitionConfiguration(com.linkedin.d2.D2ClusterPartitionConfiguration) Test(org.testng.annotations.Test)

Example 7 with HashBasedPartitionProperties

use of com.linkedin.d2.balancer.properties.HashBasedPartitionProperties 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)

Aggregations

HashBasedPartitionProperties (com.linkedin.d2.balancer.properties.HashBasedPartitionProperties)7 RangeBasedPartitionProperties (com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties)6 RangedPartitionProperties (com.linkedin.d2.RangedPartitionProperties)4 PartitionProperties (com.linkedin.d2.balancer.properties.PartitionProperties)4 D2ClusterPartitionConfiguration (com.linkedin.d2.D2ClusterPartitionConfiguration)3 CustomizedPartitionProperties (com.linkedin.d2.balancer.properties.CustomizedPartitionProperties)3 NullPartitionProperties (com.linkedin.d2.balancer.properties.NullPartitionProperties)3 Test (org.testng.annotations.Test)3 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)1 PartitionAccessorList (com.linkedin.d2.PartitionAccessorList)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 RewriteLoadBalancerClient (com.linkedin.d2.balancer.clients.RewriteLoadBalancerClient)1 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1