Search in sources :

Example 16 with SplitBrainProtectionConfig

use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.

the class SplitBrainProtectionTest method givenRecentlyActiveSplitBrainProtection_whenHeartbeatTolerance_lessThanHeartbeatInterval_exceptionIsThrown.

@Test(expected = InvalidConfigurationException.class)
public void givenRecentlyActiveSplitBrainProtection_whenHeartbeatTolerance_lessThanHeartbeatInterval_exceptionIsThrown() {
    Config config = new Config();
    config.setProperty(ClusterProperty.HEARTBEAT_INTERVAL_SECONDS.getName(), "5");
    SplitBrainProtectionConfig recentlyActiveSplitBrainProtectionConfig = SplitBrainProtectionConfig.newRecentlyActiveSplitBrainProtectionConfigBuilder("test-splitBrainProtection", 3, 3000).build();
    config.addSplitBrainProtectionConfig(recentlyActiveSplitBrainProtectionConfig);
    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 17 with SplitBrainProtectionConfig

use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.

the class SplitBrainProtectionTest method testProbabilisticSplitBrainProtectionConsidersLocalMember.

@Test
public void testProbabilisticSplitBrainProtectionConsidersLocalMember() {
    String splitBrainProtectionName = randomString();
    SplitBrainProtectionFunction splitBrainProtectionFunction = new ProbabilisticSplitBrainProtectionFunction(1, 100, 1250, 20, 100, 20);
    SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(splitBrainProtectionName).setEnabled(true).setFunctionImplementation(splitBrainProtectionFunction);
    Config config = new Config().addSplitBrainProtectionConfig(splitBrainProtectionConfig).setProperty(ClusterProperty.HEARTBEAT_INTERVAL_SECONDS.getName(), "1");
    HazelcastInstance instance = createHazelcastInstance(config);
    final SplitBrainProtection splitBrainProtection = instance.getSplitBrainProtectionService().getSplitBrainProtection(splitBrainProtectionName);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(splitBrainProtection.hasMinimumSize());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with SplitBrainProtectionConfig

use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.

the class SplitBrainProtectionTest method givenSplitBrainProtectionFunctionConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance.

@Test
public void givenSplitBrainProtectionFunctionConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance() {
    SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig(randomString(), true).setFunctionClassName(HazelcastInstanceAwareSplitBrainProtectionFunction.class.getName());
    Config config = new Config().addSplitBrainProtectionConfig(splitBrainProtectionConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    assertEquals(instance, HazelcastInstanceAwareSplitBrainProtectionFunction.instance);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 19 with SplitBrainProtectionConfig

use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.

the class SplitBrainProtectionServiceImpl method initializeSplitBrainProtections.

private Map<String, SplitBrainProtectionImpl> initializeSplitBrainProtections() {
    Map<String, SplitBrainProtectionImpl> splitBrainProtections = new HashMap<>();
    for (SplitBrainProtectionConfig splitBrainProtectionConfig : nodeEngine.getConfig().getSplitBrainProtectionConfigs().values()) {
        validateSplitBrainProtectionConfig(splitBrainProtectionConfig);
        if (!splitBrainProtectionConfig.isEnabled()) {
            continue;
        }
        SplitBrainProtectionImpl splitBrainProtection = new SplitBrainProtectionImpl(splitBrainProtectionConfig, nodeEngine);
        splitBrainProtections.put(splitBrainProtectionConfig.getName(), splitBrainProtection);
    }
    return splitBrainProtections;
}
Also used : HashMap(java.util.HashMap) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig)

Example 20 with SplitBrainProtectionConfig

use of com.hazelcast.config.SplitBrainProtectionConfig in project hazelcast by hazelcast.

the class TestFullApplicationContext method testProbabilisticSplitBrainProtectionConfig.

@Test
public void testProbabilisticSplitBrainProtectionConfig() {
    SplitBrainProtectionConfig probabilisticSplitBrainProtectionConfig = config.getSplitBrainProtectionConfig("probabilistic-split-brain-protection");
    assertNotNull(probabilisticSplitBrainProtectionConfig);
    assertEquals("probabilistic-split-brain-protection", probabilisticSplitBrainProtectionConfig.getName());
    assertNotNull(probabilisticSplitBrainProtectionConfig.getFunctionImplementation());
    assertInstanceOf(ProbabilisticSplitBrainProtectionFunction.class, probabilisticSplitBrainProtectionConfig.getFunctionImplementation());
    assertTrue(probabilisticSplitBrainProtectionConfig.isEnabled());
    assertEquals(3, probabilisticSplitBrainProtectionConfig.getMinimumClusterSize());
    assertEquals(2, probabilisticSplitBrainProtectionConfig.getListenerConfigs().size());
    assertEquals(SplitBrainProtectionOn.READ_WRITE, probabilisticSplitBrainProtectionConfig.getProtectOn());
    assertEquals("com.hazelcast.spring.DummySplitBrainProtectionListener", probabilisticSplitBrainProtectionConfig.getListenerConfigs().get(0).getClassName());
    assertNotNull(probabilisticSplitBrainProtectionConfig.getListenerConfigs().get(1).getImplementation());
    ProbabilisticSplitBrainProtectionFunction splitBrainProtectionFunction = (ProbabilisticSplitBrainProtectionFunction) probabilisticSplitBrainProtectionConfig.getFunctionImplementation();
    assertEquals(11, splitBrainProtectionFunction.getSuspicionThreshold(), 0.001d);
    assertEquals(31415, splitBrainProtectionFunction.getAcceptableHeartbeatPauseMillis());
    assertEquals(42, splitBrainProtectionFunction.getMaxSampleSize());
    assertEquals(77123, splitBrainProtectionFunction.getHeartbeatIntervalMillis());
    assertEquals(1000, splitBrainProtectionFunction.getMinStdDeviationMillis());
}
Also used : ProbabilisticSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.ProbabilisticSplitBrainProtectionFunction) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

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