Search in sources :

Example 1 with QuorumFunction

use of com.hazelcast.quorum.QuorumFunction 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 2 with QuorumFunction

use of com.hazelcast.quorum.QuorumFunction 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)

Aggregations

Config (com.hazelcast.config.Config)2 QuorumConfig (com.hazelcast.config.QuorumConfig)2 QuorumListenerConfig (com.hazelcast.config.QuorumListenerConfig)2 Member (com.hazelcast.core.Member)2 QuorumEvent (com.hazelcast.quorum.QuorumEvent)2 QuorumFunction (com.hazelcast.quorum.QuorumFunction)2 QuorumListener (com.hazelcast.quorum.QuorumListener)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 QuorumException (com.hazelcast.quorum.QuorumException)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1