use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class IssuesTest method testIssue321_3.
// verify an event including values and an event excluding values are received, in any order
@Test
public void testIssue321_3() throws Exception {
int n = 1;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(n);
final IMap<Integer, Integer> imap = factory.newHazelcastInstance(getConfig()).getMap("testIssue321_3");
final List<EntryEvent<Integer, Integer>> eventsWithValues = new ArrayList<EntryEvent<Integer, Integer>>();
final List<EntryEvent<Integer, Integer>> eventsWithoutValues = new ArrayList<EntryEvent<Integer, Integer>>();
final EntryAdapter<Integer, Integer> listener = new EntryAdapter<Integer, Integer>() {
@Override
public void entryAdded(com.hazelcast.core.EntryEvent<Integer, Integer> event) {
if (event.getValue() == null) {
eventsWithoutValues.add(event);
} else {
eventsWithValues.add(event);
}
}
};
imap.addEntryListener(listener, true);
Thread.sleep(50L);
imap.addEntryListener(listener, false);
imap.put(1, 1);
assertEqualsEventually(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return eventsWithValues.size();
}
}, 1);
assertEqualsEventually(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return eventsWithoutValues.size();
}
}, 1);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class LocalMapStatsMultipleNodeTest method testLocalMapStats_preservedAfterEviction.
@Test
public void testLocalMapStats_preservedAfterEviction() {
String mapName = randomMapName();
Config config = new Config();
config.getProperties().setProperty(ClusterProperty.PARTITION_COUNT.getName(), "5");
MapConfig mapConfig = config.getMapConfig(mapName);
EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
evictionConfig.setMaxSizePolicy(MaxSizePolicy.PER_PARTITION);
evictionConfig.setSize(25);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Object, Object> map = instance.getMap(mapName);
final CountDownLatch entryEvictedLatch = new CountDownLatch(700);
map.addEntryListener(new EntryEvictedListener() {
@Override
public void entryEvicted(EntryEvent event) {
entryEvictedLatch.countDown();
}
}, true);
for (int i = 0; i < 1000; i++) {
map.put(i, i);
map.set(i, i);
assertEquals(i, map.get(i));
}
LocalMapStats localMapStats = map.getLocalMapStats();
assertEquals(2000, localMapStats.getHits());
assertEquals(1000, localMapStats.getPutOperationCount());
assertEquals(1000, localMapStats.getSetOperationCount());
assertEquals(1000, localMapStats.getGetOperationCount());
assertOpenEventually(entryEvictedLatch);
localMapStats = map.getLocalMapStats();
assertEquals(2000, localMapStats.getHits());
assertEquals(1000, localMapStats.getPutOperationCount());
assertEquals(1000, localMapStats.getSetOperationCount());
assertEquals(1000, localMapStats.getGetOperationCount());
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EntryEventDataCacheTest method createInvalidationEventRejectingFilter.
private static EventListenerFilter createInvalidationEventRejectingFilter() {
ListenerAdapter listenerAdapter = createListenerAdapter(new EntryAddedListener() {
@Override
public void entryAdded(EntryEvent event) {
}
});
int flags = setAndGetListenerFlags(listenerAdapter);
return new EventListenerFilter(flags, TrueEventFilter.INSTANCE);
}
use of com.hazelcast.core.EntryEvent 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=");
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapExpirationManagerTest method backgroundClearTaskStops_whenLifecycleState.
private void backgroundClearTaskStops_whenLifecycleState(LifecycleEvent.LifecycleState lifecycleState) {
Config config = getConfig();
config.setProperty(taskPeriodSecondsPropName(), "1");
HazelcastInstance node = createHazelcastInstance(config);
final AtomicInteger expirationCounter = new AtomicInteger();
IMap<Integer, Integer> map = node.getMap("test");
map.addEntryListener(new EntryExpiredListener() {
@Override
public void entryExpired(EntryEvent event) {
expirationCounter.incrementAndGet();
}
}, true);
map.put(1, 1, 3, TimeUnit.SECONDS);
((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(lifecycleState);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() {
int expirationCount = expirationCounter.get();
assertEquals(format("Expecting no expiration but found:%d", expirationCount), 0, expirationCount);
}
}, 5);
}
Aggregations