use of com.hazelcast.quorum.QuorumFunction in project hazelcast by hazelcast.
the class CacheQuorumListenerTest 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 cacheName = randomString();
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.getCacheConfig(cacheName).setQuorumName(quorumName);
config.addQuorumConfig(quorumConfig);
HazelcastInstance instance = createHazelcastInstance(config);
HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance);
Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache(cacheName);
try {
cache.put(generateKeyOwnedBy(instance), 1);
fail("Expected a QuorumException");
} catch (QuorumException expected) {
EmptyStatement.ignore(expected);
}
assertOpenEventually(countDownLatch, 15);
}
use of com.hazelcast.quorum.QuorumFunction 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);
}
Aggregations