1,
1,
1,
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
Cluster newCluster = new Cluster("single_zone_cluster", nodes, zones);
try {
adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
fail("Should have thrown an exception since rep-factor = 1");
} catch(VoldemortException e) {}
// Test 1 - With consistent routing strategy
storeDef = ServerTestUtils.getStoreDef("consistent",
2,
1,
1,
1,
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
// On node 0
Map<Integer, List<Integer>> replicationMapping = adminClient.replicaOps.getReplicationMapping(0,
newCluster,
storeDef);
{
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(1,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 2
replicationMapping = adminClient.replicaOps.getReplicationMapping(2,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(3, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 3
replicationMapping = adminClient.replicaOps.getReplicationMapping(3,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
// Test 2 - With zone routing strategy
HashMap<Integer, Integer> zoneReplicationFactors = Maps.newHashMap();
for(int zoneIds = 0; zoneIds < 2; zoneIds++) {
zoneReplicationFactors.put(zoneIds, 1);
}
storeDef = ServerTestUtils.getStoreDef("zone",
2,
1,
1,
1,
0,
0,
zoneReplicationFactors,
HintedHandoffStrategyType.PROXIMITY_STRATEGY,
RoutingStrategyType.ZONE_STRATEGY);
newCluster = new Cluster("multi_zone_cluster", nodes, zones);
{
// On node 0
replicationMapping = adminClient.replicaOps.getReplicationMapping(0,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(0, 4, 8, 2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(1,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 2
replicationMapping = adminClient.replicaOps.getReplicationMapping(2,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8, 2, 6, 10));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 3
replicationMapping = adminClient.replicaOps.getReplicationMapping(3,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
// Test 3 - Consistent with rep factor 3
storeDef = ServerTestUtils.getStoreDef("consistent",
3,
1,
1,
1,
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
newCluster = new Cluster("single_zone_cluster", nodes, zones);
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(0,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(1,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(2,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(3, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(3,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
zoneReplicationFactors = Maps.newHashMap();
for(int zoneIds = 0; zoneIds < 2; zoneIds++) {
zoneReplicationFactors.put(zoneIds, 2);
}
storeDef = ServerTestUtils.getStoreDef("zone",
1,
1,
1,
1,
0,
0,
zoneReplicationFactors,
HintedHandoffStrategyType.PROXIMITY_STRATEGY,
RoutingStrategyType.ZONE_STRATEGY);
newCluster = new Cluster("multi_zone_cluster", nodes, zones);
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(0,
newCluster,
storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();