Search in sources :

Example 31 with MapConfig

use of com.hazelcast.config.MapConfig 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 32 with MapConfig

use of com.hazelcast.config.MapConfig 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 33 with MapConfig

use of com.hazelcast.config.MapConfig 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)

Example 34 with MapConfig

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

the class MapLoaderTest method givenSpecificKeysWereReloaded_whenLoadAllIsCalled_thenAllEntriesAreLoadedFromTheStore.

@Test
public void givenSpecificKeysWereReloaded_whenLoadAllIsCalled_thenAllEntriesAreLoadedFromTheStore() {
    String name = randomString();
    int keysInMapStore = 10000;
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new DummyMapLoader(keysInMapStore));
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = instanceFactory.newInstances(config);
    IMap<Integer, Integer> map = instances[0].getMap(name);
    //load specific keys
    map.loadAll(setOfValuesBetween(0, keysInMapStore), true);
    //remove everything
    map.clear();
    //assert loadAll with load all entries provided by the mapLoader
    map.loadAll(true);
    assertEquals(keysInMapStore, map.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) 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 35 with MapConfig

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

the class MapStoreEvictionTest method newConfig.

private Config newConfig(String mapName, boolean sizeLimited, MapStoreConfig.InitialLoadMode loadMode) {
    Config cfg = new Config();
    cfg.setGroupConfig(new GroupConfig(getClass().getSimpleName()));
    cfg.setProperty("hazelcast.partition.count", "5");
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(loader).setInitialLoadMode(loadMode);
    MapConfig mapConfig = cfg.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    if (sizeLimited) {
        MaxSizeConfig maxSizeConfig = new MaxSizeConfig(MAX_SIZE_PER_NODE, MaxSizeConfig.MaxSizePolicy.PER_NODE);
        mapConfig.setMaxSizeConfig(maxSizeConfig);
        mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
        mapConfig.setMinEvictionCheckMillis(0);
    }
    return cfg;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) GroupConfig(com.hazelcast.config.GroupConfig) Config(com.hazelcast.config.Config) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) GroupConfig(com.hazelcast.config.GroupConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

MapConfig (com.hazelcast.config.MapConfig)182 Config (com.hazelcast.config.Config)125 HazelcastInstance (com.hazelcast.core.HazelcastInstance)78 Test (org.junit.Test)75 QuickTest (com.hazelcast.test.annotation.QuickTest)68 ParallelTest (com.hazelcast.test.annotation.ParallelTest)62 MapStoreConfig (com.hazelcast.config.MapStoreConfig)43 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)28 NearCacheConfig (com.hazelcast.config.NearCacheConfig)27 MapIndexConfig (com.hazelcast.config.MapIndexConfig)20 QuorumConfig (com.hazelcast.config.QuorumConfig)19 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)18 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 PartitionedCluster (com.hazelcast.quorum.PartitionedCluster)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 BeforeClass (org.junit.BeforeClass)10 AssertTask (com.hazelcast.test.AssertTask)9