use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheMethodsWithPredicateTest method test_entrySet_withIndexedKeys_whenIncludeValueFalse.
@Test
public void test_entrySet_withIndexedKeys_whenIncludeValueFalse() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance instance = getInstance();
IMap<Integer, Employee> map = instance.getMap(mapName);
int count = 111;
for (int i = 0; i < count; i++) {
map.put(i, new Employee(i));
}
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
// here adding key index. (key --> integer; value --> Employee)
cache.addIndex(IndexType.SORTED, "__key");
for (int i = 17; i < count; i++) {
map.remove(i);
}
// ust choose arbitrary numbers to prove whether #entrySet with predicate is working
int smallerThan = 17;
int expectedSize = 17;
assertEntrySetSizeEventually(expectedSize, Predicates.sql("__key < " + smallerThan), cache);
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheMethodsWithPredicateTest method assertValuesSizeEventually.
private void assertValuesSizeEventually(final int expectedSize, final Predicate predicate, final QueryCache<Integer, Employee> cache) {
AssertTask task = new AssertTask() {
@Override
public void run() throws Exception {
int size = cache.size();
Collection<Employee> values = cache.values(predicate);
assertEquals("cache size = " + size, expectedSize, values.size());
}
};
assertTrueEventually(task, DEFAULT_TEST_TIMEOUT);
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenerShouldBeRegistered_whenConfiguredProgrammatically.
@Test
public void listenerShouldBeRegistered_whenConfiguredProgrammatically() {
MapConfig mapConfig = new MapConfig(mapName);
final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig(listener, true, true));
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);
populateMap(map, 100);
assertTrueEventually(() -> assertEquals(100, listener.getAddedEventCount()));
assertTrueAllTheTime(() -> assertEquals(100, listener.getAddedEventCount()), 5);
}
use of com.hazelcast.map.impl.querycache.utils.Employee 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.map.impl.querycache.utils.Employee 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());
}
Aggregations