Search in sources :

Example 1 with MapLoader

use of com.hazelcast.core.MapLoader 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 2 with MapLoader

use of com.hazelcast.core.MapLoader in project hazelcast by hazelcast.

the class MapLoaderTest method test1770.

// https://github.com/hazelcast/hazelcast/issues/1770
@Test
public void test1770() throws InterruptedException {
    Config config = getConfig();
    config.getManagementCenterConfig().setEnabled(true);
    config.getManagementCenterConfig().setUrl("http://127.0.0.1:8090/mancenter");
    MapConfig mapConfig = config.getMapConfig("foo");
    final AtomicBoolean loadAllCalled = new AtomicBoolean();
    MapLoader<Object, Object> mapLoader = new MapLoader<Object, Object>() {

        @Override
        public Object load(Object key) {
            return null;
        }

        @Override
        public Map<Object, Object> loadAll(Collection keys) {
            loadAllCalled.set(true);
            return new HashMap<Object, Object>();
        }

        @Override
        public Set<Object> loadAllKeys() {
            return new HashSet<Object>(Collections.singletonList(1));
        }
    };
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(mapLoader);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    HazelcastInstance hz = createHazelcastInstance(config);
    hz.getMap(mapConfig.getName());
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() {
            assertFalse("LoadAll should not have been called", loadAllCalled.get());
        }
    }, 10);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapLoader(com.hazelcast.core.MapLoader) Collection(java.util.Collection) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MapLoader (com.hazelcast.core.MapLoader)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 IMap (com.hazelcast.core.IMap)1 AssertTask (com.hazelcast.test.AssertTask)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1