Search in sources :

Example 61 with IMap

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

the class MapStoreTest method issue614.

@Test(timeout = 120000)
public void issue614() {
    final ConcurrentMap<Long, String> STORE = new ConcurrentHashMap<>();
    STORE.put(1L, "Event1");
    STORE.put(2L, "Event2");
    STORE.put(3L, "Event3");
    STORE.put(4L, "Event4");
    STORE.put(5L, "Event5");
    STORE.put(6L, "Event6");
    Config config = getConfig();
    config.getMapConfig("map").setMapStoreConfig(new MapStoreConfig().setWriteDelaySeconds(1).setImplementation(new SimpleMapStore<>(STORE)));
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap map = instance.getMap("map");
    map.values();
    LocalMapStats localMapStats = map.getLocalMapStats();
    assertEquals(0, localMapStats.getDirtyEntryCount());
}
Also used : LocalMapStats(com.hazelcast.map.LocalMapStats) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AtomicLong(java.util.concurrent.atomic.AtomicLong) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with IMap

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

the class MapStoreTest method testInitialLoadModeEagerWhileStoppigOneNode.

@Test(timeout = 120000)
public void testInitialLoadModeEagerWhileStoppigOneNode() {
    final int instanceCount = 2;
    final int size = 10000;
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
    final Config config = getConfig();
    config.setClusterName("testEager");
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    config.getMapConfig("testInitialLoadModeEagerWhileStoppigOneNode").setMapStoreConfig(mapStoreConfig);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    new Thread(() -> {
        sleepSeconds(3);
        instance1.getLifecycleService().shutdown();
        sleepSeconds(3);
        final IMap<Object, Object> map = instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
        assertEquals(size, map.size());
        countDownLatch.countDown();
    }).start();
    assertOpenEventually(countDownLatch);
    final IMap<Object, Object> map2 = instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
    final int map2Size = map2.size();
    assertEquals(size, map2Size);
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with IMap

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

the class MapStoreTest method testIssue991EvictedNullIssue.

@Test(timeout = 120000)
public void testIssue991EvictedNullIssue() throws InterruptedException {
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new MapLoader<String, String>() {

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

        @Override
        public Map<String, String> loadAll(Collection<String> keys) {
            return null;
        }

        @Override
        public Set<String> loadAllKeys() {
            return null;
        }
    });
    Config config = getConfig();
    config.getMapConfig("testIssue991EvictedNullIssue").setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap("testIssue991EvictedNullIssue");
    map.get("key");
    assertNull(map.get("key"));
    map.put("key", "value");
    Thread.sleep(2000);
    assertEquals("value", map.get("key"));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with IMap

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

the class MapStoreTest method testIssue1142ExceptionWhenLoadAllReturnsNull.

@Test(timeout = 120000)
public void testIssue1142ExceptionWhenLoadAllReturnsNull() {
    Config config = getConfig();
    String mapName = "testIssue1142ExceptionWhenLoadAllReturnsNull";
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setImplementation(new MapStoreAdapter<String, String>() {

        @Override
        public Set<String> loadAllKeys() {
            Set<String> keys = new HashSet<>();
            keys.add("key");
            return keys;
        }

        public Map<String, String> loadAll(Collection<String> keys) {
            return null;
        }
    });
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    final IMap<Integer, Integer> map = instance.getMap(mapName);
    for (int i = 0; i < 300; i++) {
        map.put(i, i);
    }
    assertEquals(300, map.size());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) IMap(com.hazelcast.map.IMap) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with IMap

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

the class MapLoaderTest method testNullValue_loadAll.

@Ignore("See https://github.com/hazelcast/hazelcast/issues/11931")
@Test
public void testNullValue_loadAll() {
    String name = "testNullIn_loadAll";
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setEnabled(true).setInitialLoadMode(MapStoreConfig.InitialLoadMode.LAZY).setImplementation(new MapLoader<String, String>() {

        @Override
        public String load(String key) {
            if (key.equals("1")) {
                return "1";
            }
            if (key.equals("2")) {
                return null;
            }
            if (key.equals("3")) {
                return "3";
            }
            return null;
        }

        @Override
        public Map<String, String> loadAll(Collection<String> keys) {
            Map<String, String> val = new HashMap<>();
            if (keys.contains("1")) {
                val.put("1", "1");
            }
            if (keys.contains("2")) {
                val.put("2", null);
            }
            if (keys.contains("3")) {
                val.put("3", "3");
            }
            return val;
        }

        @Override
        public Iterable<String> loadAllKeys() {
            List<String> keys = new ArrayList<>();
            keys.add("1");
            keys.add("2");
            keys.add("3");
            return keys;
        }
    });
    Config config = getConfig();
    config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<String, String> map = instance.getMap(name);
    expectedException.expect(NullPointerException.class);
    expectedException.expectMessage(startsWith("Neither key nor value can be loaded as null"));
    map.size();
    assertEquals(2, map.size());
    assertEquals("1", map.get("1"));
    assertEquals(null, map.get("2"));
    assertEquals("3", map.get("3"));
}
Also used : MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IMap(com.hazelcast.map.IMap) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IMap (com.hazelcast.map.IMap)292 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)73 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32