use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapStoreTest method testIssue583MapReplaceShouldTriggerMapStore.
@Test(timeout = 120000)
public void testIssue583MapReplaceShouldTriggerMapStore() {
final ConcurrentMap<String, Long> store = new ConcurrentHashMap<String, Long>();
final MapStore<String, Long> myMapStore = new SimpleMapStore<String, Long>(store);
Config config = getConfig();
config.getMapConfig("myMap").setMapStoreConfig(new MapStoreConfig().setImplementation(myMapStore));
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance hc = nodeFactory.newHazelcastInstance(config);
IMap<String, Long> myMap = hc.getMap("myMap");
myMap.put("one", 1L);
assertEquals(1L, myMap.get("one").longValue());
assertEquals(1L, store.get("one").longValue());
myMap.putIfAbsent("two", 2L);
assertEquals(2L, myMap.get("two").longValue());
assertEquals(2L, store.get("two").longValue());
myMap.putIfAbsent("one", 5L);
assertEquals(1L, myMap.get("one").longValue());
assertEquals(1L, store.get("one").longValue());
myMap.replace("one", 1L, 111L);
assertEquals(111L, myMap.get("one").longValue());
assertEquals(111L, store.get("one").longValue());
myMap.replace("one", 1L);
assertEquals(1L, myMap.get("one").longValue());
assertEquals(1L, store.get("one").longValue());
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapLoaderTest method createMapConfig.
private Config createMapConfig(String mapName, SampleIndexableObjectMapLoader loader) {
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(mapName);
List<MapIndexConfig> indexConfigs = mapConfig.getMapIndexConfigs();
indexConfigs.add(new MapIndexConfig("name", true));
MapStoreConfig storeConfig = new MapStoreConfig();
storeConfig.setFactoryImplementation(loader);
storeConfig.setEnabled(true);
mapConfig.setMapStoreConfig(storeConfig);
return config;
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapLoaderTest method testSenderAndBackupTerminates_AfterInitialLoad.
@Test
public void testSenderAndBackupTerminates_AfterInitialLoad() throws InterruptedException {
String name = randomString();
Config config = new Config();
MapConfig mapConfig = config.getMapConfig(name);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new DummyMapLoader());
mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
mapConfig.setMapStoreConfig(mapStoreConfig);
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(5);
HazelcastInstance[] instances = instanceFactory.newInstances(config);
IMap<Object, Object> map = instances[0].getMap(name);
map.clear();
HazelcastInstance[] ownerAndReplicas = findOwnerAndReplicas(instances, name);
ownerAndReplicas[0].getLifecycleService().terminate();
ownerAndReplicas[1].getLifecycleService().terminate();
assertClusterSizeEventually(3, ownerAndReplicas[3]);
map = ownerAndReplicas[3].getMap(name);
map.loadAll(false);
assertEquals(DummyMapLoader.DEFAULT_SIZE, map.size());
}
use of com.hazelcast.config.MapStoreConfig 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);
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapStoreDataLoadingContinuesWhenNodeJoins method testNoDeadLockDuringJoin.
@Test(timeout = 600000)
public void testNoDeadLockDuringJoin() throws Exception {
// create shared hazelcast config
final Config config = new XmlConfigBuilder().build();
// disable JMX to make sure lazy loading works asynchronously
config.setProperty("hazelcast.jmx", "false");
// get map config
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
// create shared map store implementation
// - use slow loading (300ms per map entry)
final CountDownLatch halfOfKeysAreLoaded = new CountDownLatch(1);
final InMemoryMapStore store = new InMemoryMapStore(halfOfKeysAreLoaded, MS_PER_LOAD, false);
store.preload(PRELOAD_SIZE);
// configure map store
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setInitialLoadMode(InitialLoadMode.LAZY);
mapStoreConfig.setWriteDelaySeconds(WRITE_DELAY_SECONDS);
mapStoreConfig.setClassName(null);
mapStoreConfig.setImplementation(store);
mapConfig.setMapStoreConfig(mapStoreConfig);
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final CountDownLatch node1Started = new CountDownLatch(1);
final CountDownLatch node1FinishedLoading = new CountDownLatch(1);
// thread 1:
// start a single node and load the data
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance hcInstance = factory.newHazelcastInstance(config);
// try-finally to stop hazelcast instance
node1Started.countDown();
try {
// get map
// this will trigger loading the data
IMap<String, String> map = hcInstance.getMap(MAP_NAME);
map.size();
node1FinishedLoading.countDown();
} finally {
thread1Shutdown.set(System.currentTimeMillis());
hcInstance.getLifecycleService().shutdown();
}
}
}, "Thread 1");
thread1.start();
node1Started.await();
// thread 2:
// simulate a second member which joins the cluster
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
HazelcastInstance hcInstance = factory.newHazelcastInstance(config);
try {
hcInstance.getMap(MAP_NAME);
final int loadTimeMillis = MS_PER_LOAD * PRELOAD_SIZE;
node1FinishedLoading.await(loadTimeMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
EmptyStatement.ignore(e);
} finally {
thread2Shutdown.set(System.currentTimeMillis());
hcInstance.getLifecycleService().shutdown();
}
}
}, "Thread 2");
thread2.start();
// join threads
thread1.join();
thread2.join();
// assert correct shutdown order
if (thread1Shutdown.get() > thread2Shutdown.get()) {
fail("Thread 2 was shutdown before thread 1.");
}
}
Aggregations