Search in sources :

Example 1 with MapStore

use of com.hazelcast.core.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;
}
Also used : Random(java.util.Random) MapStore(com.hazelcast.core.MapStore) Collection(java.util.Collection) MapConfig(com.hazelcast.config.MapConfig) Map(java.util.Map)

Example 2 with MapStore

use of com.hazelcast.core.MapStore 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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) Random(java.util.Random) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStore(com.hazelcast.core.MapStore) PostProcessingMapStore(com.hazelcast.core.PostProcessingMapStore) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapConfig (com.hazelcast.config.MapConfig)2 MapStore (com.hazelcast.core.MapStore)2 Random (java.util.Random)2 Config (com.hazelcast.config.Config)1 GroupConfig (com.hazelcast.config.GroupConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 PostProcessingMapStore (com.hazelcast.core.PostProcessingMapStore)1 Employee (com.hazelcast.query.SampleObjects.Employee)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Collection (java.util.Collection)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1