use of com.hazelcast.map.MapStore in project hazelcast by hazelcast.
the class StoreLatencyPlugin_MapIntegrationTest method addMapConfig.
private static MapConfig addMapConfig(Config config) {
MapConfig mapConfig = config.getMapConfig("mappy");
mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(new MapStore() {
private final Random random = new Random();
@Override
public void store(Object key, Object value) {
}
@Override
public Object load(Object key) {
randomSleep();
return null;
}
private void randomSleep() {
long delay = random.nextInt(100);
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public Map loadAll(Collection keys) {
return null;
}
@Override
public void storeAll(Map map) {
}
@Override
public void delete(Object key) {
}
@Override
public Iterable loadAllKeys() {
return null;
}
@Override
public void deleteAll(Collection keys) {
}
});
return mapConfig;
}
use of com.hazelcast.map.MapStore in project hazelcast by hazelcast.
the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.
@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() {
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