expectedEndpoints.get("Keyspace4").putAll(new BigIntegerToken("95"), makeAddrs("127.0.0.1", "127.0.0.2", "127.0.0.3"));
for (Map.Entry<String, AbstractReplicationStrategy> tableStrategy : tableStrategyMap.entrySet())
{
String table = tableStrategy.getKey();
AbstractReplicationStrategy strategy = tableStrategy.getValue();
for (Token token : keyTokens)
{
endpoints = tmd.getWriteEndpoints(token, table, strategy.getNaturalEndpoints(token));
assertTrue(expectedEndpoints.get(table).get(token).size() == endpoints.size());
assertTrue(expectedEndpoints.get(table).get(token).containsAll(endpoints));
}
// just to be sure that things still work according to the old tests, run them:
if (strategy.getReplicationFactor() != 3)
continue;
// tokens 5, 15 and 25 should go three nodes
for (int i = 0; i < 3; i++)
{
endpoints = tmd.getWriteEndpoints(keyTokens.get(i), table, strategy.getNaturalEndpoints(keyTokens.get(i)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(i+1)));
assertTrue(endpoints.contains(hosts.get(i+2)));
assertTrue(endpoints.contains(hosts.get(i+3)));
}
// token 35 should go to nodes 4, 5, 6 and boot1
endpoints = tmd.getWriteEndpoints(keyTokens.get(3), table, strategy.getNaturalEndpoints(keyTokens.get(3)));
assertTrue(endpoints.size() == 4);
assertTrue(endpoints.contains(hosts.get(4)));
assertTrue(endpoints.contains(hosts.get(5)));
assertTrue(endpoints.contains(hosts.get(6)));
assertTrue(endpoints.contains(boot1));
// token 45 should go to nodes 5, 6, 7 boot1
endpoints = tmd.getWriteEndpoints(keyTokens.get(4), table, strategy.getNaturalEndpoints(keyTokens.get(4)));
assertTrue(endpoints.size() == 4);
assertTrue(endpoints.contains(hosts.get(5)));
assertTrue(endpoints.contains(hosts.get(6)));
assertTrue(endpoints.contains(hosts.get(7)));
assertTrue(endpoints.contains(boot1));
// token 55 should go to nodes 6, 7, 8 boot1 and boot2
endpoints = tmd.getWriteEndpoints(keyTokens.get(5), table, strategy.getNaturalEndpoints(keyTokens.get(5)));
assertTrue(endpoints.size() == 5);
assertTrue(endpoints.contains(hosts.get(6)));
assertTrue(endpoints.contains(hosts.get(7)));
assertTrue(endpoints.contains(hosts.get(8)));
assertTrue(endpoints.contains(boot1));
assertTrue(endpoints.contains(boot2));
// token 65 should go to nodes 7, 8, 9 and boot2
endpoints = tmd.getWriteEndpoints(keyTokens.get(6), table, strategy.getNaturalEndpoints(keyTokens.get(6)));
assertTrue(endpoints.size() == 4);
assertTrue(endpoints.contains(hosts.get(7)));
assertTrue(endpoints.contains(hosts.get(8)));
assertTrue(endpoints.contains(hosts.get(9)));
assertTrue(endpoints.contains(boot2));
// token 75 should to go nodes 8, 9, 0 and boot2
endpoints = tmd.getWriteEndpoints(keyTokens.get(7), table, strategy.getNaturalEndpoints(keyTokens.get(7)));
assertTrue(endpoints.size() == 4);
assertTrue(endpoints.contains(hosts.get(8)));
assertTrue(endpoints.contains(hosts.get(9)));
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(boot2));
// token 85 should go to nodes 9, 0, 1
endpoints = tmd.getWriteEndpoints(keyTokens.get(8), table, strategy.getNaturalEndpoints(keyTokens.get(8)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(9)));
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(hosts.get(1)));
// token 95 should go to nodes 0, 1 and 2
endpoints = tmd.getWriteEndpoints(keyTokens.get(9), table, strategy.getNaturalEndpoints(keyTokens.get(9)));
assertTrue(endpoints.size() == 3);
assertTrue(endpoints.contains(hosts.get(0)));
assertTrue(endpoints.contains(hosts.get(1)));
assertTrue(endpoints.contains(hosts.get(2)));
}