Search in sources :

Example 6 with SplitBrainProtectionConfig

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);
}
Also used : SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig)

Example 7 with SplitBrainProtectionConfig

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);
}
Also used : SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Assert.assertNotNull(org.junit.Assert.assertNotNull) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) RunWith(org.junit.runner.RunWith) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) AtomicReference(java.util.concurrent.atomic.AtomicReference) SplitBrainProtectionListenerConfig(com.hazelcast.config.SplitBrainProtectionListenerConfig) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Assert.assertThat(org.junit.Assert.assertThat) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.assertEquals(org.junit.Assert.assertEquals) SplitBrainProtectionListenerConfig(com.hazelcast.config.SplitBrainProtectionListenerConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionListenerConfig(com.hazelcast.config.SplitBrainProtectionListenerConfig) 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 8 with SplitBrainProtectionConfig

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");
}
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) MapConfig(com.hazelcast.config.MapConfig) 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 9 with SplitBrainProtectionConfig

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");
}
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) MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) 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)

Example 10 with SplitBrainProtectionConfig

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);
}
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)

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