public void testDistributedFramework() throws Exception {
final long generation = 1;
Set<AffinityGroup> group1 = new HashSet<AffinityGroup>();
{
HashSet<Identity> identitySet = new HashSet<Identity>();
identitySet.add(new DummyIdentity("1"));
identitySet.add(new DummyIdentity("2"));
identitySet.add(new DummyIdentity("3"));
AffinitySet a = new AffinitySet(1, generation, identitySet);
group1.add(a);
identitySet = new HashSet<Identity>();
identitySet.add(new DummyIdentity("4"));
identitySet.add(new DummyIdentity("5"));
AffinitySet b = new AffinitySet(2, generation, identitySet);
group1.add(b);
}
Set<AffinityGroup> group2 = new HashSet<AffinityGroup>();
{
HashSet<Identity> identitySet = new HashSet<Identity>();
identitySet.add(new DummyIdentity("6"));
identitySet.add(new DummyIdentity("7"));
AffinitySet a = new AffinitySet(1, generation, identitySet);
group2.add(a);
identitySet = new HashSet<Identity>();
identitySet.add(new DummyIdentity("8"));
identitySet.add(new DummyIdentity("9"));
AffinitySet b = new AffinitySet(3, generation, identitySet);
group2.add(b);
}
Set<AffinityGroup> group3 = new HashSet<AffinityGroup>();
{
HashSet<Identity> identitySet = new HashSet<Identity>();
identitySet.add(new DummyIdentity("10"));
identitySet.add(new DummyIdentity("11"));
AffinitySet a = new AffinitySet(4, generation, identitySet);
group3.add(a);
}
HashSet<TestLPAClient> clients = new HashSet<TestLPAClient>();
TestLPAClient client1 = new TestLPAClient(server, 10, 10, 3, group1);
TestLPAClient client2 = new TestLPAClient(server, 20, 20, 4, group2);
TestLPAClient client3 = new TestLPAClient(server, 30, 30, 2, group3);
clients.add(client1);
clients.add(client2);
clients.add(client3);
server.register(10, client1);
server.register(20, client2);
server.register(30, client3);
long now = System.currentTimeMillis();
Set<RelocatingAffinityGroup> groups = server.findAffinityGroups();
System.out.printf("finished in %d milliseconds %n",
System.currentTimeMillis() - now);
for (TestLPAClient client : clients) {
assertFalse(client.failed);
assertTrue(client.currentIter >= client.convergeCount);
}
for (AffinityGroup ag : groups) {
Set<Identity> ids = ag.getIdentities();
if (ag.getId() == 1) {
assertEquals(5, ids.size());
assertTrue(ids.contains(new DummyIdentity("1")));
assertTrue(ids.contains(new DummyIdentity("2")));
assertTrue(ids.contains(new DummyIdentity("3")));
assertTrue(ids.contains(new DummyIdentity("6")));
assertTrue(ids.contains(new DummyIdentity("7")));
} else if (ag.getId() == 2) {
assertEquals(2, ids.size());
assertTrue(ids.contains(new DummyIdentity("4")));
assertTrue(ids.contains(new DummyIdentity("5")));
} else if (ag.getId() == 3) {
assertEquals(2, ids.size());
assertTrue(ids.contains(new DummyIdentity("8")));
assertTrue(ids.contains(new DummyIdentity("9")));
} else if (ag.getId() == 4) {
assertEquals(2, ids.size());
assertTrue(ids.contains(new DummyIdentity("10")));
assertTrue(ids.contains(new DummyIdentity("11")));
} else {
fail("Unknown group found " + ag.getId());
}
}
}