Search in sources :

Example 51 with MapStoreConfig

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

the class TestFullApplicationContext method testMapConfig.

@Test
public void testMapConfig() {
    assertNotNull(config);
    assertEquals(26, config.getMapConfigs().size());
    MapConfig testMapConfig = config.getMapConfig("testMap");
    assertNotNull(testMapConfig);
    assertEquals("testMap", testMapConfig.getName());
    assertEquals(2, testMapConfig.getBackupCount());
    assertEquals(EvictionPolicy.NONE, testMapConfig.getEvictionPolicy());
    assertEquals(Integer.MAX_VALUE, testMapConfig.getMaxSizeConfig().getSize());
    assertEquals(30, testMapConfig.getEvictionPercentage());
    assertEquals(0, testMapConfig.getTimeToLiveSeconds());
    assertTrue(testMapConfig.getHotRestartConfig().isEnabled());
    assertTrue(testMapConfig.getHotRestartConfig().isFsync());
    assertEquals(1000, testMapConfig.getMinEvictionCheckMillis());
    assertEquals("PUT_IF_ABSENT", testMapConfig.getMergePolicy());
    assertTrue(testMapConfig.isReadBackupData());
    assertEquals(2, testMapConfig.getMapIndexConfigs().size());
    for (MapIndexConfig index : testMapConfig.getMapIndexConfigs()) {
        if ("name".equals(index.getAttribute())) {
            assertFalse(index.isOrdered());
        } else if ("age".equals(index.getAttribute())) {
            assertTrue(index.isOrdered());
        } else {
            fail("unknown index!");
        }
    }
    assertEquals(2, testMapConfig.getMapAttributeConfigs().size());
    for (MapAttributeConfig attribute : testMapConfig.getMapAttributeConfigs()) {
        if ("power".equals(attribute.getName())) {
            assertEquals("com.car.PowerExtractor", attribute.getExtractor());
        } else if ("weight".equals(attribute.getName())) {
            assertEquals("com.car.WeightExtractor", attribute.getExtractor());
        } else {
            fail("unknown attribute!");
        }
    }
    assertEquals("my-quorum", testMapConfig.getQuorumName());
    // test that the testMapConfig has a mapStoreConfig and it is correct
    MapStoreConfig testMapStoreConfig = testMapConfig.getMapStoreConfig();
    assertNotNull(testMapStoreConfig);
    assertEquals("com.hazelcast.spring.DummyStore", testMapStoreConfig.getClassName());
    assertTrue(testMapStoreConfig.isEnabled());
    assertEquals(0, testMapStoreConfig.getWriteDelaySeconds());
    assertEquals(10, testMapStoreConfig.getWriteBatchSize());
    assertTrue(testMapStoreConfig.isWriteCoalescing());
    assertEquals(MapStoreConfig.InitialLoadMode.EAGER, testMapStoreConfig.getInitialLoadMode());
    // test that the testMapConfig has a nearCacheConfig and it is correct
    NearCacheConfig testNearCacheConfig = testMapConfig.getNearCacheConfig();
    assertNotNull(testNearCacheConfig);
    assertEquals(0, testNearCacheConfig.getTimeToLiveSeconds());
    assertEquals(60, testNearCacheConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, testNearCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(5000, testNearCacheConfig.getEvictionConfig().getSize());
    assertTrue(testNearCacheConfig.isInvalidateOnChange());
    // test that the testMapConfig2's mapStoreConfig implementation
    MapConfig testMapConfig2 = config.getMapConfig("testMap2");
    assertNotNull(testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(dummyMapStore, testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(MapStoreConfig.InitialLoadMode.LAZY, testMapConfig2.getMapStoreConfig().getInitialLoadMode());
    // test testMapConfig2's WanReplicationConfig
    WanReplicationRef wanReplicationRef = testMapConfig2.getWanReplicationRef();
    assertEquals("testWan", wanReplicationRef.getName());
    assertEquals("PUT_IF_ABSENT", wanReplicationRef.getMergePolicy());
    assertTrue(wanReplicationRef.isRepublishingEnabled());
    assertEquals(1000, testMapConfig2.getMaxSizeConfig().getSize());
    assertEquals(MaxSizeConfig.MaxSizePolicy.PER_NODE, testMapConfig2.getMaxSizeConfig().getMaxSizePolicy());
    assertEquals(2, testMapConfig2.getEntryListenerConfigs().size());
    for (EntryListenerConfig listener : testMapConfig2.getEntryListenerConfigs()) {
        if (listener.getClassName() != null) {
            assertNull(listener.getImplementation());
            assertTrue(listener.isIncludeValue());
            assertFalse(listener.isLocal());
        } else {
            assertNotNull(listener.getImplementation());
            assertEquals(entryListener, listener.getImplementation());
            assertTrue(listener.isLocal());
            assertTrue(listener.isIncludeValue());
        }
    }
    MapConfig simpleMapConfig = config.getMapConfig("simpleMap");
    assertNotNull(simpleMapConfig);
    assertEquals("simpleMap", simpleMapConfig.getName());
    assertEquals(3, simpleMapConfig.getBackupCount());
    assertEquals(1, simpleMapConfig.getAsyncBackupCount());
    assertEquals(EvictionPolicy.LRU, simpleMapConfig.getEvictionPolicy());
    assertEquals(10, simpleMapConfig.getMaxSizeConfig().getSize());
    assertEquals(50, simpleMapConfig.getEvictionPercentage());
    assertEquals(1, simpleMapConfig.getTimeToLiveSeconds());
    assertEquals("LATEST_UPDATE", simpleMapConfig.getMergePolicy());
    // test that the simpleMapConfig does NOT have a nearCacheConfig
    assertNull(simpleMapConfig.getNearCacheConfig());
    MapConfig testMapConfig3 = config.getMapConfig("testMap3");
    assertEquals("com.hazelcast.spring.DummyStoreFactory", testMapConfig3.getMapStoreConfig().getFactoryClassName());
    assertFalse(testMapConfig3.getMapStoreConfig().getProperties().isEmpty());
    assertEquals(testMapConfig3.getMapStoreConfig().getProperty("dummy.property"), "value");
    MapConfig testMapConfig4 = config.getMapConfig("testMap4");
    assertEquals(dummyMapStoreFactory, testMapConfig4.getMapStoreConfig().getFactoryImplementation());
    MapConfig mapWithOptimizedQueriesConfig = config.getMapConfig("mapWithOptimizedQueries");
    assertEquals(CacheDeserializedValues.ALWAYS, mapWithOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig mapWithValueCachingSetToNever = config.getMapConfig("mapWithValueCachingSetToNever");
    assertEquals(CacheDeserializedValues.NEVER, mapWithValueCachingSetToNever.getCacheDeserializedValues());
    MapConfig mapWithValueCachingSetToAlways = config.getMapConfig("mapWithValueCachingSetToAlways");
    assertEquals(CacheDeserializedValues.ALWAYS, mapWithValueCachingSetToAlways.getCacheDeserializedValues());
    MapConfig mapWithNotOptimizedQueriesConfig = config.getMapConfig("mapWithNotOptimizedQueries");
    assertEquals(CacheDeserializedValues.INDEX_ONLY, mapWithNotOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig mapWithDefaultOptimizedQueriesConfig = config.getMapConfig("mapWithDefaultOptimizedQueries");
    assertEquals(CacheDeserializedValues.INDEX_ONLY, mapWithDefaultOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig testMapWithPartitionLostListenerConfig = config.getMapConfig("mapWithPartitionLostListener");
    List<MapPartitionLostListenerConfig> partitionLostListenerConfigs = testMapWithPartitionLostListenerConfig.getPartitionLostListenerConfigs();
    assertEquals(1, partitionLostListenerConfigs.size());
    assertEquals("DummyMapPartitionLostListenerImpl", partitionLostListenerConfigs.get(0).getClassName());
    MapConfig testMapWithPartitionStrategyConfig = config.getMapConfig("mapWithPartitionStrategy");
    assertEquals("com.hazelcast.spring.DummyPartitionStrategy", testMapWithPartitionStrategyConfig.getPartitioningStrategyConfig().getPartitioningStrategyClass());
}
Also used : MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) WanReplicationRef(com.hazelcast.config.WanReplicationRef) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 52 with MapStoreConfig

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

the class ClientMapStoreTest method destroyMap_configuredWithMapStore.

@Test
public void destroyMap_configuredWithMapStore() {
    Config config = new Config();
    MapConfig mapConfig = new MapConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    MapStoreBackup store = new MapStoreBackup();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(store);
    mapStoreConfig.setWriteDelaySeconds(4);
    mapConfig.setName(MAP_NAME);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    config.addMapConfig(mapConfig);
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(MAP_NAME);
    for (int i = 0; i < 1; i++) {
        map.putAsync(i, i);
    }
    map.destroy();
}
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) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 53 with MapStoreConfig

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

the class ClientMapStoreTest method mapSize_After_MapStore_OperationQueue_OverFlow.

@Test
public void mapSize_After_MapStore_OperationQueue_OverFlow() throws Exception {
    int maxCapacity = 1000;
    Config config = new Config();
    config.setProperty(GroupProperty.MAP_WRITE_BEHIND_QUEUE_CAPACITY.getName(), String.valueOf(maxCapacity));
    MapConfig mapConfig = new MapConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    MapStoreBackup store = new MapStoreBackup();
    int delaySeconds = Integer.MAX_VALUE;
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(store);
    mapStoreConfig.setWriteDelaySeconds(delaySeconds);
    mapStoreConfig.setWriteCoalescing(false);
    mapConfig.setName(MAP_NAME);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    config.addMapConfig(mapConfig);
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(MAP_NAME);
    int overflow = 100;
    List<Future> futures = new ArrayList<Future>(maxCapacity + overflow);
    for (int i = 0; i < maxCapacity + overflow; i++) {
        Future future = map.putAsync(i, i);
        futures.add(future);
    }
    int success = 0;
    for (Future future : futures) {
        try {
            future.get();
            success++;
        } catch (ExecutionException e) {
            assertInstanceOf(ReachedMaxSizeException.class, e.getCause());
        }
    }
    assertEquals(success, maxCapacity);
    assertEquals(map.size(), maxCapacity);
}
Also used : MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ReachedMaxSizeException(com.hazelcast.map.ReachedMaxSizeException) ArrayList(java.util.ArrayList) MapStoreConfig(com.hazelcast.config.MapStoreConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) MapConfig(com.hazelcast.config.MapConfig) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 54 with MapStoreConfig

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

the class ClientMapStoreTest method testIssue3023_testWithSubStringMapNames.

@Test
public void testIssue3023_testWithSubStringMapNames() throws Exception {
    String mapNameWithStore = "MapStore*";
    String mapNameWithStoreAndSize = "MapStoreMaxSize*";
    String xml = "<hazelcast xsi:schemaLocation=\"http://www.hazelcast.com/schema/config\n" + "                             http://www.hazelcast.com/schema/config/hazelcast-config-3.9.xsd\"\n" + "                             xmlns=\"http://www.hazelcast.com/schema/config\"\n" + "                             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "\n" + "    <map name=\"" + mapNameWithStore + "\">\n" + "        <map-store enabled=\"true\">\n" + "            <class-name>com.will.cause.problem.if.used</class-name>\n" + "            <write-delay-seconds>5</write-delay-seconds>\n" + "        </map-store>\n" + "    </map>\n" + "\n" + "    <map name=\"" + mapNameWithStoreAndSize + "\">\n" + "        <in-memory-format>BINARY</in-memory-format>\n" + "        <backup-count>1</backup-count>\n" + "        <async-backup-count>0</async-backup-count>\n" + "        <max-idle-seconds>0</max-idle-seconds>\n" + "        <eviction-policy>LRU</eviction-policy>\n" + "        <max-size policy=\"PER_NODE\">10</max-size>\n" + "        <eviction-percentage>50</eviction-percentage>\n" + "\n" + "        <merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>\n" + "\n" + "        <map-store enabled=\"true\">\n" + "            <class-name>com.hazelcast.client.map.helpers.AMapStore</class-name>\n" + "            <write-delay-seconds>5</write-delay-seconds>\n" + "        </map-store>\n" + "    </map>\n" + "\n" + "</hazelcast>";
    Config config = buildConfig(xml);
    HazelcastInstance hz = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(mapNameWithStoreAndSize + "1");
    map.put(1, 1);
    MapStoreConfig mapStoreConfig = hz.getConfig().getMapConfig(mapNameWithStoreAndSize + "1").getMapStoreConfig();
    final AMapStore store = (AMapStore) (mapStoreConfig.getImplementation());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, store.store.get(1));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AMapStore(com.hazelcast.client.map.helpers.AMapStore) ReachedMaxSizeException(com.hazelcast.map.ReachedMaxSizeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 55 with MapStoreConfig

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

the class MapStoreTest method testEntryProcessor_calls_load_only_one_time_per_key.

@Test
public void testEntryProcessor_calls_load_only_one_time_per_key() throws Exception {
    Config config = getConfig();
    // configure map with one backup and dummy map store
    MapConfig mapConfig = config.getMapConfig("default");
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    MapStoreWithCounter mapStore = new MapStoreWithCounter();
    mapStoreConfig.setImplementation(mapStore);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    HazelcastInstance member = createHazelcastInstance(config);
    IMap<Integer, Integer> map = member.getMap("default");
    map.executeOnKey(1, new AbstractEntryProcessor<Integer, Integer>(false) {

        @Override
        public Object process(Map.Entry<Integer, Integer> entry) {
            entry.setValue(2);
            return null;
        }
    });
    assertEquals(1, mapStore.getLoadCount());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreWithCounter(com.hazelcast.map.impl.mapstore.writebehind.MapStoreWithCounter) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) IMap(com.hazelcast.core.IMap) 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