Search in sources :

Example 1 with MapLoader

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

the class MapLoaderTest method testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime.

@Test(timeout = MINUTE)
public void testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime() {
    Config config = getConfig();
    MapLoader failingMapLoader = new FailingMapLoader();
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(failingMapLoader);
    MapConfig mapConfig = config.getMapConfig(getClass().getName()).setMapStoreConfig(mapStoreConfig);
    final ILogger logger = Logger.getLogger(LoggingLifecycleListener.class);
    HazelcastInstance[] hz = createHazelcastInstanceFactory(2).newInstances(config, 2);
    final 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);
    // In the first map load, partitions are notified asynchronously
    // by the com.hazelcast.map.impl.MapKeyLoader.sendKeyLoadCompleted
    // method and also some partitions are notified twice.
    // Because of this, a subsequent map load might get completed with the
    // results of the first map load.
    // This is why a subsequent map load might fail with the exception from
    // a previous load. In this case, we need to try again.
    // An alternative would be to wait for all partitions to be notified by
    // the result from the first load before initiating a second load but
    // unfortunately we can't observe this as some partitions are completed
    // twice and we might just end up observing the first completion.
    assertTrueEventually(() -> {
        try {
            map.loadAll(true);
            assertEquals(1, map.size());
        } catch (IllegalStateException e) {
            logger.info("Map load observed result from a previous load, retrying...", e);
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapLoader(com.hazelcast.map.MapLoader) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) ILogger(com.hazelcast.logging.ILogger) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Config (com.hazelcast.config.Config)1 IndexConfig (com.hazelcast.config.IndexConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ILogger (com.hazelcast.logging.ILogger)1 IMap (com.hazelcast.map.IMap)1 MapLoader (com.hazelcast.map.MapLoader)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1