Search in sources :

Example 26 with MapStoreConfig

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

the class TestMapUsingMapStoreBuilder method build.

public IMap<K, V> build() {
    if (backupCount != 0 && backupCount > nodeCount - 1) {
        throw new IllegalArgumentException("backupCount > nodeCount - 1");
    }
    final MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(writeDelaySeconds).setWriteBatchSize(writeBatchSize).setWriteCoalescing(writeCoalescing);
    final Config config = new Config();
    config.getMapConfig(mapName).setBackupCount(backupCount).setMapStoreConfig(mapStoreConfig).setInMemoryFormat(inMemoryFormat);
    if (writeBehindQueueCapacity > 0) {
        config.setProperty(GroupProperty.MAP_WRITE_BEHIND_QUEUE_CAPACITY.getName(), String.valueOf(writeBehindQueueCapacity));
    }
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(partitionCount));
    if (backupDelaySeconds > 0) {
        config.setProperty(GroupProperty.MAP_REPLICA_SCHEDULED_TASK_DELAY_SECONDS.getName(), String.valueOf(backupDelaySeconds));
    }
    // nodes
    nodes = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        nodes[i] = instanceFactory.newHazelcastInstance(config);
    }
    return nodes[0].getMap(mapName);
}
Also used : Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig)

Example 27 with MapStoreConfig

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

the class WriteBehindFlushTest method testWriteBehindQueues_flushed_onNodeShutdown.

@Test
public void testWriteBehindQueues_flushed_onNodeShutdown() throws Exception {
    int nodeCount = 3;
    String mapName = randomName();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>();
    mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(3000);
    Config config = getConfig();
    config.getMapConfig(mapName).setBackupCount(0).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance member = factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = member.getMap(mapName);
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
    }
    factory.shutdownAll();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int i = 0; i < 1000; i++) {
                assertEquals(i, mapStore.store.get(i));
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with MapStoreConfig

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

the class WriteBehindFlushTest method testWriteBehindQueues_flushed_uponEviction.

@Test
public void testWriteBehindQueues_flushed_uponEviction() throws Exception {
    int nodeCount = 3;
    String mapName = randomName();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>();
    mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(3000);
    Config config = getConfig();
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = node1.getMap(mapName);
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
    }
    for (int i = 0; i < 1000; i++) {
        map.evict(i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1000, mapStore.countStore.get());
        }
    });
    assertWriteBehindQueuesEmpty(mapName, asList(node1, node2, node3));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with MapStoreConfig

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

the class MapStoreWriteBehindTest method testIssue1085WriteBehindBackupWithLongRunnigMapStore.

@Test(timeout = 120000)
public void testIssue1085WriteBehindBackupWithLongRunnigMapStore() throws InterruptedException {
    final String name = randomMapName("testIssue1085WriteBehindBackup");
    final int expectedStoreCount = 3;
    final int nodeCount = 3;
    Config config = getConfig();
    config.setProperty(GroupProperty.MAP_REPLICA_SCHEDULED_TASK_DELAY_SECONDS.getName(), "30");
    MapConfig writeBehindBackupConfig = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setWriteDelaySeconds(5);
    final MapStoreWithStoreCount mapStore = new MapStoreWithStoreCount(expectedStoreCount, 300, 50);
    mapStoreConfig.setImplementation(mapStore);
    writeBehindBackupConfig.setMapStoreConfig(mapStoreConfig);
    // create nodes.
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    // create corresponding keys.
    final String keyOwnedByNode1 = generateKeyOwnedBy(node1);
    final String keyOwnedByNode2 = generateKeyOwnedBy(node2);
    final String keyOwnedByNode3 = generateKeyOwnedBy(node3);
    // put one key value pair per node.
    final IMap<String, Integer> map = node1.getMap(name);
    map.put(keyOwnedByNode1, 1);
    map.put(keyOwnedByNode2, 2);
    map.put(keyOwnedByNode3, 3);
    // shutdown node2.
    node2.getLifecycleService().shutdown();
    // wait store ops. finish.
    mapStore.awaitStores();
    // we should see at least expected store count.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            int storeOperationCount = mapStore.count.intValue();
            assertTrue("expected : " + expectedStoreCount + ", actual : " + storeOperationCount, expectedStoreCount <= storeOperationCount);
        }
    });
}
Also used : MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreWithStoreCount(com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount) MapStoreConfig(com.hazelcast.config.MapStoreConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with MapStoreConfig

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

the class MapLoaderTest method testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime.

@Test(timeout = MINUTE)
public void testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime() throws InterruptedException {
    Config config = getConfig();
    MapLoader failingMapLoader = new FailingMapLoader();
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(failingMapLoader);
    MapConfig mapConfig = config.getMapConfig(getClass().getName()).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance[] hz = createHazelcastInstanceFactory(2).newInstances(config, 2);
    IMap map = hz[0].getMap(mapConfig.getName());
    Throwable exception = null;
    try {
        map.get(generateKeyNotOwnedBy(hz[0]));
    } catch (Throwable e) {
        exception = e;
    }
    assertNotNull("Exception wasn't propagated", exception);
    map.loadAll(true);
    assertEquals(1, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapLoader(com.hazelcast.core.MapLoader) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapStoreConfig (com.hazelcast.config.MapStoreConfig)76 Config (com.hazelcast.config.Config)70 MapConfig (com.hazelcast.config.MapConfig)61 HazelcastInstance (com.hazelcast.core.HazelcastInstance)51 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)43 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 GroupConfig (com.hazelcast.config.GroupConfig)21 IMap (com.hazelcast.core.IMap)12 AssertTask (com.hazelcast.test.AssertTask)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 MapIndexConfig (com.hazelcast.config.MapIndexConfig)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 NightlyTest (com.hazelcast.test.annotation.NightlyTest)8 HashSet (java.util.HashSet)8 NearCacheConfig (com.hazelcast.config.NearCacheConfig)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 MapStoreAdapter (com.hazelcast.core.MapStoreAdapter)5