Search in sources :

Example 6 with QueryCache

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

the class QueryCacheEventLostListenerTest method testListenerNotified_uponEventLoss.

@Test
public void testListenerNotified_uponEventLoss() {
    String mapName = randomString();
    String queryCacheName = randomString();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    Config config = new Config();
    config.setProperty(ClusterProperty.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 all nodes
    int count = 30;
    // expecting one lost event per partition
    final CountDownLatch lossCount = new CountDownLatch(1);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            lossCount.countDown();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertOpenEventually(lossCount);
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with QueryCache

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

the class ClientQueryCacheCreateDestroyTest 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();
    HazelcastInstance client = factory.newHazelcastClient(newClientConfigWithQueryCache(mapName, queryCacheName));
    // create client-side query-cache
    IMap clientMap = client.getMap(mapName);
    QueryCache clientQueryCache = clientMap.getQueryCache(queryCacheName);
    clientQueryCache.destroy();
    QueryCache newQueryCache = clientMap.getQueryCache(queryCacheName);
    assertFalse(clientQueryCache == 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)

Example 8 with QueryCache

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

the class ClientQueryCacheCreateDestroyTest method recreated_queryCache_gets_updates_from_restarted_server.

@Test
public void recreated_queryCache_gets_updates_from_restarted_server() {
    final String mapName = "someMap";
    final String queryCacheName = "testCache";
    // start server
    HazelcastInstance server = factory.newHazelcastInstance();
    server.getMap(mapName);
    // start client with query-cache config
    HazelcastInstance client = factory.newHazelcastClient(newClientConfigWithQueryCache(mapName, queryCacheName));
    // create client-side query-cache
    IMap clientMap = client.getMap(mapName);
    QueryCache clientQueryCache = clientMap.getQueryCache(queryCacheName);
    // shutdown all members, at this point only client is alive
    factory.shutdownAllMembers();
    // start new server to emulate server re-start
    HazelcastInstance newServer = factory.newHazelcastInstance();
    IMap newServerMap = newServer.getMap(mapName);
    // populate new map on server
    for (int i = 0; i < 1000; i++) {
        newServerMap.put(i, i);
    }
    // destroy client query-cache from client-side to re-create it,
    // otherwise it stays tied with previous server
    clientQueryCache.destroy();
    // new client-side query-cache should have all updates from server side
    clientQueryCache = clientMap.getQueryCache(queryCacheName);
    int queryCacheSize = clientQueryCache.size();
    assertEquals(1000, queryCacheSize);
}
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 9 with QueryCache

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

the class ClientQueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_concurrent_destroy.

@Test
public void event_service_is_empty_after_queryCache_concurrent_destroy() throws InterruptedException {
    final HazelcastInstance node1 = factory.newHazelcastInstance();
    HazelcastInstance node2 = factory.newHazelcastInstance();
    String mapName = "test";
    HazelcastInstance client = factory.newHazelcastClient();
    final IMap<Integer, Integer> map = client.getMap(mapName);
    populateMap(map);
    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("a", Predicates.alwaysTrue(), true);
                    queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {

                        @Override
                        public void entryAdded(EntryEvent<Integer, Integer> event) {
                        }
                    }, 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();
    }
    assertNoUserListenerLeft(node1);
    assertNoUserListenerLeft(node2);
    assertNoUserListenerLeft(mapName, client);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) 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 10 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 = getConfig();
    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, Predicates.sql("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) 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) 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