Search in sources :

Example 16 with QueryCache

use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.

the class QueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_destroy.

@Test
public void event_service_is_empty_after_queryCache_destroy() throws InterruptedException {
    final String mapName = "test";
    final String queryCacheName = "cqc";
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    Config config = getConfig();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, node1, node2, node3);
    final IMap<Integer, Integer> map = node1.getMap(mapName);
    final AtomicBoolean stop = new AtomicBoolean(false);
    ArrayList<Thread> threads = new ArrayList<Thread>();
    for (int i = 0; i < STRESS_TEST_THREAD_COUNT; i++) {
        Thread thread = new Thread() {

            @Override
            public void run() {
                while (!stop.get()) {
                    QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.alwaysTrue(), true);
                    queryCache.destroy();
                }
            }
        };
        threads.add(thread);
    }
    for (Thread thread : threads) {
        thread.start();
    }
    sleepSeconds(STRESS_TEST_RUN_SECONDS);
    stop.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    map.destroy();
    assertNoUserListenerLeft(node1);
    assertNoUserListenerLeft(node2);
    assertNoUserListenerLeft(node3);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with QueryCache

use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.

the class QueryCacheNoEventLossTest method assertAllQueryCachesSyncWithMap.

private void assertAllQueryCachesSyncWithMap() {
    Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
    for (HazelcastInstance instance : instances) {
        IMap map = instance.getMap(MAP_NAME);
        Set<Map.Entry> mapEntrySet = map.entrySet();
        QueryCache queryCache = map.getQueryCache(QUERY_CACHE_NAME);
        Set<Map.Entry> queryCacheEntrySet = queryCache.entrySet();
        assertEquals(queryCacheEntrySet.size(), mapEntrySet.size());
        for (Map.Entry entry : mapEntrySet) {
            Object key = entry.getKey();
            Object valueFromMap = entry.getValue();
            Object valueFromQueryCache = queryCache.get(key);
            assertEquals(valueFromQueryCache, valueFromMap);
        }
    }
}
Also used : IMap(com.hazelcast.map.IMap) QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 18 with QueryCache

use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.

the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_evictAll.

@Test
public void testQueryCacheCleared_afterCalling_IMap_evictAll() {
    final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 1000);
    IFunction evictAll = (ignored) -> {
        map.evictAll();
        return null;
    };
    assertQueryCacheSizeEventually(0, evictAll, queryCache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AttributeConfig(com.hazelcast.config.AttributeConfig) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) PredicateConfig(com.hazelcast.config.PredicateConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) ValueCollector(com.hazelcast.query.extractor.ValueCollector) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Employee(com.hazelcast.map.impl.querycache.utils.Employee) Predicates(com.hazelcast.query.Predicates) QueryCache(com.hazelcast.map.QueryCache) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) EntryAdapter(com.hazelcast.core.EntryAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Employee(com.hazelcast.map.impl.querycache.utils.Employee) IFunction(com.hazelcast.core.IFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with QueryCache

use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.

the class QueryCacheTest method testDestroy_emptiesQueryCache.

@Test
public void testDestroy_emptiesQueryCache() {
    int entryCount = 1000;
    final CountDownLatch numberOfAddEvents = new CountDownLatch(entryCount);
    IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, (EntryAddedListener<Integer, Employee>) (event) -> numberOfAddEvents.countDown(), TRUE_PREDICATE, false);
    populateMap(map, entryCount);
    assertOpenEventually(numberOfAddEvents);
    queryCache.destroy();
    assertEquals(0, queryCache.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AttributeConfig(com.hazelcast.config.AttributeConfig) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) PredicateConfig(com.hazelcast.config.PredicateConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) ValueCollector(com.hazelcast.query.extractor.ValueCollector) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Employee(com.hazelcast.map.impl.querycache.utils.Employee) Predicates(com.hazelcast.query.Predicates) QueryCache(com.hazelcast.map.QueryCache) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) EntryAdapter(com.hazelcast.core.EntryAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Employee(com.hazelcast.map.impl.querycache.utils.Employee) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with QueryCache

use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.

the class QueryCacheCreateDestroyTest method create_after_destroy_gives_fresh_query_cache_instance.

@Test
public void create_after_destroy_gives_fresh_query_cache_instance() {
    final String mapName = "someMap";
    final String queryCacheName = "testCache";
    HazelcastInstance server = factory.newHazelcastInstance(newConfigWithQueryCache(mapName, queryCacheName));
    server.getMap(mapName);
    IMap map = server.getMap(mapName);
    QueryCache queryCache = map.getQueryCache(queryCacheName);
    queryCache.destroy();
    QueryCache newQueryCache = map.getQueryCache(queryCacheName);
    assertFalse(queryCache == newQueryCache);
}
Also used : IMap(com.hazelcast.map.IMap) QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

QueryCache (com.hazelcast.map.QueryCache)23 QuickTest (com.hazelcast.test.annotation.QuickTest)22 Test (org.junit.Test)22 HazelcastInstance (com.hazelcast.core.HazelcastInstance)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Config (com.hazelcast.config.Config)12 IMap (com.hazelcast.map.IMap)11 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)8 EventLostEvent (com.hazelcast.map.EventLostEvent)7 EventLostListener (com.hazelcast.map.listener.EventLostListener)7 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 ArrayList (java.util.ArrayList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AttributeConfig (com.hazelcast.config.AttributeConfig)3 MapConfig (com.hazelcast.config.MapConfig)3 PredicateConfig (com.hazelcast.config.PredicateConfig)3 EntryAdapter (com.hazelcast.core.EntryAdapter)3 EntryEvent (com.hazelcast.core.EntryEvent)3