use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class QueryCacheIMapEventHandlingTest method testEvent_EXPIRED.
@Test
public void testEvent_EXPIRED() throws Exception {
int key = 1;
int value = 1;
final CountDownLatch latch = new CountDownLatch(1);
queryCache.addEntryListener(new EntryAddedListener() {
@Override
public void entryAdded(EntryEvent event) {
latch.countDown();
}
}, true);
map.put(key, value, 1, SECONDS);
latch.await();
sleepSeconds(1);
// map#get creates EXPIRED event
map.get(key);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method testMaxSizeEvictionWorks.
@Test
public void testMaxSizeEvictionWorks() {
int maxSize = 100;
int populationCount = 500;
String mapName = randomString();
String cacheName = randomString();
Config config = getConfig(maxSize, mapName, cacheName);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Integer> map = getMap(node, mapName);
final CountDownLatch entryCountingLatch = new CountDownLatch(populationCount);
QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, Predicates.alwaysTrue(), true);
UUID listener = cache.addEntryListener(new EntryAddedListener() {
@Override
public void entryAdded(EntryEvent event) {
entryCountingLatch.countDown();
}
}, false);
for (int i = 0; i < populationCount; i++) {
map.put(i, i);
}
assertOpenEventually("Cache size is " + cache.size(), entryCountingLatch);
// expecting at most populationCount - maxSize - 5 entries
// 5 states an error margin since eviction does not sweep precise number of entries.
assertQueryCacheEvicted(maxSize, 5, cache);
assertTrue(cache.removeEntryListener(listener));
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class QueryCacheCoalescingTest method testCoalescingModeWorks.
@Test
public void testCoalescingModeWorks() {
String mapName = randomString();
String cacheName = randomString();
Config config = getConfig(mapName, cacheName);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Integer> map = getMap(node, mapName);
final CountDownLatch updateEventCount = new CountDownLatch(1);
final QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
cache.addEntryListener(new EntryUpdatedListener() {
@Override
public void entryUpdated(EntryEvent event) {
updateEventCount.countDown();
}
}, false);
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
// update same key to control whether coalescing kicks in.
for (int i = 0; i < 500; i++) {
map.put(0, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(100, cache.size());
}
});
assertOpenEventually(updateEventCount);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EventPublishOrderWithEvictionTest method assertEmittedEventsOrder.
private void assertEmittedEventsOrder(EventOrderAwareEntryListener entryListener) {
Map<Integer, List<EntryEventType>> eventsPerKey = new HashMap<Integer, List<EntryEventType>>();
List<EntryEvent> events = entryListener.getOrderedEvents();
for (EntryEvent event : events) {
Integer key = (Integer) event.getKey();
List<EntryEventType> eventTypes = eventsPerKey.get(key);
if (eventTypes == null) {
eventTypes = new ArrayList<EntryEventType>();
eventsPerKey.put(key, eventTypes);
}
EntryEventType eventType = event.getEventType();
eventTypes.add(eventType);
}
Set<Map.Entry<Integer, List<EntryEventType>>> entries = eventsPerKey.entrySet();
for (Map.Entry<Integer, List<EntryEventType>> entry : entries) {
List<EntryEventType> eventTypes = entry.getValue();
EntryEventType prev = null;
for (int i = 0; i < eventTypes.size(); i++) {
final EntryEventType eventType = eventTypes.get(i);
if (i == 0) {
assertEquals(EntryEventType.ADDED, eventType);
prev = eventType;
continue;
}
if (prev.equals(EntryEventType.ADDED)) {
assertEquals(EntryEventType.EVICTED, eventType);
} else if (prev.equals(EntryEventType.EVICTED)) {
assertEquals(EntryEventType.ADDED, eventType);
}
prev = eventType;
}
}
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method expired_entries_removed_after_migration.
@Test
@Category(NightlyTest.class)
public void expired_entries_removed_after_migration() {
int numOfEntries = 10;
String name = "expired_entries_removed_after_migration";
MapConfig mapConfig = newMapConfig(name).setMaxIdleSeconds(20);
Config config = getConfig().setProperty(PROP_TASK_PERIOD_SECONDS, "1").setProperty(ClusterProperty.PARTITION_COUNT.getName(), "2").addMapConfig(mapConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance node1 = factory.newHazelcastInstance(config);
IMap<Integer, Integer> map = node1.getMap(name);
final CountDownLatch latch = new CountDownLatch(numOfEntries);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryExpired(EntryEvent event) {
latch.countDown();
}
}, false);
for (int i = 0; i < numOfEntries; ++i) {
map.put(i, i);
}
// data migration will be done to new node
factory.newHazelcastInstance(config);
assertOpenEventually(latch);
assertSizeEventually(0, map);
}
Aggregations