use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class QuorumTest method testQuorumIsSetCorrectlyOnNodeInitialization.
@Test
public void testQuorumIsSetCorrectlyOnNodeInitialization() {
String quorumName1 = randomString();
String quorumName2 = randomString();
QuorumConfig quorumConfig1 = new QuorumConfig().setName(quorumName1).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {
@Override
public boolean apply(Collection<Member> members) {
return true;
}
});
QuorumConfig quorumConfig2 = new QuorumConfig().setName(quorumName2).setEnabled(true).setSize(2);
Config config = new Config().addQuorumConfig(quorumConfig1).addQuorumConfig(quorumConfig2);
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
final Quorum quorum1 = hazelcastInstance.getQuorumService().getQuorum(quorumName1);
final Quorum quorum2 = hazelcastInstance.getQuorumService().getQuorum(quorumName2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(quorum1.isPresent());
assertFalse(quorum2.isPresent());
}
});
}
use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class QuorumTest method testQuorumIgnoresMemberAttributeEvents.
@Test
public void testQuorumIgnoresMemberAttributeEvents() {
final RecordingQuorumFunction function = new RecordingQuorumFunction();
QuorumConfig quorumConfig = new QuorumConfig().setName(randomString()).setEnabled(true).setQuorumFunctionImplementation(function);
Config config = new Config().addQuorumConfig(quorumConfig);
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
NodeEngineImpl nodeEngine = getNodeEngineImpl(hazelcastInstance);
MembershipAwareService service = nodeEngine.getService(QuorumServiceImpl.SERVICE_NAME);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(function.wasCalled);
}
});
function.wasCalled = false;
MemberAttributeServiceEvent event = mock(MemberAttributeServiceEvent.class);
service.memberAttributeChanged(event);
assertFalse(function.wasCalled);
}
use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class QuorumTest method testCustomQuorumFunctionFailsForAllNodes.
@Test(expected = QuorumException.class)
public void testCustomQuorumFunctionFailsForAllNodes() {
String mapName = randomMapName();
String quorumName = randomString();
MapConfig mapConfig = new MapConfig(mapName).setQuorumName(quorumName);
QuorumConfig quorumConfig = new QuorumConfig().setName(quorumName).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {
@Override
public boolean apply(Collection<Member> members) {
return false;
}
});
Config config = new Config().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
factory.newHazelcastInstance(config);
HazelcastInstance hz = factory.newHazelcastInstance(config);
IMap<Object, Object> map2 = hz.getMap(mapName);
map2.put("1", "1");
}
use of com.hazelcast.config.QuorumConfig 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.config.QuorumConfig in project hazelcast by hazelcast.
the class CacheQuorumListenerTest 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 cacheName = randomString();
String quorumName = randomString();
QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
quorumConfig.addListenerConfig(listenerConfig);
config.getCacheConfig(cacheName).setQuorumName(quorumName);
config.addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastServerCachingProvider cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(instance1);
Cache<Object, Object> cache = cachingProvider1.getCacheManager().getCache(cacheName);
try {
cache.put(generateKeyOwnedBy(instance1), 1);
fail("Expected a QuorumException");
} catch (QuorumException expected) {
EmptyStatement.ignore(expected);
}
assertOpenEventually(belowLatch, 15);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
cache.put(generateKeyOwnedBy(instance1), 1);
assertOpenEventually(aboveLatch, 15);
}
Aggregations