use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class CacheQuorumListenerTest method testDifferentQuorumsGetCorrectEvents.
@Test
public void testDifferentQuorumsGetCorrectEvents() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final CountDownLatch quorumFailureLatch = new CountDownLatch(2);
String fourNodeQuorumName = "fourNode";
QuorumConfig fourNodeQuorumConfig = new QuorumConfig(fourNodeQuorumName, true, 4);
fourNodeQuorumConfig.addListenerConfig(new QuorumListenerConfig(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
quorumFailureLatch.countDown();
}
}
}));
String threeNodeQuorumName = "threeNode";
QuorumConfig threeNodeQuorumConfig = new QuorumConfig(threeNodeQuorumName, true, 3);
threeNodeQuorumConfig.addListenerConfig(new QuorumListenerConfig(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
quorumFailureLatch.countDown();
}
}
}));
CacheSimpleConfig fourNodeCacheConfig = new CacheSimpleConfig();
fourNodeCacheConfig.setName("fourNode");
fourNodeCacheConfig.setQuorumName(fourNodeQuorumName);
CacheSimpleConfig threeNodeCacheConfig = new CacheSimpleConfig();
threeNodeCacheConfig.setName("threeNode");
threeNodeCacheConfig.setQuorumName(threeNodeQuorumName);
Config config = new Config();
config.addCacheConfig(fourNodeCacheConfig);
config.addQuorumConfig(fourNodeQuorumConfig);
config.addCacheConfig(threeNodeCacheConfig);
config.addQuorumConfig(threeNodeQuorumConfig);
HazelcastInstance h1 = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(h1);
Cache<Object, Object> fourNode = cachingProvider.getCacheManager().getCache("fourNode");
Cache<Object, Object> threeNode = cachingProvider.getCacheManager().getCache("threeNode");
try {
threeNode.put(generateKeyOwnedBy(h1), "bar");
fail("Expected a QuorumException");
} catch (QuorumException expected) {
EmptyStatement.ignore(expected);
}
try {
fourNode.put(generateKeyOwnedBy(h1), "bar");
fail("Expected a QuorumException");
} catch (QuorumException expected) {
EmptyStatement.ignore(expected);
}
assertOpenEventually(quorumFailureLatch, 15);
}
use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class CacheQuorumListenerTest method testQuorumFailureEventFiredWhenNodeCountBelowThreshold.
@Test
public void testQuorumFailureEventFiredWhenNodeCountBelowThreshold() {
final CountDownLatch countDownLatch = new CountDownLatch(1);
Config config = new Config();
QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
listenerConfig.setImplementation(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
countDownLatch.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);
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 CacheWriteQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
cacheConfig.setName(CACHE_NAME_PREFIX + "*");
cacheConfig.setQuorumName(QUORUM_ID);
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
quorumConfig.setType(QuorumType.WRITE);
quorumConfig.setEnabled(true);
quorumConfig.setSize(3);
PartitionedCluster cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(cacheConfig, quorumConfig);
cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(cluster.h1);
cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(cluster.h2);
cachingProvider3 = HazelcastServerCachingProvider.createCachingProvider(cluster.h3);
cachingProvider4 = HazelcastServerCachingProvider.createCachingProvider(cluster.h4);
cachingProvider5 = HazelcastServerCachingProvider.createCachingProvider(cluster.h5);
}
use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class AbstractLockQuorumTest method initializeFiveMemberCluster.
static void initializeFiveMemberCluster(QuorumType type, int quorumSize) {
QuorumConfig quorumConfig = new QuorumConfig().setName(QUORUM_ID).setType(type).setEnabled(true).setSize(quorumSize);
LockConfig lockConfig = new LockConfig(LOCK_NAME_PREFIX + "*").setQuorumName(QUORUM_ID);
cluster = new PartitionedCluster(new TestHazelcastInstanceFactory());
cluster.createFiveMemberCluster(lockConfig, quorumConfig);
l1 = getLock(cluster.h1);
l2 = getLock(cluster.h2);
l3 = getLock(cluster.h3);
l4 = getLock(cluster.h4);
l5 = getLock(cluster.h5);
}
use of com.hazelcast.config.QuorumConfig in project hazelcast by hazelcast.
the class MapReadQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
quorumConfig.setType(QuorumType.READ);
quorumConfig.setEnabled(true);
quorumConfig.setSize(3);
MapConfig mapConfig = new MapConfig(MAP_NAME_PREFIX + "*");
mapConfig.setQuorumName(QUORUM_ID);
cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(mapConfig, quorumConfig);
}
Aggregations