use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QuorumTest method testCustomQuorumFunctionFailsThenSuccess.
@Test
public void testCustomQuorumFunctionFailsThenSuccess() {
final AtomicInteger count = new AtomicInteger(1);
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) {
if (count.get() == 1) {
count.incrementAndGet();
return false;
} else {
return true;
}
}
});
Config config = new Config().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
try {
map.put("1", "1");
fail();
} catch (Exception e) {
e.printStackTrace();
}
factory.newHazelcastInstance(config);
map.put("1", "1");
factory.shutdownAll();
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class MapReadWriteQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
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);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class MapWriteQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
quorumConfig.setEnabled(true);
quorumConfig.setType(QuorumType.WRITE);
quorumConfig.setSize(3);
MapConfig mapConfig = new MapConfig(MAP_NAME_PREFIX + "*");
mapConfig.setQuorumName(QUORUM_ID);
cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(mapConfig, quorumConfig);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QuorumListenerTest method testQuorumFailureEventFiredWhenNodeCountDropsBelowThreshold.
@Test
public void testQuorumFailureEventFiredWhenNodeCountDropsBelowThreshold() {
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 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();
factory.newHazelcastInstance(config);
factory.newHazelcastInstance();
HazelcastInstance hz = factory.newHazelcastInstance();
hz.shutdown();
assertOpenEventually(countDownLatch, 15);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QuorumListenerTest 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();
}
}
}));
MapConfig fourNodeMapConfig = new MapConfig("fourNode");
fourNodeMapConfig.setQuorumName(fourNodeQuorumName);
MapConfig threeNodeMapConfig = new MapConfig("threeNode");
threeNodeMapConfig.setQuorumName(threeNodeQuorumName);
Config config = new Config();
config.addMapConfig(fourNodeMapConfig);
config.addQuorumConfig(fourNodeQuorumConfig);
config.addMapConfig(threeNodeMapConfig);
config.addQuorumConfig(threeNodeQuorumConfig);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
assertOpenEventually(quorumFailureLatch);
}
Aggregations