use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EntryProcessorTest method receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnKey.
@Test
public void receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnKey() {
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.executeOnKey(1, entry -> {
entry.setValue(null);
return null;
});
assertOpenEventually(latch);
}
use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EntryProcessorTest method testMapEntryProcessorEntryListeners.
@Test
public void testMapEntryProcessorEntryListeners() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
Config cfg = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
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);
AtomicInteger addKey1Sum = new AtomicInteger(0);
AtomicInteger updateKey1Sum = new AtomicInteger(0);
AtomicInteger removeKey1Sum = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(6);
map.addEntryListener((EntryAddedListener<Integer, Integer>) event -> {
addCount.incrementAndGet();
if (event.getKey() == 1) {
addKey1Sum.addAndGet(event.getValue());
}
latch.countDown();
}, true);
map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> {
removeCount.incrementAndGet();
if (event.getKey() == 1) {
removeKey1Sum.addAndGet(event.getOldValue());
}
latch.countDown();
}, true);
map.addEntryListener((EntryUpdatedListener<Integer, Integer>) event -> {
updateCount.incrementAndGet();
if (event.getKey() == 1) {
updateKey1Sum.addAndGet(event.getValue());
}
latch.countDown();
}, true);
map.executeOnKey(1, new ValueSetterEntryProcessor(5));
map.executeOnKey(2, new ValueSetterEntryProcessor(7));
map.executeOnKey(2, new ValueSetterEntryProcessor(1));
map.executeOnKey(1, new ValueSetterEntryProcessor(3));
map.executeOnKey(1, new ValueSetterEntryProcessor(1));
map.executeOnKey(1, new ValueSetterEntryProcessor(null));
assertEquals((Integer) 1, map.get(2));
assertNull(map.get(1));
assertTrue(latch.await(100, TimeUnit.SECONDS));
assertEquals(2, addCount.get());
assertEquals(3, updateCount.get());
assertEquals(1, removeCount.get());
assertEquals(5, addKey1Sum.get());
assertEquals(4, updateKey1Sum.get());
assertEquals(1, removeKey1Sum.get());
}
use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EntryProcessorTest method testIssue969.
@Test
public void testIssue969() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
Config cfg = getConfig();
HazelcastInstance instance1 = 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(3);
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);
map.executeOnKey(1, new ValueReaderEntryProcessor());
assertNull(map.get(1));
map.executeOnKey(1, new ValueReaderEntryProcessor());
map.put(1, 3);
assertNotNull(map.get(1));
map.executeOnKey(1, new ValueReaderEntryProcessor());
map.put(2, 2);
ValueReaderEntryProcessor valueReaderEntryProcessor = new ValueReaderEntryProcessor();
map.executeOnKey(2, valueReaderEntryProcessor);
assertEquals(2, valueReaderEntryProcessor.getValue().intValue());
map.put(2, 5);
map.executeOnKey(2, valueReaderEntryProcessor);
assertEquals(5, valueReaderEntryProcessor.getValue().intValue());
assertTrue(latch.await(1, TimeUnit.MINUTES));
assertEquals(2, addCount.get());
assertEquals(0, removeCount.get());
assertEquals(1, updateCount.get());
}
use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class LocalListenerTest method no_exception_when_not_notifiable_listener.
@Test
public void no_exception_when_not_notifiable_listener() throws IllegalAccessException {
Config config = getConfig().setProperty(PROP_LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES, "true");
HazelcastInstance instance = createHazelcastInstance(config);
IMap<String, String> map = instance.getMap(randomString());
MapEventPublisherLogger mapEventPublisherLogger = new MapEventPublisherLogger();
injectLogger(instance, mapEventPublisherLogger);
// this entry-removed-listener is not notifiable,
// since we expect entry added events.
map.addLocalEntryListener((EntryRemovedListener<String, String>) event -> {
});
// generate entry-added event
map.put("key", "value");
// no exception we expect (we use assertTrueAllTheTime
// since event is fired after put return)
assertTrueAllTheTime(() -> assertTrue(mapEventPublisherLogger.logCollector.toString(), mapEventPublisherLogger.logCollector.isEmpty()), 5);
}
use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.
the class EventQueuePluginTest method testMap.
@Test
public void testMap() {
final IMap<Integer, Integer> map = hz.getMap(MAP_NAME);
map.addLocalEntryListener(new EntryAddedListener<Integer, Integer>() {
@Override
public void entryAdded(EntryEvent<Integer, Integer> event) {
assertOpenEventually(listenerLatch);
}
});
map.addLocalEntryListener(new EntryRemovedListener() {
@Override
public void entryRemoved(EntryEvent event) {
assertOpenEventually(listenerLatch);
}
});
spawn(new Runnable() {
@Override
public void run() {
Random random = new Random();
for (int i = 0; i < EVENT_COUNTER; i++) {
int key = random.nextInt(Integer.MAX_VALUE);
map.putAsync(key, 23);
map.removeAsync(key);
}
}
});
assertContainsEventually("IMap '" + MAP_NAME + "' ADDED sampleCount=", "IMap '" + MAP_NAME + "' REMOVED sampleCount=");
}
Aggregations