use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheListenerTest method published_event_contains_key_when_include_value_is_false.
@Test
public void published_event_contains_key_when_include_value_is_false() {
CountDownLatch waitEventLatch = new CountDownLatch(1);
AtomicReference<EntryEvent<Integer, Employee>> eventObject = new AtomicReference<>();
MapConfig mapConfig = new MapConfig(mapName);
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig((EntryAddedListener<Integer, Employee>) event -> {
eventObject.set(event);
waitEventLatch.countDown();
}, true, false));
mapConfig.addQueryCacheConfig(queryCacheConfig);
Config config = new Config();
config.addMapConfig(mapConfig);
IMap<Integer, Employee> map = getIMap(config);
// trigger creation of the query cache
map.getQueryCache(cacheName);
map.put(1, new Employee(1));
assertOpenEventually(waitEventLatch);
assertEquals(1, eventObject.get().getKey().intValue());
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheNoEventLossTest method newConfig.
private Config newConfig() {
QueryCacheConfig queryCacheConfig = new QueryCacheConfig().setName(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(Predicates.alwaysTrue()));
MapConfig mapConfig = new MapConfig(MAP_NAME).addQueryCacheConfig(queryCacheConfig);
return smallInstanceConfig().addMapConfig(mapConfig);
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCachePredicateConfigTest method test_whenSqlIsSet.
@Test
public void test_whenSqlIsSet() {
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.setSql("id > 10");
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(4, cache.size());
}
use of com.hazelcast.config.PredicateConfig in project hazelcast by hazelcast.
the class QueryCacheBasicTest method setup.
// setup a map with 2 query caches, same predicate, one includes values, the other excludes values
@Before
public void setup() {
Config config = new Config();
config.getMapConfig(TEST_MAP_NAME).addQueryCacheConfig(new QueryCacheConfig(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(predicate)).setIncludeValue(includeValues));
if (useNearCache) {
config.getMapConfig(TEST_MAP_NAME).setNearCacheConfig(new NearCacheConfig().setCacheLocalEntries(true));
}
config.setProperty(MapEventPublisherImpl.LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES.getName(), Boolean.toString(useQueryCacheNaturalFilteringStrategy));
instance = createHazelcastInstance(config);
map = getMap(instance, "EntryListenerEventTypesTestMap");
queryCache = map.getQueryCache(QUERY_CACHE_NAME);
}
use of com.hazelcast.config.PredicateConfig 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());
}
Aggregations