Search in sources :

Example 31 with QuorumConfig

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

the class QuorumTest method testQuorumIsSetCorrectlyOnNodeInitialization.

@Test
public void testQuorumIsSetCorrectlyOnNodeInitialization() {
    String quorumName1 = randomString();
    String quorumName2 = randomString();
    QuorumConfig quorumConfig1 = new QuorumConfig().setName(quorumName1).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return true;
        }
    });
    QuorumConfig quorumConfig2 = new QuorumConfig().setName(quorumName2).setEnabled(true).setSize(2);
    Config config = new Config().addQuorumConfig(quorumConfig1).addQuorumConfig(quorumConfig2);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    final Quorum quorum1 = hazelcastInstance.getQuorumService().getQuorum(quorumName1);
    final Quorum quorum2 = hazelcastInstance.getQuorumService().getQuorum(quorumName2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(quorum1.isPresent());
            assertFalse(quorum2.isPresent());
        }
    });
}
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) AssertTask(com.hazelcast.test.AssertTask) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 32 with QuorumConfig

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

the class QuorumTest method testQuorumIgnoresMemberAttributeEvents.

@Test
public void testQuorumIgnoresMemberAttributeEvents() {
    final RecordingQuorumFunction function = new RecordingQuorumFunction();
    QuorumConfig quorumConfig = new QuorumConfig().setName(randomString()).setEnabled(true).setQuorumFunctionImplementation(function);
    Config config = new Config().addQuorumConfig(quorumConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hazelcastInstance);
    MembershipAwareService service = nodeEngine.getService(QuorumServiceImpl.SERVICE_NAME);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(function.wasCalled);
        }
    });
    function.wasCalled = false;
    MemberAttributeServiceEvent event = mock(MemberAttributeServiceEvent.class);
    service.memberAttributeChanged(event);
    assertFalse(function.wasCalled);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) MembershipAwareService(com.hazelcast.spi.MembershipAwareService) AssertTask(com.hazelcast.test.AssertTask) MemberAttributeServiceEvent(com.hazelcast.spi.MemberAttributeServiceEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with QuorumConfig

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

the class QuorumTest method testCustomQuorumFunctionFailsForAllNodes.

@Test(expected = QuorumException.class)
public void testCustomQuorumFunctionFailsForAllNodes() {
    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().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    factory.newHazelcastInstance(config);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    IMap<Object, Object> map2 = hz.getMap(mapName);
    map2.put("1", "1");
}
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) 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 34 with QuorumConfig

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

the class CacheQuorumListenerTest 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 cacheName = randomString();
    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.getCacheConfig(cacheName).setQuorumName(quorumName);
    config.addQuorumConfig(quorumConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance);
    Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache(cacheName);
    try {
        cache.put(generateKeyOwnedBy(instance), 1);
        fail("Expected a QuorumException");
    } catch (QuorumException expected) {
        EmptyStatement.ignore(expected);
    }
    assertOpenEventually(countDownLatch, 15);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) QuorumEvent(com.hazelcast.quorum.QuorumEvent) QuorumListener(com.hazelcast.quorum.QuorumListener) CountDownLatch(java.util.concurrent.CountDownLatch) QuorumException(com.hazelcast.quorum.QuorumException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuorumFunction(com.hazelcast.quorum.QuorumFunction) Member(com.hazelcast.core.Member) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with QuorumConfig

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

the class CacheQuorumListenerTest 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 cacheName = randomString();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
    quorumConfig.addListenerConfig(listenerConfig);
    config.getCacheConfig(cacheName).setQuorumName(quorumName);
    config.addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(instance1);
    Cache<Object, Object> cache = cachingProvider1.getCacheManager().getCache(cacheName);
    try {
        cache.put(generateKeyOwnedBy(instance1), 1);
        fail("Expected a QuorumException");
    } catch (QuorumException expected) {
        EmptyStatement.ignore(expected);
    }
    assertOpenEventually(belowLatch, 15);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    cache.put(generateKeyOwnedBy(instance1), 1);
    assertOpenEventually(aboveLatch, 15);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) QuorumEvent(com.hazelcast.quorum.QuorumEvent) QuorumListener(com.hazelcast.quorum.QuorumListener) CountDownLatch(java.util.concurrent.CountDownLatch) QuorumException(com.hazelcast.quorum.QuorumException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) 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