use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheConfigBuilderHelper method queryCachePredicateHandler.
private void queryCachePredicateHandler(Node childNode, QueryCacheConfig queryCacheConfig) {
NamedNodeMap predicateAttributes = childNode.getAttributes();
String predicateType = getTextContent(predicateAttributes.getNamedItem("type"));
String textContent = getTextContent(childNode);
PredicateConfig predicateConfig = new PredicateConfig();
if ("class-name".equals(predicateType)) {
predicateConfig.setClassName(textContent);
} else if ("sql".equals(predicateType)) {
predicateConfig.setSql(textContent);
}
queryCacheConfig.setPredicateConfig(predicateConfig);
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheXmlConfigBuilderHelper method queryCachePredicateHandler.
protected void queryCachePredicateHandler(Node childNode, QueryCacheConfig queryCacheConfig) {
String predicateType = getTextContent(getNamedItemNode(childNode, "type"));
String textContent = getTextContent(childNode);
PredicateConfig predicateConfig = new PredicateConfig();
if (matches("class-name", predicateType)) {
predicateConfig.setClassName(textContent);
} else if (matches("sql", predicateType)) {
predicateConfig.setSql(textContent);
}
queryCacheConfig.setPredicateConfig(predicateConfig);
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCachePredicateConfigTest method test_whenClassNameIsSet.
@Test
public void test_whenClassNameIsSet() {
String mapName = randomString();
String cacheName = randomString();
Config config = new Config();
MapConfig mapConfig = config.getMapConfig(mapName);
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
predicateConfig.setClassName("com.hazelcast.map.impl.querycache.TestPredicate");
mapConfig.addQueryCacheConfig(cacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Employee> map = getMap(node, mapName);
for (int i = 0; i < 15; i++) {
map.put(i, new Employee(i));
}
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
assertEquals(0, cache.size());
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCache_with_attribute_inPredicate.
@Test
public void testQueryCache_with_attribute_inPredicate() {
String ATTRIBUTE_NAME = "booleanAttribute";
Config config = new Config();
config.getMapConfig(mapName).addQueryCacheConfig(new QueryCacheConfig(cacheName).setIncludeValue(true).setPredicateConfig(new PredicateConfig(Predicates.equal(ATTRIBUTE_NAME, true)))).addAttributeConfig(new AttributeConfig().setExtractorClassName(EvenNumberEmployeeValueExtractor.class.getName()).setName(ATTRIBUTE_NAME));
IMap<Integer, Employee> map = getIMap(config);
QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
populateMap(map, 100);
assertQueryCacheSizeEventually(50, queryCache);
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class AbstractDynamicConfigGeneratorTest method testMap.
// UTILITY - TESTS
private void testMap(MapStoreConfig mapStoreConfig) {
AttributeConfig attrConfig = new AttributeConfig().setName("power").setExtractorClassName("com.car.PowerExtractor");
EvictionConfig evictionConfig1 = new EvictionConfig().setSize(10).setMaxSizePolicy(MaxSizePolicy.FREE_NATIVE_MEMORY_SIZE);
IndexConfig indexConfig = new IndexConfig().addAttribute("attribute").setType(IndexType.SORTED);
EntryListenerConfig listenerConfig = new EntryListenerConfig("com.hazelcast.entrylistener", false, false);
EvictionConfig evictionConfig2 = new EvictionConfig().setMaxSizePolicy(MaxSizePolicy.FREE_NATIVE_MEMORY_SIZE).setSize(100).setComparatorClassName("comparatorClassName").setEvictionPolicy(EvictionPolicy.LRU);
PredicateConfig predicateConfig1 = new PredicateConfig();
predicateConfig1.setClassName("className");
PredicateConfig predicateConfig2 = new PredicateConfig();
predicateConfig2.setSql("sqlQuery");
QueryCacheConfig queryCacheConfig1 = new QueryCacheConfig().setName("queryCache1").setPredicateConfig(predicateConfig1).addEntryListenerConfig(listenerConfig).setBatchSize(230).setDelaySeconds(20).setPopulate(false).setBufferSize(8).setInMemoryFormat(InMemoryFormat.BINARY).setEvictionConfig(evictionConfig2).setIncludeValue(false).setCoalesce(false).addIndexConfig(indexConfig);
QueryCacheConfig queryCacheConfig2 = new QueryCacheConfig().setName("queryCache2").setPredicateConfig(predicateConfig2).addEntryListenerConfig(listenerConfig).setBatchSize(500).setDelaySeconds(10).setPopulate(true).setBufferSize(10).setInMemoryFormat(InMemoryFormat.OBJECT).setEvictionConfig(evictionConfig2).setIncludeValue(true).setCoalesce(true).addIndexConfig(indexConfig);
MapConfig expectedConfig = newMapConfig().setName("carMap").setEvictionConfig(evictionConfig1).setInMemoryFormat(InMemoryFormat.NATIVE).setMetadataPolicy(MetadataPolicy.CREATE_ON_UPDATE).setMaxIdleSeconds(100).setTimeToLiveSeconds(1000).setCacheDeserializedValues(CacheDeserializedValues.ALWAYS).setStatisticsEnabled(true).setPerEntryStatsEnabled(false).setReadBackupData(true).setBackupCount(2).setAsyncBackupCount(3).setMapStoreConfig(mapStoreConfig).setWanReplicationRef(wanReplicationRef()).setPartitioningStrategyConfig(new PartitioningStrategyConfig("partitionStrategyClass")).setMerkleTreeConfig(merkleTreeConfig()).setEventJournalConfig(eventJournalConfig()).setDataPersistenceConfig(dataPersistenceConfig()).addEntryListenerConfig(listenerConfig).setIndexConfigs(singletonList(indexConfig)).addAttributeConfig(attrConfig).setPartitionLostListenerConfigs(singletonList(new MapPartitionLostListenerConfig("partitionLostListener")));
expectedConfig.setQueryCacheConfigs(asList(queryCacheConfig1, queryCacheConfig2));
Config config = new Config().addMapConfig(expectedConfig);
Config decConfig = getNewConfigViaGenerator(config);
MapConfig actualConfig = decConfig.getMapConfig("carMap");
AttributeConfig decAttrConfig = actualConfig.getAttributeConfigs().get(0);
assertEquals(attrConfig.getName(), decAttrConfig.getName());
assertEquals(attrConfig.getExtractorClassName(), decAttrConfig.getExtractorClassName());
ConfigCompatibilityChecker.checkMapConfig(expectedConfig, actualConfig);
}
Aggregations