Search in sources :

Example 1 with QueryCache

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

the class ClientQueryCacheEventLostListenerTest method testListenerNotified_onEventLoss.

@Test
public void testListenerNotified_onEventLoss() throws Exception {
    int count = 30;
    String mapName = randomString();
    String queryCacheName = randomString();
    IMap<Integer, Integer> mapNode = node.getMap(mapName);
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Integer> mapClient = client.getMap(mapName);
    setTestSequencer(mapClient, 9);
    // expecting one lost event publication per partition.
    final CountDownLatch lostEventCount = new CountDownLatch(1);
    QueryCache queryCache = mapClient.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            lostEventCount.countDown();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        mapNode.put(i, i);
    }
    assertOpenEventually(lostEventCount);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with QueryCache

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

the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    String mapName = randomString();
    String queryCacheName = randomString();
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    mapConfig.setBackupCount(0);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
    setTestSequencer(node, 9);
    setTestSequencer(node2, 9);
    IMap<Integer, Integer> map = getMap(node, mapName);
    node2.getMap(mapName);
    //set test sequencer to subscribers.
    int count = 30;
    final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            queryCache.tryRecover();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    AssertTask task = new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(9, queryCache.size());
        }
    };
    assertTrueEventually(task);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with QueryCache

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

the class QueryCacheMemoryLeakTest method removes_user_listener_upon_query_cache_destroy.

@Test
public void removes_user_listener_upon_query_cache_destroy() {
    String name = "mapA";
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    Config config = getConfig();
    final HazelcastInstance node1 = factory.newHazelcastInstance(config);
    final HazelcastInstance node2 = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(2, node1, node2);
    final IMap<Integer, Integer> map = node1.getMap(name);
    int key = RandomPicker.getInt(0, Integer.MAX_VALUE);
    map.put(key, 1);
    QueryCache queryCache = map.getQueryCache(name, Predicates.alwaysTrue(), true);
    queryCache.get(key);
    queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {

        @Override
        public void entryAdded(EntryEvent<Integer, Integer> event) {
        }
    }, true);
    queryCache.destroy();
    map.destroy();
    assertNoUserListenerLeft(node1);
    assertNoUserListenerLeft(node2);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with QueryCache

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

the class QueryCacheMemoryLeakTest method stress_user_listener_removal_upon_query_cache_destroy.

@Test
public void stress_user_listener_removal_upon_query_cache_destroy() throws InterruptedException {
    final String[] mapNames = new String[] { "mapA", "mapB", "mapC", "mapD" };
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    Config config = getConfig();
    final HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    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()) {
                    String name = mapNames[RandomPicker.getInt(0, 4)];
                    final IMap<Integer, Integer> map = node1.getMap(name);
                    int key = RandomPicker.getInt(0, Integer.MAX_VALUE);
                    map.put(key, 1);
                    QueryCache queryCache = map.getQueryCache(name, Predicates.alwaysTrue(), true);
                    queryCache.get(key);
                    queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {

                        @Override
                        public void entryAdded(EntryEvent<Integer, Integer> event) {
                        }
                    }, true);
                    queryCache.destroy();
                    map.destroy();
                }
            }
        };
        threads.add(thread);
    }
    for (Thread thread : threads) {
        thread.start();
    }
    sleepSeconds(STRESS_TEST_RUN_SECONDS);
    stop.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    assertNoUserListenerLeft(node1);
    assertNoUserListenerLeft(node2);
    assertNoUserListenerLeft(node3);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryCache

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

the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.

@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
    final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 1000);
    IFunction clear = (ignored) -> {
        map.clear();
        return null;
    };
    assertQueryCacheSizeEventually(0, clear, 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)

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