Search in sources :

Example 11 with QueryCache

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

the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    String mapName = randomMapName("map");
    String queryCacheName = randomMapName("cache");
    Config config = new Config();
    config.setProperty(PARTITION_COUNT.getName(), "1");
    factory.newHazelcastInstance(config);
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    // set test sequencer to subscriber
    int count = 30;
    setTestSequencer(map, 9);
    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);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(9, queryCache.size());
        }
    });
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) 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) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 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, Predicates.sql("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) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with QueryCache

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

the class ClientQueryCacheCreateDestroyTest method multiple_getQueryCache_calls_returns_same_query_cache_instance.

@Test
public void multiple_getQueryCache_calls_returns_same_query_cache_instance() {
    final String mapName = "someMap";
    final String queryCacheName = "testCache";
    HazelcastInstance server = factory.newHazelcastInstance();
    HazelcastInstance client = factory.newHazelcastClient(newClientConfigWithQueryCache(mapName, queryCacheName));
    // create client-side query-cache
    IMap clientMap = client.getMap(mapName);
    QueryCache clientQueryCache1 = clientMap.getQueryCache(queryCacheName);
    QueryCache clientQueryCache2 = clientMap.getQueryCache(queryCacheName);
    assertTrue(clientQueryCache1 == clientQueryCache2);
}
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)

Example 14 with QueryCache

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

the class ClientQueryCacheMemoryLeakTest 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" };
    Config config = getConfig();
    final HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    final HazelcastInstance client = factory.newHazelcastClient();
    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[getInt(0, 4)];
                    final IMap<Integer, Integer> map = client.getMap(name);
                    int key = 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);
    for (String mapName : mapNames) {
        // this is to ensure no user added listener is left on this client side query-cache
        assertNoUserListenerLeft(mapName, client);
    }
    Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
    for (HazelcastInstance instance : instances) {
        // this is to ensure no publisher side resource is left on server side event service
        assertServerSideEventServiceCleared(instance);
    }
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with QueryCache

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

the class ClientQueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_destroy.

@Test
public void event_service_is_empty_after_queryCache_destroy() {
    String mapName = "test";
    HazelcastInstance node1 = factory.newHazelcastInstance();
    HazelcastInstance node2 = factory.newHazelcastInstance();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(mapName);
    QueryCache queryCache = map.getQueryCache(mapName, Predicates.alwaysTrue(), true);
    queryCache.destroy();
    assertNoUserListenerLeft(node1);
    assertNoUserListenerLeft(node2);
}
Also used : 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