Search in sources :

Example 76 with QueryCacheConfig

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

the class QueryCacheConfigTest method testQueryCacheNameConfiguredWithWildCard.

@Test
public void testQueryCacheNameConfiguredWithWildCard() {
    QueryCacheConfig cacheConfig = new QueryCacheConfig();
    String mapNamePrefix = "MyMap";
    String mapNameNameWithWildcard = mapNamePrefix + "*";
    cacheConfig.setName("myCache");
    cacheConfig.getPredicateConfig().setSql("__key > 10");
    HazelcastInstance hazelcastInstance = createInstanceWithQueryCacheConfig(mapNameNameWithWildcard, cacheConfig);
    IMap<Integer, Integer> map1 = getMap(hazelcastInstance, mapNamePrefix + "_1");
    QueryCache<Integer, Integer> queryCache1 = map1.getQueryCache("myCache");
    assertNotNull(queryCache1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 77 with QueryCacheConfig

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

the class QueryCacheInMemoryFormatTest method testInMemoryFormat.

private void testInMemoryFormat(InMemoryFormat inMemoryFormat, int expectedDeserializationCount) {
    SerializableObject.deserializationCount.set(0);
    String mapName = randomString();
    String cacheName = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    cacheConfig.setInMemoryFormat(inMemoryFormat);
    PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
    predicateConfig.setSql("__key > -1");
    mapConfig.addQueryCacheConfig(cacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, SerializableObject> map = getMap(node, mapName);
    map.put(1, new SerializableObject());
    assertEquals(0, SerializableObject.deserializationCount.get());
    QueryCache<Integer, SerializableObject> cache = map.getQueryCache(cacheName);
    for (int i = 0; i < 10; i++) {
        cache.get(1);
        int expectedInitialCountInLoop = inMemoryFormat == BINARY ? i + 1 : 1;
        assertEquals("Error on iteration " + i, expectedInitialCountInLoop, SerializableObject.deserializationCount.get());
    }
    assertEquals(expectedDeserializationCount, SerializableObject.deserializationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) 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)

Example 78 with QueryCacheConfig

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

the class QueryCacheMapLoaderTest method getConfig.

private Config getConfig(String mapName, String cacheName) {
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setInMemoryFormat(inMemoryFormat);
    mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(mapLoader);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    mapConfig.addQueryCacheConfig(cacheConfig);
    return config;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig)

Example 79 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)

Example 80 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)

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