/** Test predefined affinity - must be ported to other clients. */
@SuppressWarnings("UnaryPlus")
public void testPredefinedHashIdResolver() throws GridException {
// Use Md5 hasher for this test.
GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction();
getTestResources().inject(aff);
aff.setHashIdResolver(new GridCacheAffinityNodeHashResolver() {
@Override public Object resolve(GridNode node) {
return node.attribute(DFLT_REPLICA_COUNT_ATTR_NAME);
}
});
List<GridNode> nodes = new ArrayList<>();
nodes.add(createNode("000ea4cd-f449-4dcb-869a-5317c63bd619", 50));
nodes.add(createNode("010ea4cd-f449-4dcb-869a-5317c63bd62a", 60));
nodes.add(createNode("0209ec54-ff53-4fdb-8239-5a3ac1fb31bd", 70));
nodes.add(createNode("0309ec54-ff53-4fdb-8239-5a3ac1fb31ef", 80));
nodes.add(createNode("040c9b94-02ae-45a6-9d5c-a066dbdf2636", 90));
nodes.add(createNode("050c9b94-02ae-45a6-9d5c-a066dbdf2747", 100));
nodes.add(createNode("0601f916-4357-4cfe-a7df-49d4721690bf", 110));
nodes.add(createNode("0702f916-4357-4cfe-a7df-49d4721691c0", 120));
Map<Object, Integer> data = new LinkedHashMap<>();
data.put("", 4);
data.put("asdf", 3);
data.put("224ea4cd-f449-4dcb-869a-5317c63bd619", 5);
data.put("fdc9ec54-ff53-4fdb-8239-5a3ac1fb31bd", 2);
data.put("0f9c9b94-02ae-45a6-9d5c-a066dbdf2636", 2);
data.put("d8f1f916-4357-4cfe-a7df-49d4721690bf", 4);
data.put("c77ffeae-78a1-4ee6-a0fd-8d197a794412", 3);
data.put("35de9f21-3c9b-4f4a-a7d5-3e2c6cb01564", 4);
data.put("d67eb652-4e76-47fb-ad4e-cd902d9b868a", 2);
data.put(0, 4);
data.put(1, 1);
data.put(12, 7);
data.put(123, 1);
data.put(1234, 6);
data.put(12345, 2);
data.put(123456, 5);
data.put(1234567, 4);
data.put(12345678, 6);
data.put(123456789, 3);
data.put(1234567890, 3);
data.put(1234567890L, 3);
data.put(12345678901L, 0);
data.put(123456789012L, 1);
data.put(1234567890123L, 3);
data.put(12345678901234L, 5);
data.put(123456789012345L, 5);
data.put(1234567890123456L, 7);
data.put(-23456789012345L, 6);
data.put(-2345678901234L, 4);
data.put(-234567890123L, 3);
data.put(-23456789012L, 0);
data.put(-2345678901L, 4);
data.put(-234567890L, 5);
data.put(-234567890, 3);
data.put(-23456789, 3);
data.put(-2345678, 6);
data.put(-234567, 4);
data.put(-23456, 5);
data.put(-2345, 2);
data.put(-234, 7);
data.put(-23, 6);
data.put(-2, 6);
data.put(0x80000000, 7);
data.put(0x7fffffff, 1);
data.put(0x8000000000000000L, 7);
data.put(0x7fffffffffffffffL, 7);
data.put(+1.1, 2);
data.put(-10.01, 0);
data.put(+100.001, 2);
data.put(-1000.0001, 0);
data.put(+1.7976931348623157E+308, 6);
data.put(-1.7976931348623157E+308, 1);
data.put(+4.9E-324, 1);
data.put(-4.9E-324, 1);
boolean ok = true;
for (Map.Entry<Object, Integer> entry : data.entrySet()) {
int part = aff.partition(entry.getKey());
UUID exp = nodes.get(entry.getValue()).id();
UUID act = F.first(aff.nodes(part, nodes, 1)).id();
if (!exp.equals(act)) {
ok = false;
info("Failed to validate affinity for key '" + entry.getKey() + "' [expected=" + exp +