Search in sources :

Example 26 with SplitBrainProtectionConfig

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

the class MapSplitBrainProtectionLiteMemberTest method createConfig.

private Config createConfig(String name, SplitBrainProtectionOn type, int size, boolean liteMember) {
    SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig().setName(name).setProtectOn(type).setEnabled(true).setMinimumClusterSize(size);
    MapConfig mapConfig = new MapConfig(name);
    mapConfig.setSplitBrainProtectionName(name);
    Config config = new Config();
    config.addSplitBrainProtectionConfig(splitBrainProtectionConfig);
    config.addMapConfig(mapConfig);
    config.setLiteMember(liteMember);
    return config;
}
Also used : SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig)

Example 27 with SplitBrainProtectionConfig

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

the class SplitBrainProtectionTest method givenRecentlyActiveSplitBrainProtection_whenHeartbeatTolerance_greaterThanMaxNoHeartbeat_exceptionIsThrown.

@Test(expected = InvalidConfigurationException.class)
public void givenRecentlyActiveSplitBrainProtection_whenHeartbeatTolerance_greaterThanMaxNoHeartbeat_exceptionIsThrown() {
    Config config = new Config();
    config.setProperty(ClusterProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "10");
    SplitBrainProtectionConfig recentlyActiveSplitBrainProtectionConfig = SplitBrainProtectionConfig.newRecentlyActiveSplitBrainProtectionConfigBuilder("test-splitBrainProtection", 3, 13000).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 28 with SplitBrainProtectionConfig

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

the class SplitBrainProtectionTest method testRecentlyActiveSplitBrainProtectionConsidersLocalMember.

@Test
public void testRecentlyActiveSplitBrainProtectionConsidersLocalMember() {
    final String splitBrainProtectionName = randomString();
    SplitBrainProtectionFunction splitBrainProtectionFunction = new RecentlyActiveSplitBrainProtectionFunction(1, 10000);
    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 : RecentlyActiveSplitBrainProtectionFunction(com.hazelcast.splitbrainprotection.impl.RecentlyActiveSplitBrainProtectionFunction) 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with SplitBrainProtectionConfig

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

the class SplitBrainProtectionTest method oneSplitBrainProtectionShouldNotAffectSplitBrainProtectionAwareOperationsOnDataStructuresWithoutSplitBrainProtectionConfiguration.

/**
 * https://github.com/hazelcast/hazelcast/issues/9792
 */
@Test
public void oneSplitBrainProtectionShouldNotAffectSplitBrainProtectionAwareOperationsOnDataStructuresWithoutSplitBrainProtectionConfiguration() {
    String splitBrainProtectionName = randomString();
    SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig(splitBrainProtectionName, true).setFunctionImplementation(new SplitBrainProtectionFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() == 3;
        }
    });
    MapConfig mapConfig = new MapConfig("splitBrainProtectionMap").setSplitBrainProtectionName(splitBrainProtectionName);
    Config config = new Config().addMapConfig(mapConfig).addSplitBrainProtectionConfig(splitBrainProtectionConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    IMap<Object, Object> splitBrainProtectionMap = hz.getMap("splitBrainProtectionMap");
    splitBrainProtectionMap.put(generateKeyOwnedBy(hz), "bar");
    IQueue queue = hz.getQueue("noSplitBrainProtectionQueue");
    queue.offer("item");
}
Also used : MapConfig(com.hazelcast.config.MapConfig) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) Config(com.hazelcast.config.Config) SplitBrainProtectionConfig(com.hazelcast.config.SplitBrainProtectionConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) 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)

Example 30 with SplitBrainProtectionConfig

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

the class SplitBrainProtectionTest method testSplitBrainProtectionNotChecked_whenIsNotEnabled.

@Test
public void testSplitBrainProtectionNotChecked_whenIsNotEnabled() {
    String disabledSBPName = "disabled-quorum";
    SplitBrainProtectionConfig disabledSBPConfig = new SplitBrainProtectionConfig().setName(disabledSBPName).setMinimumClusterSize(3);
    MapConfig mapConfig = new MapConfig(randomMapName()).setSplitBrainProtectionName(disabledSBPName);
    Config config = new Config().addSplitBrainProtectionConfig(disabledSBPConfig).addMapConfig(mapConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getSplitBrainProtectionService().ensureNoSplitBrain(disabledSBPName, disabledSBPConfig.getProtectOn());
    instance.getMap(mapConfig.getName()).put("key", "value");
}
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) 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