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);
}
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;
}
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;
}
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();
}
}
}
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;
}
Aggregations