use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenKey_withPredicate_whenNoLongerMatching.
@Test
public void listenKey_withPredicate_whenNoLongerMatching() {
IMap<Integer, Employee> map = getIMapWithDefaultConfig(SQL_PREDICATE_LT, useNaturalFilteringStrategy);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
Employee employee = new Employee(0);
map.put(0, employee);
final QueryCacheRemovalListener listener = new QueryCacheRemovalListener();
cache.addEntryListener(listener, true);
employee = new Employee(200);
map.put(0, employee);
assertTrueEventually(() -> assertEquals(1, listener.getRemovedEventCount()));
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenKey_withPredicate_whenMatching.
@Test
public void listenKey_withPredicate_whenMatching() {
IMap<Integer, Employee> map = getIMapWithDefaultConfig(SQL_PREDICATE_LT, useNaturalFilteringStrategy);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
Employee employee = new Employee(200);
map.put(0, employee);
final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
cache.addEntryListener(listener, true);
employee = new Employee(0);
map.put(0, employee);
sleepAtLeastSeconds(5);
assertTrueEventually(() -> assertEquals(1, listener.getAddedEventCount()));
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared.
@Test
public void listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared() {
IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE, useNaturalFilteringStrategy);
int entryCount = 1000;
final AtomicInteger clearAllEventCount = new AtomicInteger();
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {
@Override
public void mapCleared(MapEvent e) {
clearAllEventCount.incrementAndGet();
}
}, TRUE_PREDICATE, false);
populateMap(map, entryCount);
assertQueryCacheSizeEventually(entryCount, queryCache);
map.clear();
assertTrueEventually(() -> {
// expecting at least 1 event
assertTrue(clearAllEventCount.get() >= 1);
assertEquals(0, queryCache.size());
});
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testValuesAreNotBackedByQueryCache_nonIndexedAttribute.
@Test
public void testValuesAreNotBackedByQueryCache_nonIndexedAttribute() {
Assume.assumeTrue(inMemoryFormat != OBJECT);
int count = 111;
IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
populateMap(map, count);
Predicate<Integer, Employee> predicate = Predicates.lessThan("salary", Employee.MAX_SALARY);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
cache.addIndex(IndexType.SORTED, "id");
for (Employee employee : cache.values(predicate)) {
employee.setAge(Employee.MAX_AGE + 1);
}
for (Employee employee : cache.values(predicate)) {
assertNotEquals(Employee.MAX_AGE + 1, employee.getAge());
}
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method assertEntrySetSizeEventually.
private void assertEntrySetSizeEventually(final int expectedSize, final Predicate predicate, final QueryCache<Integer, Employee> cache) {
AssertTask task = () -> {
int size = cache.size();
Set<Map.Entry<Integer, Employee>> entries = cache.entrySet(predicate);
assertEquals("cache size = " + size, expectedSize, entries.size());
};
assertTrueEventually(task);
}
Aggregations