use of com.hazelcast.config.QuorumListenerConfig in project hazelcast by hazelcast.
the class QuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.
@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
final CountDownLatch belowLatch = new CountDownLatch(2);
Config config = new Config();
QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
listenerConfig.setImplementation(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
Collection<Member> currentMembers = quorumEvent.getCurrentMembers();
assertEquals(3, quorumEvent.getThreshold());
assertTrue(currentMembers.size() < quorumEvent.getThreshold());
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);
}
use of com.hazelcast.config.QuorumListenerConfig in project hazelcast by hazelcast.
the class QuorumListenerTest method testCustomResolverFiresQuorumFailureEvent.
@Test
public void testCustomResolverFiresQuorumFailureEvent() {
final CountDownLatch countDownLatch = new CountDownLatch(1);
Config config = new Config();
QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
listenerConfig.setImplementation(new QuorumListener() {
@Override
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
countDownLatch.countDown();
}
}
});
String mapName = randomMapName();
String quorumName = randomString();
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(quorumName);
quorumConfig.setEnabled(true);
quorumConfig.addListenerConfig(listenerConfig);
quorumConfig.setQuorumFunctionImplementation(new QuorumFunction() {
@Override
public boolean apply(Collection<Member> members) {
return false;
}
});
config.getMapConfig(mapName).setQuorumName(quorumName);
config.addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
factory.newHazelcastInstance(config);
factory.newHazelcastInstance();
assertOpenEventually(countDownLatch, 15);
}
use of com.hazelcast.config.QuorumListenerConfig 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);
}
use of com.hazelcast.config.QuorumListenerConfig in project hazelcast by hazelcast.
the class BaseQuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.
@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
final CountDownLatch quorumNotPresent = new CountDownLatch(1);
QuorumListenerConfig listenerConfig = new QuorumListenerConfig(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
Collection<Member> currentMembers = quorumEvent.getCurrentMembers();
assertEquals(3, quorumEvent.getThreshold());
assertTrue(currentMembers.size() < quorumEvent.getThreshold());
quorumNotPresent.countDown();
}
}
});
String distributedObjectName = randomString();
String quorumName = randomString();
QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3).addListenerConfig(listenerConfig);
Config config = new Config().addQuorumConfig(quorumConfig);
addQuorumConfig(config, distributedObjectName, quorumName);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
assertOpenEventually(quorumNotPresent);
}
use of com.hazelcast.config.QuorumListenerConfig in project hazelcast by hazelcast.
the class QuorumServiceImpl method initializeListeners.
private void initializeListeners() {
for (Map.Entry<String, QuorumConfig> configEntry : nodeEngine.getConfig().getQuorumConfigs().entrySet()) {
QuorumConfig config = configEntry.getValue();
String instanceName = configEntry.getKey();
for (QuorumListenerConfig listenerConfig : config.getListenerConfigs()) {
initializeListenerInternal(instanceName, listenerConfig);
}
}
}
Aggregations