Search in sources :

Example 16 with MapStoreConfig

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

the class MapStoreTest method testMapstoreDeleteOnClear.

/*
     * Test for Issue 572
    */
@Test(timeout = 120000)
public void testMapstoreDeleteOnClear() throws Exception {
    Config config = getConfig();
    SimpleMapStore store = new SimpleMapStore();
    config.getMapConfig("testMapstoreDeleteOnClear").setMapStoreConfig(new MapStoreConfig().setEnabled(true).setImplementation(store));
    HazelcastInstance hz = createHazelcastInstance(config);
    IMap<Object, Object> map = hz.getMap("testMapstoreDeleteOnClear");
    int size = 10;
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    assertEquals(size, map.size());
    assertEquals(size, store.store.size());
    assertEquals(size, store.loadAllKeys().size());
    map.clear();
    assertEquals(0, map.size());
    assertEquals(0, store.loadAllKeys().size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with MapStoreConfig

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

the class PostProcessingMapStoreTest method createInstanceAndGetMap.

private IMap<Integer, SampleObject> createInstanceAndGetMap() {
    String name = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true).setClassName(IncrementerPostProcessingMapStore.class.getName());
    mapConfig.setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    warmUpPartitions(instance);
    return instance.getMap(name);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig)

Example 18 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 19 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 20 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)

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