use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EntryProcessorTest method testIssue969MapEntryProcessorAllKeys.
@Test
public void testIssue969MapEntryProcessorAllKeys() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
nodeFactory.newHazelcastInstance(cfg);
IMap<Integer, Integer> map = instance1.getMap(MAP_NAME);
AtomicInteger addCount = new AtomicInteger(0);
AtomicInteger updateCount = new AtomicInteger(0);
AtomicInteger removeCount = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(300);
map.addEntryListener((EntryAddedListener<Integer, Integer>) event -> {
addCount.incrementAndGet();
latch.countDown();
}, true);
map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> {
removeCount.incrementAndGet();
latch.countDown();
}, true);
map.addEntryListener((EntryUpdatedListener<Integer, Integer>) event -> {
updateCount.incrementAndGet();
latch.countDown();
}, true);
int size = 100;
for (int i = 0; i < size; i++) {
map.put(i, i);
}
IncrementorEntryProcessor<Integer> entryProcessor = new IncrementorEntryProcessor<>();
Map<Integer, Integer> res = map.executeOnEntries(entryProcessor);
for (int i = 0; i < size; i++) {
assertEquals(map.get(i), (Object) (i + 1));
}
for (int i = 0; i < size; i++) {
assertEquals(map.get(i), res.get(i));
}
RemoveEntryProcessor removeEntryProcessor = new RemoveEntryProcessor();
map.executeOnEntries(removeEntryProcessor);
assertEquals(0, map.size());
assertTrue(latch.await(100, TimeUnit.SECONDS));
assertEquals(100, addCount.get());
assertEquals(100, removeCount.get());
assertEquals(100, updateCount.get());
}
use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EntryProcessorTest method receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnEntries.
@Test
public void receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnEntries() {
Config config = getConfig();
config.getMapConfig(MAP_NAME).getMapStoreConfig().setEnabled(true).setImplementation(new TestPostProcessingMapStore<>());
IMap<Integer, Integer> map = createHazelcastInstance(config).getMap(MAP_NAME);
final CountDownLatch latch = new CountDownLatch(1);
map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> latch.countDown(), true);
map.put(1, 1);
map.executeOnEntries(entry -> {
entry.setValue(null);
return null;
});
assertOpenEventually(latch);
}
Aggregations