Search in sources :

Example 6 with QuorumConfig

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

the class TransactionalMapWriteQuorumTest method initialize.

@BeforeClass
public static void initialize() throws Exception {
    QuorumConfig quorumConfig = new QuorumConfig();
    quorumConfig.setEnabled(true);
    quorumConfig.setSize(3);
    quorumConfig.setName(QUORUM_ID);
    quorumConfig.setType(QuorumType.WRITE);
    MapConfig mapConfig = new MapConfig(MAP_NAME_PREFIX + "*");
    mapConfig.setQuorumName(QUORUM_ID);
    cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(mapConfig, quorumConfig);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) PartitionedCluster(com.hazelcast.quorum.PartitionedCluster) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) BeforeClass(org.junit.BeforeClass)

Example 7 with QuorumConfig

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

the class TransactionalMapReadWriteQuorumTest method initialize.

@BeforeClass
public static void initialize() throws Exception {
    QuorumConfig quorumConfig = new QuorumConfig();
    quorumConfig.setEnabled(true);
    quorumConfig.setSize(3);
    quorumConfig.setName(QUORUM_ID);
    quorumConfig.setType(QuorumType.READ_WRITE);
    MapConfig mapConfig = new MapConfig(MAP_NAME_PREFIX + "*");
    mapConfig.setQuorumName(QUORUM_ID);
    cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(mapConfig, quorumConfig);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) PartitionedCluster(com.hazelcast.quorum.PartitionedCluster) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) BeforeClass(org.junit.BeforeClass)

Example 8 with QuorumConfig

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

the class CacheQuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.

@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
    final CountDownLatch belowLatch = new CountDownLatch(1);
    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 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);
    factory.newHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance1);
    Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache(cacheName);
    try {
        cache.put(generateKeyOwnedBy(instance1), 1);
        fail("Expected a QuorumException");
    } catch (QuorumException expected) {
        EmptyStatement.ignore(expected);
    }
    assertOpenEventually(belowLatch, 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) Collection(java.util.Collection) 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)

Example 9 with QuorumConfig

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

the class CacheReadQuorumTest method initialize.

@BeforeClass
public static void initialize() throws Exception {
    CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
    cacheConfig.setName(CACHE_NAME_PREFIX + "*");
    cacheConfig.setQuorumName(QUORUM_ID);
    QuorumConfig quorumConfig = new QuorumConfig();
    quorumConfig.setName(QUORUM_ID);
    quorumConfig.setType(QuorumType.READ);
    quorumConfig.setEnabled(true);
    quorumConfig.setSize(3);
    PartitionedCluster cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(cacheConfig, quorumConfig);
    cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(cluster.h1);
    cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(cluster.h2);
    cachingProvider3 = HazelcastServerCachingProvider.createCachingProvider(cluster.h3);
    cachingProvider4 = HazelcastServerCachingProvider.createCachingProvider(cluster.h4);
    cachingProvider5 = HazelcastServerCachingProvider.createCachingProvider(cluster.h5);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) PartitionedCluster(com.hazelcast.quorum.PartitionedCluster) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) BeforeClass(org.junit.BeforeClass)

Example 10 with QuorumConfig

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

the class CacheReadWriteQuorumTest method initialize.

@BeforeClass
public static void initialize() throws Exception {
    CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
    cacheConfig.setName(CACHE_NAME_PREFIX + "*");
    cacheConfig.setQuorumName(QUORUM_ID);
    QuorumConfig quorumConfig = new QuorumConfig();
    quorumConfig.setName(QUORUM_ID);
    quorumConfig.setType(QuorumType.READ_WRITE);
    quorumConfig.setEnabled(true);
    quorumConfig.setSize(3);
    PartitionedCluster cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(cacheConfig, quorumConfig);
    cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(cluster.h1);
    cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(cluster.h2);
    cachingProvider3 = HazelcastServerCachingProvider.createCachingProvider(cluster.h3);
    cachingProvider4 = HazelcastServerCachingProvider.createCachingProvider(cluster.h4);
    cachingProvider5 = HazelcastServerCachingProvider.createCachingProvider(cluster.h5);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) PartitionedCluster(com.hazelcast.quorum.PartitionedCluster) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) BeforeClass(org.junit.BeforeClass)

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