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 XmlClientConfigBuilderTest method testQueryCacheFullConfig.
@Test
public void testQueryCacheFullConfig() throws Exception {
QueryCacheConfig queryCacheConfig = clientConfig.getQueryCacheConfigs().get("map-name").get("query-cache-name");
EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
assertEquals("query-cache-name", queryCacheConfig.getName());
assertTrue(entryListenerConfig.isIncludeValue());
assertFalse(entryListenerConfig.isLocal());
assertEquals("com.hazelcast.examples.EntryListener", entryListenerConfig.getClassName());
assertTrue(queryCacheConfig.isIncludeValue());
assertEquals(1, queryCacheConfig.getBatchSize());
assertEquals(16, queryCacheConfig.getBufferSize());
assertEquals(0, queryCacheConfig.getDelaySeconds());
assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(EvictionConfig.MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaximumSizePolicy());
assertEquals(10000, queryCacheConfig.getEvictionConfig().getSize());
assertEquals(InMemoryFormat.BINARY, queryCacheConfig.getInMemoryFormat());
assertFalse(queryCacheConfig.isCoalesce());
assertTrue(queryCacheConfig.isPopulate());
for (MapIndexConfig mapIndexConfig : queryCacheConfig.getIndexConfigs()) {
assertEquals("name", mapIndexConfig.getAttribute());
assertFalse(mapIndexConfig.isOrdered());
}
assertEquals("com.hazelcast.examples.ExamplePredicate", queryCacheConfig.getPredicateConfig().getClassName());
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheTest method initConfig.
private void initConfig(String mapName, String cacheName, boolean enableInitialPopulation) {
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
queryCacheConfig.setPopulate(enableInitialPopulation).getPredicateConfig().setImplementation(TRUE_PREDICATE);
MapConfig mapConfig = new MapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
config.addMapConfig(mapConfig);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class NodeQueryCacheConfigurator method getOrCreateConfiguration.
@Override
public QueryCacheConfig getOrCreateConfiguration(String mapName, String cacheName, String cacheId) {
MapConfig mapConfig = config.getMapConfig(mapName);
QueryCacheConfig queryCacheConfig = findQueryCacheConfigFromMapConfig(mapConfig, cacheName);
if (queryCacheConfig != null) {
setPredicateImpl(queryCacheConfig);
setEntryListener(mapName, cacheId, queryCacheConfig);
return queryCacheConfig;
}
QueryCacheConfig newConfig = new QueryCacheConfig(cacheName);
mapConfig.getQueryCacheConfigs().add(newConfig);
return newConfig;
}
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;
}
queryCacheConfigs.removeIf(config -> config.getName().equals(cacheName));
}
Aggregations