use of com.hazelcast.quorum.QuorumListener in project hazelcast by hazelcast.
the class QuorumListenerTest method testQuorumEventsFiredWhenNodeCountBelowThenAboveThreshold.
@Test
public void testQuorumEventsFiredWhenNodeCountBelowThenAboveThreshold() {
final CountDownLatch belowLatch = new CountDownLatch(1);
final CountDownLatch aboveLatch = new CountDownLatch(1);
Config config = new Config();
QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
listenerConfig.setImplementation(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (quorumEvent.isPresent()) {
aboveLatch.countDown();
} else {
belowLatch.countDown();
}
}
});
String mapName = randomMapName();
String quorumName = randomString();
QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
quorumConfig.addListenerConfig(listenerConfig);
config.getMapConfig(mapName).setQuorumName(quorumName);
config.addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
assertOpenEventually(belowLatch, 15);
factory.newHazelcastInstance(config);
assertOpenEventually(aboveLatch);
}
Aggregations