use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class MemberDomConfigProcessor method handleSplitBrainProtection.
protected void handleSplitBrainProtection(Node node) {
String name = getAttribute(node, "name");
SplitBrainProtectionConfig splitBrainProtectionConfig = ConfigUtils.getByNameOrNew(config.getSplitBrainProtectionConfigs(), name, SplitBrainProtectionConfig.class);
handleSplitBrainProtectionNode(node, splitBrainProtectionConfig, name);
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionListenerTest method whenCustomResolverDefined_splitBrainProtectionEventsFired.
@Test
public void whenCustomResolverDefined_splitBrainProtectionEventsFired() {
EventCountingSplitBrainProtectionListener listener = new EventCountingSplitBrainProtectionListener(0, 1);
SplitBrainProtectionListenerConfig listenerConfig = new SplitBrainProtectionListenerConfig(listener);
SplitBrainProtectionFunction function = members -> members.size() >= 2;
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(randomName()).setEnabled(true).addListenerConfig(listenerConfig).setFunctionImplementation(function);
Config config = new Config().addSplitBrainProtectionConfig(splitBrainProtectionConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config).shutdown();
assertOpenEventually(listener.notPresentLatch);
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testCustomSplitBrainProtectionFunctionFails.
@Test(expected = SplitBrainProtectionException.class)
public void testCustomSplitBrainProtectionFunctionFails() {
String mapName = randomMapName();
String splitBrainProtectionName = randomString();
MapConfig mapConfig = new MapConfig(mapName).setSplitBrainProtectionName(splitBrainProtectionName);
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(splitBrainProtectionName).setEnabled(true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return false;
}
});
Config config = new Config().addSplitBrainProtectionConfig(splitBrainProtectionConfig).addMapConfig(mapConfig);
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
map.put("1", "1");
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testCustomSplitBrainProtectionFunctionFailsForAllNodes.
@Test(expected = SplitBrainProtectionException.class)
public void testCustomSplitBrainProtectionFunctionFailsForAllNodes() {
String mapName = randomMapName();
String splitBrainProtectionName = randomString();
MapConfig mapConfig = new MapConfig(mapName).setSplitBrainProtectionName(splitBrainProtectionName);
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(splitBrainProtectionName).setEnabled(true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return false;
}
});
Config config = new Config().addMapConfig(mapConfig).addSplitBrainProtectionConfig(splitBrainProtectionConfig);
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.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method givenProbabilisticSplitBrainProtection_whenAcceptableHeartbeatPause_lessThanHeartbeatInterval_exceptionIsThrown.
@Test(expected = InvalidConfigurationException.class)
public void givenProbabilisticSplitBrainProtection_whenAcceptableHeartbeatPause_lessThanHeartbeatInterval_exceptionIsThrown() {
Config config = new Config();
config.setProperty(ClusterProperty.HEARTBEAT_INTERVAL_SECONDS.getName(), "5");
SplitBrainProtectionConfig probabilisticSplitBrainProtectionConfig = SplitBrainProtectionConfig.newProbabilisticSplitBrainProtectionConfigBuilder("prob-split-brain-protection", 3).withAcceptableHeartbeatPauseMillis(3000).build();
config.addSplitBrainProtectionConfig(probabilisticSplitBrainProtectionConfig);
createHazelcastInstance(config);
}
Aggregations