Search in sources :

Example 1 with PredicateBuilderImpl

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);
    }
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) HashMap(java.util.HashMap) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) Predicate(com.hazelcast.query.Predicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) PredicateBuilderImpl(com.hazelcast.query.impl.PredicateBuilderImpl) EntryView(com.hazelcast.core.EntryView)

Aggregations

Config (com.hazelcast.config.Config)1 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 EvictionConfig (com.hazelcast.config.EvictionConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 EntryView (com.hazelcast.core.EntryView)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Predicate (com.hazelcast.query.Predicate)1 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)1 Employee (com.hazelcast.query.SampleTestObjects.Employee)1 PredicateBuilderImpl (com.hazelcast.query.impl.PredicateBuilderImpl)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1