Search in sources :

Example 41 with QuorumConfig

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

the class QuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.

@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
    final CountDownLatch belowLatch = new CountDownLatch(2);
    Config config = new Config();
    QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
    listenerConfig.setImplementation(new QuorumListener() {

        public void onChange(QuorumEvent quorumEvent) {
            if (!quorumEvent.isPresent()) {
                Collection<Member> currentMembers = quorumEvent.getCurrentMembers();
                assertEquals(3, quorumEvent.getThreshold());
                assertTrue(currentMembers.size() < quorumEvent.getThreshold());
                belowLatch.countDown();
            }
        }
    });
    String mapName = randomMapName();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
    quorumConfig.addListenerConfig(listenerConfig);
    config.getMapConfig(mapName).setQuorumName(quorumName);
    config.addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    assertOpenEventually(belowLatch);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumEvent(com.hazelcast.quorum.QuorumEvent) Collection(java.util.Collection) QuorumListener(com.hazelcast.quorum.QuorumListener) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with QuorumConfig

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

the class QuorumListenerTest method testCustomResolverFiresQuorumFailureEvent.

@Test
public void testCustomResolverFiresQuorumFailureEvent() {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Config config = new Config();
    QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
    listenerConfig.setImplementation(new QuorumListener() {

        @Override
        public void onChange(QuorumEvent quorumEvent) {
            if (!quorumEvent.isPresent()) {
                countDownLatch.countDown();
            }
        }
    });
    String mapName = randomMapName();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig();
    quorumConfig.setName(quorumName);
    quorumConfig.setEnabled(true);
    quorumConfig.addListenerConfig(listenerConfig);
    quorumConfig.setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return false;
        }
    });
    config.getMapConfig(mapName).setQuorumName(quorumName);
    config.addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance();
    assertOpenEventually(countDownLatch, 15);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumEvent(com.hazelcast.quorum.QuorumEvent) QuorumListener(com.hazelcast.quorum.QuorumListener) CountDownLatch(java.util.concurrent.CountDownLatch) QuorumFunction(com.hazelcast.quorum.QuorumFunction) 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 43 with QuorumConfig

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

the class QuorumListenerTest method testQuorumEventsFiredWhenNodeCountBelowThenAboveThreshold.

@Test
public void testQuorumEventsFiredWhenNodeCountBelowThenAboveThreshold() {
    final CountDownLatch belowLatch = new CountDownLatch(1);
    final CountDownLatch aboveLatch = new CountDownLatch(1);
    Config config = new Config();
    QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
    listenerConfig.setImplementation(new QuorumListener() {

        public void onChange(QuorumEvent quorumEvent) {
            if (quorumEvent.isPresent()) {
                aboveLatch.countDown();
            } else {
                belowLatch.countDown();
            }
        }
    });
    String mapName = randomMapName();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
    quorumConfig.addListenerConfig(listenerConfig);
    config.getMapConfig(mapName).setQuorumName(quorumName);
    config.addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    assertOpenEventually(belowLatch, 15);
    factory.newHazelcastInstance(config);
    assertOpenEventually(aboveLatch);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumEvent(com.hazelcast.quorum.QuorumEvent) QuorumListener(com.hazelcast.quorum.QuorumListener) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with QuorumConfig

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

the class BaseQuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.

@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
    final CountDownLatch quorumNotPresent = new CountDownLatch(1);
    QuorumListenerConfig listenerConfig = new QuorumListenerConfig(new QuorumListener() {

        public void onChange(QuorumEvent quorumEvent) {
            if (!quorumEvent.isPresent()) {
                Collection<Member> currentMembers = quorumEvent.getCurrentMembers();
                assertEquals(3, quorumEvent.getThreshold());
                assertTrue(currentMembers.size() < quorumEvent.getThreshold());
                quorumNotPresent.countDown();
            }
        }
    });
    String distributedObjectName = randomString();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3).addListenerConfig(listenerConfig);
    Config config = new Config().addQuorumConfig(quorumConfig);
    addQuorumConfig(config, distributedObjectName, quorumName);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    assertOpenEventually(quorumNotPresent);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Collection(java.util.Collection) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with QuorumConfig

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

the class MapQuorumLiteMemberTest method createConfig.

private Config createConfig(String name, QuorumType type, int size, boolean liteMember) {
    QuorumConfig quorumConfig = new QuorumConfig().setName(name).setType(type).setEnabled(true).setSize(size);
    MapConfig mapConfig = new MapConfig(name);
    mapConfig.setQuorumName(name);
    Config config = new Config();
    config.addQuorumConfig(quorumConfig);
    config.addMapConfig(mapConfig);
    config.setLiteMember(liteMember);
    return config;
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) MapConfig(com.hazelcast.config.MapConfig)

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