MulticastDetector detector2 = new MulticastDetector();
Connector connector1 = new Connector();
Connector connector2 = new Connector();
NetworkRegistry reg1 = setupServers(detector1, connector1);
TestNotificationListener notif1 = new TestNotificationListener();
reg1.addNotificationListener(notif1, null, null);
NetworkRegistry reg2 = setupServers(detector2, connector2);
TestNotificationListener notif2 = new TestNotificationListener();
reg2.addNotificationListener(notif2, null, null);
// Need to allow heartbeat so have detection
Thread.currentThread().sleep(5000);
//Should now have an entry for both of the registries
int reg1Count = reg1.getServers().length;
int reg2Count = reg2.getServers().length;
// Actual junit test
assertTrue(reg1Count == 1 && reg2Count == 1);
if(reg1Count == 1 && reg2Count == 1)
{
System.out.println("PASSED - both registries have found the detectors.");
}
else
{
System.out.println("FAILED - registries not populated with remote detectors.");
}
assertTrue(((String)notif1.notifLog.get(0)).startsWith("ADDED"));
assertTrue(((String)notif1.notifLog.get(1)).startsWith("ADDED"));
System.out.println("Notifications from Registry #1--->" + notif1.notifLog);
assertTrue(((String)notif2.notifLog.get(0)).startsWith("ADDED"));
assertTrue(((String)notif2.notifLog.get(1)).startsWith("ADDED"));
System.out.println("Notifications from Registry #2--->" + notif2.notifLog);
// stop the 2nd detector, so see if 1st one detects it is missing
connector1.stop();
connector1.destroy();
connector1 = null;
connector2.stop();
connector2.destroy();
connector2 = null;
detector1.stop();
// sleep for a few seconds so the 1st detector can discover 2nd one down
Thread.sleep(60000);
// 1st one should be empty
reg1Count = reg2.getServers().length;
// Actual junit test
assertTrue(reg1Count == 0);
if(reg1Count == 0)