use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method testMemberLoadAll_invalidates_clientNearCache.
@Test
public void testMemberLoadAll_invalidates_clientNearCache() {
int mapSize = 1000;
String mapName = randomMapName();
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
HazelcastInstance client = getClient(hazelcastFactory, newInvalidationOnChangeEnabledNearCacheConfig(mapName));
Config config = member.getConfig();
SimpleMapStore store = new SimpleMapStore();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(store);
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
final IMap<Integer, Integer> clientMap = client.getMap(mapName);
populateMap(clientMap, mapSize);
populateNearCache(clientMap, mapSize);
IMap<Integer, Integer> map = member.getMap(mapName);
map.loadAll(true);
assertTrueEventually(new AssertTask() {
public void run() {
assertThatOwnedEntryCountEquals(clientMap, 0);
}
});
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class AbstractMapStoreTest method newConfig.
public Config newConfig(String mapName, Object storeImpl, int writeDelaySeconds, MapStoreConfig.InitialLoadMode loadMode) {
Config config = getConfig();
config.getManagementCenterConfig().setEnabled(false);
MapConfig mapConfig = config.getMapConfig(mapName);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setImplementation(storeImpl);
mapStoreConfig.setWriteDelaySeconds(writeDelaySeconds);
mapStoreConfig.setInitialLoadMode(loadMode);
mapConfig.setMapStoreConfig(mapStoreConfig);
return config;
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapClassLoaderTest method testIssue2721.
// https://github.com/hazelcast/hazelcast/issues/2721
@Test
public void testIssue2721() throws InterruptedException {
final Config config = new Config();
// get map config
final MapConfig mapConfig = config.getMapConfig(MAP_NAME);
// create shared map store implementation
final InMemoryMapStore store = new InMemoryMapStore();
store.preload(PRE_LOAD_SIZE);
// create map store config
final MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
mapStoreConfig.setWriteDelaySeconds(WRITE_DELAY_SECONDS);
mapStoreConfig.setClassName(null);
mapStoreConfig.setImplementation(store);
mapConfig.setMapStoreConfig(mapStoreConfig);
final HazelcastInstance instance = createHazelcastInstance(config);
// Get map so map store is triggered
instance.getMap(MAP_NAME);
boolean anEmptyCtxClassLoaderExist = false;
// test if all load threads had a context class loader set
for (boolean hasCtxClassLoader : store.getContextClassLoaders().values()) {
if (!hasCtxClassLoader) {
anEmptyCtxClassLoaderExist = true;
break;
}
}
assertFalse(anEmptyCtxClassLoaderExist);
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapStoreTest method testInitialLoadModeEagerMultipleThread.
@Test(timeout = 120000)
public void testInitialLoadModeEagerMultipleThread() {
final String mapName = "default";
final int instanceCount = 2;
final int size = 10000;
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
final Config config = getConfig();
GroupConfig groupConfig = new GroupConfig("testEager");
config.setGroupConfig(groupConfig);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
Runnable runnable = new Runnable() {
public void run() {
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final IMap<Object, Object> map = instance2.getMap(mapName);
assertEquals(size, map.size());
countDownLatch.countDown();
}
};
new Thread(runnable).start();
assertOpenEventually(countDownLatch, 120);
IMap map = instance1.getMap(mapName);
assertEquals(size, map.size());
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.
@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
Config config = getConfig();
String mapName = "testIssue1115";
MapStore mapStore = new ProcessingStore();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(mapStore);
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap(mapName);
Random random = new Random();
// testing put with new object
for (int i = 0; i < 10; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with existing object
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with replace
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.replace(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with putIfAbsent
for (int i = 10; i < 20; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.putIfAbsent(i, emp);
}
for (int i = 10; i < 20; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
}
Aggregations