Search in sources :

Example 21 with QueryCache

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

the class QueryCacheCreateDestroyTest method tryRecover_fails_after_destroy.

@Test
public void tryRecover_fails_after_destroy() {
    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();
    assertFalse(queryCache.tryRecover());
}
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 22 with QueryCache

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

the class QueryCacheCreateDestroyTest 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 a server
    HazelcastInstance server = factory.newHazelcastInstance();
    server.getMap(mapName);
    // start a serverWithQueryCache
    HazelcastInstance serverWithQueryCache = factory.newHazelcastInstance(newConfigWithQueryCache(mapName, queryCacheName));
    // create query-cache
    IMap map = serverWithQueryCache.getMap(mapName);
    QueryCache queryCache = map.getQueryCache(queryCacheName);
    // shutdown other member, at this point only serverWithQueryCache is alive
    server.shutdown();
    // start new server to emulate server re-start
    HazelcastInstance newServer = factory.newHazelcastInstance();
    IMap newServerMap = newServer.getMap(mapName);
    // populate new map from newServer
    for (int i = 0; i < 1000; i++) {
        newServerMap.put(i, i);
    }
    // destroy query-cache from serverWithQueryCache
    queryCache.destroy();
    // new query-cache should have all updates from server side
    queryCache = map.getQueryCache(queryCacheName);
    int queryCacheSize = queryCache.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 23 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);
    final String mapName = randomString();
    String queryCacheName = randomString();
    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);
    final 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);
    final CountDownLatch waitEventLossNotification = new CountDownLatch(1);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

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

        @Override
        public void run() {
            assertEquals(9, queryCache.size());
        }
    });
    // re-put entries and check if broken-sequences holder map will be empty
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            Map brokenSequences = getBrokenSequences(node, mapName, queryCache);
            assertTrue("After recovery, there should be no broken sequences left", brokenSequences.isEmpty());
        }
    });
}
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) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Map(java.util.Map) AbstractQueryCacheTestSupport.getMap(com.hazelcast.map.impl.querycache.AbstractQueryCacheTestSupport.getMap) IMap(com.hazelcast.map.IMap) 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