Search in sources :

Example 26 with QueryCacheConfig

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

the class ClientQueryCacheIndexTest method test_keySet_withPredicate_whenValuesAreNotCached.

@Test
public void test_keySet_withPredicate_whenValuesAreNotCached() {
    String mapName = randomString();
    String cacheName = randomString();
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setDelaySeconds(1);
    queryCacheConfig.setBatchSize(3);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    // populate map before construction of query cache
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    cache.addIndex("__key", true);
    // populate map after construction of query cache
    for (int i = putCount; i < 2 * putCount; i++) {
        map.put(i, new Employee(i));
    }
    // just choose arbitrary numbers for querying in order to prove whether #keySet with predicate is correctly working
    int equalsOrBiggerThan = 27;
    int expectedSize = 2 * putCount - equalsOrBiggerThan;
    assertKeySetSizeEventually(expectedSize, new SqlPredicate("__key >= " + equalsOrBiggerThan), cache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with QueryCacheConfig

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

the class AbstractQueryCacheEndToEndConstructor method initQueryCacheConfig.

protected QueryCacheConfig initQueryCacheConfig(QueryCacheRequest request) {
    Predicate predicate = request.getPredicate();
    QueryCacheConfig queryCacheConfig;
    if (predicate == null) {
        queryCacheConfig = getOrNullQueryCacheConfig(mapName, request.getUserGivenCacheName());
    } else {
        queryCacheConfig = getOrCreateQueryCacheConfig(mapName, request.getUserGivenCacheName());
        queryCacheConfig.setIncludeValue(request.isIncludeValue());
        queryCacheConfig.getPredicateConfig().setImplementation(predicate);
    }
    if (queryCacheConfig == null) {
        return null;
    }
    // init some required parameters
    this.includeValue = queryCacheConfig.isIncludeValue();
    this.predicate = queryCacheConfig.getPredicateConfig().getImplementation();
    return queryCacheConfig;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate)

Example 28 with QueryCacheConfig

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

the class AbstractQueryCacheEndToEndConstructor method createNew.

/**
     * Here order of method calls should not change.
     */
@Override
public final InternalQueryCache createNew(String arg) {
    try {
        QueryCacheConfig queryCacheConfig = initQueryCacheConfig(request);
        if (queryCacheConfig == null) {
            return NULL_QUERY_CACHE;
        }
        queryCache = createUnderlyingQueryCache(request);
        // this is users listener which can be given as a parameter
        // when calling `IMap.getQueryCache` method
        addListener(request);
        AccumulatorInfo info = createAccumulatorInfo(queryCacheConfig, mapName, request.getCacheName(), predicate);
        addInfoToSubscriberContext(info);
        info.setPublishable(true);
        createSubscriberAccumulator(info);
        createPublisherAccumulator(info);
    } catch (Throwable throwable) {
        removeQueryCacheConfig(mapName, request.getUserGivenCacheName());
        throw rethrow(throwable);
    }
    return queryCache;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) AccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo) AccumulatorInfo.createAccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo.createAccumulatorInfo)

Example 29 with QueryCacheConfig

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

the class NodeQueryCacheConfigurator method removeConfiguration.

@Override
public void removeConfiguration(String mapName, String cacheName) {
    MapConfig mapConfig = config.getMapConfig(mapName);
    List<QueryCacheConfig> queryCacheConfigs = mapConfig.getQueryCacheConfigs();
    if (queryCacheConfigs == null || queryCacheConfigs.isEmpty()) {
        return;
    }
    Iterator<QueryCacheConfig> iterator = queryCacheConfigs.iterator();
    while (iterator.hasNext()) {
        QueryCacheConfig config = iterator.next();
        if (config.getName().equals(cacheName)) {
            iterator.remove();
        }
    }
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 30 with QueryCacheConfig

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

the class NodeQueryCacheConfigurator method getOrCreateConfiguration.

@Override
public QueryCacheConfig getOrCreateConfiguration(String mapName, String cacheName) {
    MapConfig mapConfig = config.getMapConfig(mapName);
    List<QueryCacheConfig> queryCacheConfigs = mapConfig.getQueryCacheConfigs();
    Iterator<QueryCacheConfig> iterator = queryCacheConfigs.iterator();
    while (iterator.hasNext()) {
        QueryCacheConfig config = iterator.next();
        if (config.getName().equals(cacheName)) {
            setPredicateImpl(config);
            setEntryListener(mapName, cacheName, config);
            return config;
        }
    }
    QueryCacheConfig newConfig = new QueryCacheConfig(cacheName);
    queryCacheConfigs.add(newConfig);
    return newConfig;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)31 MapConfig (com.hazelcast.config.MapConfig)16 Config (com.hazelcast.config.Config)14 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 ClientConfig (com.hazelcast.client.config.ClientConfig)6 SqlPredicate (com.hazelcast.query.SqlPredicate)6 PredicateConfig (com.hazelcast.config.PredicateConfig)5 AssertTask (com.hazelcast.test.AssertTask)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)3 EventLostEvent (com.hazelcast.map.EventLostEvent)3 QueryCache (com.hazelcast.map.QueryCache)3 EventLostListener (com.hazelcast.map.listener.EventLostListener)3 Employee (com.hazelcast.mapreduce.helpers.Employee)3 Before (org.junit.Before)3 EvictionConfig (com.hazelcast.config.EvictionConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2