HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
try {
CoordinationStructures coord = new CoordinationStructures(hz);
SploutConfiguration dNodeConfig = SploutConfiguration.getTestConfig();
dNodeConfig.setProperty(DNodeProperties.PORT, 1000);
coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));
try {
handler.init(config);
} catch(Exception e) {
// since the handler will try to connect to "localhost:1000" we skip the Exception and continue
// the things we want to assert should be present anyway.
}
Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
1);
coord.getDNodes().remove(coord.getDNodes().entrySet().iterator().next().getKey());
Thread.sleep(100);
Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
0);
dNodeConfig = SploutConfiguration.getTestConfig();
dNodeConfig.setProperty(DNodeProperties.PORT, 1001);
coord.getDNodes().put("/localhost:1001", new DNodeInfo(dNodeConfig));
Thread.sleep(100);
Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
1);
dNodeConfig = SploutConfiguration.getTestConfig();
dNodeConfig.setProperty(DNodeProperties.PORT, 1000);
coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));
Thread.sleep(100);
Assert.assertEquals(handler.getContext().getCoordinationStructures().getDNodes().values().size(),
2);