Search in sources :

Example 11 with SplitBrainProtectionConfig

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());
}
Also used : MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecentlyActiveSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction) ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with SplitBrainProtectionConfig

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");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with SplitBrainProtectionConfig

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());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecentlyActiveSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction) ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with SplitBrainProtectionConfig

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);
}
Also used : MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with SplitBrainProtectionConfig

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) {
    }
}
Also used : MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecentlyActiveSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction) ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.cluster.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SplitBrainProtectionConfig (com.hazelcast.config.SplitBrainProtectionConfig)32 Config (com.hazelcast.config.Config)21 QuickTest (com.hazelcast.test.annotation.QuickTest)21 Test (org.junit.Test)21 MapConfig (com.hazelcast.config.MapConfig)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ProbabilisticSplitBrainProtectionFunction (com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction)9 RecentlyActiveSplitBrainProtectionFunction (com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction)9 Member (com.hazelcast.cluster.Member)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 SplitBrainProtectionListenerConfig (com.hazelcast.config.SplitBrainProtectionListenerConfig)4 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)3 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2 AssertTask (com.hazelcast.test.AssertTask)2 IQueue (com.hazelcast.collection.IQueue)1 AttributeConfig (com.hazelcast.config.AttributeConfig)1 AwsConfig (com.hazelcast.config.AwsConfig)1 AzureConfig (com.hazelcast.config.AzureConfig)1 BitmapIndexOptions (com.hazelcast.config.BitmapIndexOptions)1