use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testCustomSplitBrainProtectionFunctionIsPresent.
@Test
public void testCustomSplitBrainProtectionFunctionIsPresent() {
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);
try {
map.put("1", "1");
fail();
} catch (Exception ignored) {
}
SplitBrainProtection splitBrainProtection = hazelcastInstance.getSplitBrainProtectionService().getSplitBrainProtection(splitBrainProtectionName);
assertFalse(splitBrainProtection.hasMinimumSize());
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testCustomSplitBrainProtectionFunctionFailsThenSuccess.
@Test
public void testCustomSplitBrainProtectionFunctionFailsThenSuccess() {
String mapName = randomMapName();
String splitBrainProtectionName = randomString();
MapConfig mapConfig = new MapConfig(mapName).setSplitBrainProtectionName(splitBrainProtectionName);
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(splitBrainProtectionName).setEnabled(true).setFunctionImplementation(members -> members.size() >= 2);
Config config = new Config().addMapConfig(mapConfig).addSplitBrainProtectionConfig(splitBrainProtectionConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
try {
map.put("1", "1");
fail();
} catch (SplitBrainProtectionException ignored) {
}
factory.newHazelcastInstance(config);
map.put("1", "1");
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testSplitBrainProtectionIsSetCorrectlyOnNodeInitialization.
@Test
public void testSplitBrainProtectionIsSetCorrectlyOnNodeInitialization() {
String splitBrainProtectionName1 = randomString();
String splitBrainProtectionName2 = randomString();
SplitBrainProtectionConfig splitBrainProtectionConfig1 = new SplitBrainProtectionConfig().setName(splitBrainProtectionName1).setEnabled(true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return true;
}
});
SplitBrainProtectionConfig splitBrainProtectionConfig2 = new SplitBrainProtectionConfig().setName(splitBrainProtectionName2).setEnabled(true).setMinimumClusterSize(2);
Config config = new Config().addSplitBrainProtectionConfig(splitBrainProtectionConfig1).addSplitBrainProtectionConfig(splitBrainProtectionConfig2);
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
final SplitBrainProtection splitBrainProtection1 = hazelcastInstance.getSplitBrainProtectionService().getSplitBrainProtection(splitBrainProtectionName1);
final SplitBrainProtection splitBrainProtection2 = hazelcastInstance.getSplitBrainProtectionService().getSplitBrainProtection(splitBrainProtectionName2);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(splitBrainProtection1.hasMinimumSize());
assertFalse(splitBrainProtection2.hasMinimumSize());
}
});
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method givenProbabilisticSplitBrainProtection_whenAcceptableHeartbeatPause_greaterThanMaxNoHeartbeat_exceptionIsThrown.
@Test(expected = InvalidConfigurationException.class)
public void givenProbabilisticSplitBrainProtection_whenAcceptableHeartbeatPause_greaterThanMaxNoHeartbeat_exceptionIsThrown() {
Config config = new Config();
config.setProperty(ClusterProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "10");
SplitBrainProtectionConfig probabilisticSplitBrainProtectionConfig = SplitBrainProtectionConfig.newProbabilisticSplitBrainProtectionConfigBuilder("prob-split-brain-protection", 3).withAcceptableHeartbeatPauseMillis(13000).build();
config.addSplitBrainProtectionConfig(probabilisticSplitBrainProtectionConfig);
createHazelcastInstance(config);
}
use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.
the class SplitBrainProtectionTest method testOneSplitBrainProtectionsFailsOneSplitBrainProtectionSuccessForDifferentMaps.
@Test
public void testOneSplitBrainProtectionsFailsOneSplitBrainProtectionSuccessForDifferentMaps() {
String fourNodeSplitBrainProtection = randomString();
String threeNodeSplitBrainProtection = randomString();
MapConfig fourNodeMapConfig = new MapConfig("fourNode").setSplitBrainProtectionName(fourNodeSplitBrainProtection);
MapConfig threeNodeMapConfig = new MapConfig("threeNode").setSplitBrainProtectionName(threeNodeSplitBrainProtection);
SplitBrainProtectionConfig fourNodeSplitBrainProtectionConfig = new SplitBrainProtectionConfig(fourNodeSplitBrainProtection, true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return members.size() == 4;
}
});
SplitBrainProtectionConfig threeNodeSplitBrainProtectionConfig = new SplitBrainProtectionConfig(threeNodeSplitBrainProtection, true).setFunctionImplementation(new SplitBrainProtectionFunction() {
@Override
public boolean apply(Collection<Member> members) {
return members.size() == 3;
}
});
Config config = new Config().addMapConfig(fourNodeMapConfig).addMapConfig(threeNodeMapConfig).addSplitBrainProtectionConfig(threeNodeSplitBrainProtectionConfig).addSplitBrainProtectionConfig(fourNodeSplitBrainProtectionConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance hz = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
IMap<Object, Object> fourNode = hz.getMap("fourNode");
IMap<Object, Object> threeNode = hz.getMap("threeNode");
threeNode.put(generateKeyOwnedBy(hz), "bar");
try {
fourNode.put(generateKeyOwnedBy(hz), "bar");
fail();
} catch (Exception ignored) {
}
}
Aggregations