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());
}
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);
}
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"));
}
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());
}
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"));
}
Aggregations