use of com.hazelcast.query.impl.PredicateBuilderImpl in project hazelcast by hazelcast.
the class EvictionTest method testMaxIdle_readThroughIndex.
private void testMaxIdle_readThroughIndex(IndexType type) {
String mapName = randomMapName();
Config config = getConfig();
config.getMapConfig("default").setPerEntryStatsEnabled(true);
// "disable" the cleaner task
config.setProperty(PROP_TASK_PERIOD_SECONDS, Integer.toString(MAX_VALUE));
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Employee> map = node.getMap(mapName);
map.addIndex(type, "city");
int entryCount = 5;
Map<Integer, Long> lastAccessTimes = new HashMap<>();
for (int i = 0; i < entryCount; ++i) {
String cityName = i % 2 == 0 ? "cityname" : null;
Employee emp = new Employee(i, "name" + i, cityName, 0, true, i);
map.put(i, emp, 0L, SECONDS, 60L, SECONDS);
// we do get to set the last access time
map.get(i);
EntryView view = map.getEntryView(i);
long lastAccessTime = view.getLastAccessTime();
assertTrue(lastAccessTime > 0);
lastAccessTimes.put(i, lastAccessTime);
}
sleepAtLeastSeconds(1);
EntryObject entryObject = new PredicateBuilderImpl().getEntryObject();
Predicate predicateCityNull = entryObject.get("city").isNull();
Collection<Employee> valuesNullCity = map.values(predicateCityNull);
Collection<Employee> valuesNotNullCity = map.values(Predicates.equal("city", "cityname"));
assertEquals(entryCount, valuesNullCity.size() + valuesNotNullCity.size());
// check that evaluating the predicate didn't update the last access time of the returned records
for (int i = 0; i < entryCount; ++i) {
EntryView view = map.getEntryView(i);
assertNotNull(view);
long lastAccessTime = view.getLastAccessTime();
long prevLastAccessTime = lastAccessTimes.get(i);
assertTrue("lastAccessTime=" + lastAccessTime + ", prevLastAccessTime=" + prevLastAccessTime, lastAccessTime == prevLastAccessTime);
}
}
Aggregations