Search in sources :

Example 1 with EntryUpdatedListener

use of com.hazelcast.map.listener.EntryUpdatedListener 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);
}
Also used : Config(com.hazelcast.config.Config) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) CountDownLatch(java.util.concurrent.CountDownLatch) EntryUpdatedListener(com.hazelcast.map.listener.EntryUpdatedListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)1 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)1 EntryEvent (com.hazelcast.core.EntryEvent)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 EntryUpdatedListener (com.hazelcast.map.listener.EntryUpdatedListener)1 AssertTask (com.hazelcast.test.AssertTask)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1