use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ClientMultiMapListenersTest method testListenerOnKey_whenOtherKeysAdded.
@Test
public void testListenerOnKey_whenOtherKeysAdded() throws InterruptedException {
final MultiMap mm = client.getMultiMap(randomString());
final List<EntryEvent> events = new ArrayList<EntryEvent>();
mm.addEntryListener(new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
events.add(event);
}
}, "key", true);
mm.put("key2", "value");
mm.put("key", "value");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, events.size());
assertEquals("key", events.get(0).getKey());
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
String mapName = randomString();
String queryCacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, Predicates.sql("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of add events wrong!", 9, countAddEvent.get());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
String mapName = randomString();
String queryCacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, new SqlPredicate("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of add events wrong!", 9, countAddEvent.get());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ClientQueryCacheEventHandlingTest 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 testMapRecordIdleEvictionOnMigration.
@Test
@Category(NightlyTest.class)
public void testMapRecordIdleEvictionOnMigration() {
final String name = "testMapRecordIdleEvictionOnMigration";
Config cfg = getConfig();
cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
MapConfig mapConfig = cfg.getMapConfig(name);
int maxIdleSeconds = 30;
int size = 100;
final int nsize = size / 5;
mapConfig.setMaxIdleSeconds(maxIdleSeconds);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
final IMap<Integer, Integer> map = instance1.getMap(name);
final CountDownLatch latch = new CountDownLatch(size - nsize);
map.addEntryListener(new EntryAdapter() {
public void entryEvicted(EntryEvent event) {
latch.countDown();
}
}, false);
// put sample data
for (int i = 0; i < size; i++) {
map.put(i, i);
}
// wait until some time that is close to eviction
sleepSeconds(maxIdleSeconds - 5);
// touch the ones you dont want to be evicted.
for (int i = 0; i < nsize; i++) {
map.get(i);
}
factory.newHazelcastInstance(cfg);
factory.newHazelcastInstance(cfg);
//wait until eviction is complete
assertOpenEventually(latch, 240);
assertSizeEventually(nsize, map);
}
Aggregations