Search in sources :

Example 71 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class QueryCacheTest method testQueryCache.

@SuppressWarnings("unchecked")
private void testQueryCache(boolean includeValue) {
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setIncludeValue(includeValue);
    Config config = new Config();
    config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
    IMap<Integer, Integer> map = getIMap(config);
    String cacheName = randomString();
    for (int i = 0; i < 50; i++) {
        map.put(i, i);
    }
    Predicate<Integer, Integer> predicate = Predicates.sql("this > 5 AND this < 100");
    QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, predicate, includeValue);
    for (int i = 50; i < 100; i++) {
        map.put(i, i);
    }
    int expected = 94;
    assertQueryCacheSizeEventually(expected, cache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config)

Example 72 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class QueryCacheTest method testWithInitialPopulation.

private void testWithInitialPopulation(boolean enableInitialPopulation, int expectedSize, int numberOfElementsToPut) {
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setPopulate(enableInitialPopulation);
    Config config = new Config();
    config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
    IMap<Integer, Employee> map = getIMap(config);
    populateMap(map, numberOfElementsToPut);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    assertEquals(expectedSize, queryCache.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config)

Example 73 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class QueryCacheTest method testQueryCache_withLocalListener.

@Test
public void testQueryCache_withLocalListener() {
    Config config = new Config().setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
    IMap<Integer, Integer> map = getIMap(config);
    for (int i = 0; i < 30; i++) {
        map.put(i, i);
    }
    final AtomicInteger countAddEvent = new AtomicInteger();
    final AtomicInteger countRemoveEvent = new AtomicInteger();
    final QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {

        @Override
        public void entryAdded(EntryEvent event) {
            countAddEvent.incrementAndGet();
        }

        @Override
        public void entryRemoved(EntryEvent event) {
            countRemoveEvent.incrementAndGet();
        }
    }, SQL_PREDICATE, true);
    for (int i = 0; i < 30; i++) {
        map.remove(i);
    }
    assertTrueEventually(() -> assertEquals(0, queryCache.size()));
    assertTrueEventually(() -> assertEquals("Count of add events wrong!", 9, countAddEvent.get()));
    assertTrueEventually(() -> assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeConfig(com.hazelcast.config.AttributeConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig 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)

Example 75 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class QueryCacheIndexConfigTest method testIndexConfigIsRespected.

@Test
public void testIndexConfigIsRespected() {
    IndexConfig indexConfig = IndexUtils.createTestIndexConfig(IndexType.SORTED, "field");
    final Config config = new Config();
    final MapConfig mapConfig = new MapConfig("map").addQueryCacheConfig(new QueryCacheConfig().setName("query-cache").setPredicateConfig(new PredicateConfig(Predicates.alwaysTrue())).addIndexConfig(indexConfig));
    config.addMapConfig(mapConfig);
    final HazelcastInstance instance = createHazelcastInstance(config);
    final IMap<Object, Object> map = instance.getMap("map");
    final DefaultQueryCache<Object, Object> cache = (DefaultQueryCache<Object, Object>) map.getQueryCache("query-cache");
    assertNotNull(cache.indexes.getIndex(indexConfig.getName()));
    assertTrue(cache.indexes.getIndex(indexConfig.getName()).isOrdered());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)80 Config (com.hazelcast.config.Config)29 Test (org.junit.Test)29 QuickTest (com.hazelcast.test.annotation.QuickTest)28 MapConfig (com.hazelcast.config.MapConfig)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 PredicateConfig (com.hazelcast.config.PredicateConfig)17 ClientConfig (com.hazelcast.client.config.ClientConfig)15 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)14 AttributeConfig (com.hazelcast.config.AttributeConfig)8 Employee (com.hazelcast.map.impl.querycache.utils.Employee)8 Before (org.junit.Before)8 IndexConfig (com.hazelcast.config.IndexConfig)7 AssertTask (com.hazelcast.test.AssertTask)7 Map (java.util.Map)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 EvictionConfig (com.hazelcast.config.EvictionConfig)6 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 EventLostEvent (com.hazelcast.map.EventLostEvent)5