Search in sources :

Example 11 with QuorumConfig

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

the class PartitionedCluster method createSuccessfulSplitTestQuorum.

private QuorumConfig createSuccessfulSplitTestQuorum() {
    QuorumConfig splitConfig = new QuorumConfig();
    splitConfig.setEnabled(true);
    splitConfig.setSize(3);
    splitConfig.setName(SUCCESSFUL_SPLIT_TEST_QUORUM_NAME);
    return splitConfig;
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig)

Example 12 with QuorumConfig

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

the class PartitionedCluster method createFiveMemberCluster.

public PartitionedCluster createFiveMemberCluster(LockConfig lockConfig, QuorumConfig quorumConfig) {
    Config config = createClusterConfig().addLockConfig(lockConfig).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 13 with QuorumConfig

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

the class QuorumTest method givenQuorumFunctionConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance.

@Test
public void givenQuorumFunctionConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance() {
    QuorumConfig quorumConfig = new QuorumConfig(randomString(), true).setQuorumFunctionClassName(HazelcastInstanceAwareQuorumFunction.class.getName());
    Config config = new Config().addQuorumConfig(quorumConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    assertEquals(instance, HazelcastInstanceAwareQuorumFunction.instance);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with QuorumConfig

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

the class QuorumTest method givenQuorumFunctionInstanceConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance.

@Test
public void givenQuorumFunctionInstanceConfigured_whenImplementsHazelcastInstanceAware_thenHazelcastInjectsItsInstance() {
    QuorumConfig quorumConfig = new QuorumConfig(randomString(), true).setQuorumFunctionImplementation(new HazelcastInstanceAwareQuorumFunction());
    Config config = new Config().addQuorumConfig(quorumConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    assertEquals(instance, HazelcastInstanceAwareQuorumFunction.instance);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with QuorumConfig

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

the class QuorumTest method testCustomQuorumFunctionFailsThenSuccess.

@Test
public void testCustomQuorumFunctionFailsThenSuccess() {
    final AtomicInteger count = new AtomicInteger(1);
    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) {
            if (count.get() == 1) {
                count.incrementAndGet();
                return false;
            } else {
                return true;
            }
        }
    });
    Config config = new Config().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    try {
        map.put("1", "1");
        fail();
    } catch (Exception e) {
        e.printStackTrace();
    }
    factory.newHazelcastInstance(config);
    map.put("1", "1");
    factory.shutdownAll();
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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)

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