Search in sources :

Example 26 with QuorumConfig

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

the class PartitionedCluster method createFiveMemberCluster.

public PartitionedCluster createFiveMemberCluster(CacheSimpleConfig cacheSimpleConfig, QuorumConfig quorumConfig) {
    Config config = createClusterConfig().addCacheConfig(cacheSimpleConfig).addQuorumConfig(quorumConfig);
    createInstances(config);
    return this;
}
Also used : Config(com.hazelcast.config.Config) QueueConfig(com.hazelcast.config.QueueConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) LockConfig(com.hazelcast.config.LockConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig)

Example 27 with QuorumConfig

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

the class PartitionedCluster method createFiveMemberCluster.

private PartitionedCluster createFiveMemberCluster(MapConfig mapConfig, QuorumConfig quorumConfig) {
    Config config = createClusterConfig().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
    createInstances(config);
    return this;
}
Also used : Config(com.hazelcast.config.Config) QueueConfig(com.hazelcast.config.QueueConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) LockConfig(com.hazelcast.config.LockConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig)

Example 28 with QuorumConfig

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

the class QuorumTest method oneQuorumShouldNotAffectQuorumAwareOperationsOnDataStructuresWithoutQuorumConfiguration.

/**
     * https://github.com/hazelcast/hazelcast/issues/9792
     */
@Test
public void oneQuorumShouldNotAffectQuorumAwareOperationsOnDataStructuresWithoutQuorumConfiguration() {
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig(quorumName, true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() == 3;
        }
    });
    MapConfig mapConfig = new MapConfig("quorumMap").setQuorumName(quorumName);
    Config config = new Config().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    IMap<Object, Object> quorumMap = hz.getMap("quorumMap");
    quorumMap.put(generateKeyOwnedBy(hz), "bar");
    ILock lock = hz.getLock("noQuorumLock");
    try {
        lock.lock();
    } finally {
        lock.unlock();
    }
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) ILock(com.hazelcast.core.ILock) Member(com.hazelcast.core.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with QuorumConfig

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

the class QuorumTest method testOneQuorumsFailsOneQuorumSuccessForDifferentMaps.

@Test
public void testOneQuorumsFailsOneQuorumSuccessForDifferentMaps() {
    String fourNodeQuorum = randomString();
    String threeNodeQuorum = randomString();
    MapConfig fourNodeMapConfig = new MapConfig("fourNode").setQuorumName(fourNodeQuorum);
    MapConfig threeNodeMapConfig = new MapConfig("threeNode").setQuorumName(threeNodeQuorum);
    QuorumConfig fourNodeQuorumConfig = new QuorumConfig(fourNodeQuorum, true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() == 4;
        }
    });
    QuorumConfig threeNodeQuorumConfig = new QuorumConfig(threeNodeQuorum, true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() == 3;
        }
    });
    Config config = new Config().addMapConfig(fourNodeMapConfig).addMapConfig(threeNodeMapConfig).addQuorumConfig(threeNodeQuorumConfig).addQuorumConfig(fourNodeQuorumConfig);
    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 : QuorumConfig(com.hazelcast.config.QuorumConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.core.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with QuorumConfig

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

the class QuorumTest method testCustomQuorumFunctionIsPresent.

@Test
public void testCustomQuorumFunctionIsPresent() {
    String mapName = randomMapName();
    String quorumName = randomString();
    MapConfig mapConfig = new MapConfig(mapName).setQuorumName(quorumName);
    QuorumConfig quorumConfig = new QuorumConfig().setName(quorumName).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return false;
        }
    });
    Config config = new Config().addQuorumConfig(quorumConfig).addMapConfig(mapConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    try {
        map.put("1", "1");
        fail();
    } catch (Exception ignored) {
    }
    Quorum quorum = hazelcastInstance.getQuorumService().getQuorum(quorumName);
    assertFalse(quorum.isPresent());
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

QuorumConfig (com.hazelcast.config.QuorumConfig)52 MapConfig (com.hazelcast.config.MapConfig)31 Config (com.hazelcast.config.Config)29 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)25 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Test (org.junit.Test)25 ParallelTest (com.hazelcast.test.annotation.ParallelTest)23 PartitionedCluster (com.hazelcast.quorum.PartitionedCluster)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)16 BeforeClass (org.junit.BeforeClass)16 QuorumListenerConfig (com.hazelcast.config.QuorumListenerConfig)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 QuorumEvent (com.hazelcast.quorum.QuorumEvent)11 QuorumListener (com.hazelcast.quorum.QuorumListener)11 Member (com.hazelcast.core.Member)10 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)7 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)5 LockConfig (com.hazelcast.config.LockConfig)5 QueueConfig (com.hazelcast.config.QueueConfig)5