use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class MapTransactionRegressionTest method test_Issue1076.
@Test
public void test_Issue1076() {
Config config = getConfig();
final HazelcastInstance inst = createHazelcastInstance(config);
IMap map = inst.getMap("default");
EntryListener<String, Integer> l = new EntryAdapter<String, Integer>() {
};
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate<String, Integer> p = e.equal(1);
map.addEntryListener(l, p, null, false);
for (Integer i = 0; i < 100; i++) {
TransactionContext context = inst.newTransactionContext();
context.beginTransaction();
TransactionalMap<String, Integer> txnMap = context.getMap("default");
txnMap.remove(i.toString());
context.commitTransaction();
}
assertEquals(0, map.size());
inst.shutdown();
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class QueryListenerTest method testMapQueryListener2.
@Test
public void testMapQueryListener2() throws InterruptedException {
Config cfg = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(cfg);
HazelcastInstance instance3 = nodeFactory.newHazelcastInstance(cfg);
final IMap<Object, Object> map = instance1.getMap("testMapQueryListener2");
final AtomicInteger addCount = new AtomicInteger(0);
EntryListener<Object, Object> listener = new EntryAdapter<Object, Object>() {
public void entryAdded(EntryEvent<Object, Object> event) {
addCount.incrementAndGet();
}
};
Predicate<Object, Object> predicate = new SqlPredicate("age >= 50");
map.addEntryListener(listener, predicate, null, false);
int size = 100;
for (int i = 0; i < size; i++) {
Person person = new Person("name", i);
map.put(i, person);
}
Thread.sleep(1000);
assertEquals(50, addCount.get());
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class QueryListenerTest method testMapQueryListener.
@Test
public void testMapQueryListener() throws InterruptedException {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance3 = nodeFactory.newHazelcastInstance(config);
final IMap<Object, Object> map = instance1.getMap("testMapQueryListener");
final Object[] addedKey = new Object[1];
final Object[] addedValue = new Object[1];
final Object[] updatedKey = new Object[1];
final Object[] oldValue = new Object[1];
final Object[] newValue = new Object[1];
final Object[] removedKey = new Object[1];
final Object[] removedValue = new Object[1];
EntryListener<Object, Object> listener = new EntryAdapter<Object, Object>() {
public void entryAdded(EntryEvent<Object, Object> event) {
addedKey[0] = event.getKey();
addedValue[0] = event.getValue();
}
public void entryRemoved(EntryEvent<Object, Object> event) {
removedKey[0] = event.getKey();
removedValue[0] = event.getOldValue();
}
public void entryUpdated(EntryEvent<Object, Object> event) {
updatedKey[0] = event.getKey();
oldValue[0] = event.getOldValue();
newValue[0] = event.getValue();
}
public void entryEvicted(EntryEvent<Object, Object> event) {
}
@Override
public void mapEvicted(MapEvent event) {
}
@Override
public void mapCleared(MapEvent event) {
}
};
map.addEntryListener(listener, new StartsWithPredicate("a"), null, true);
map.put("key1", "abc");
map.put("key2", "bcd");
map.put("key2", "axyz");
map.remove("key1");
Thread.sleep(1000);
assertEquals(addedKey[0], "key1");
assertEquals(addedValue[0], "abc");
assertEquals(updatedKey[0], "key2");
assertEquals(oldValue[0], "bcd");
assertEquals(newValue[0], "axyz");
assertEquals(removedKey[0], "key1");
assertEquals(removedValue[0], "abc");
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared.
@Test
public void listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared() {
String cacheName = randomString();
int entryCount = 1000;
final AtomicInteger clearAllEventCount = new AtomicInteger();
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {
@Override
public void mapCleared(MapEvent e) {
clearAllEventCount.incrementAndGet();
}
}, TRUE_PREDICATE, false);
populateMap(map, entryCount);
assertQueryCacheSizeEventually(entryCount, queryCache);
map.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
// expecting at least 1 event
assertTrue(clearAllEventCount.get() >= 1);
assertEquals(0, queryCache.size());
}
});
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class EvictionTest method testMapPutTTLWithListener.
/**
* Background task {@link com.hazelcast.map.impl.eviction.ExpirationManager.ClearExpiredRecordsTask}
* should sweep expired records eventually.
*/
@Test
@Category(NightlyTest.class)
public void testMapPutTTLWithListener() throws InterruptedException {
final int putCount = 100;
final CountDownLatch latch = new CountDownLatch(putCount);
IMap<Integer, Integer> map = createSimpleMap();
map.addEntryListener(new EntryAdapter() {
public void entryEvicted(final EntryEvent event) {
latch.countDown();
}
}, true);
final int ttl = (int) (Math.random() * 5000);
for (int j = 0; j < putCount; j++) {
map.put(j, j, ttl, TimeUnit.MILLISECONDS);
}
// wait until eviction is complete.
assertOpenEventually(latch, TimeUnit.MINUTES.toSeconds(10));
}
Aggregations