Search in sources :

Example 1 with Employee

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()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with Employee

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()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with Employee

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());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryAdapter(com.hazelcast.core.EntryAdapter) MapEvent(com.hazelcast.map.MapEvent) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Employee

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());
    }
}
Also used : Employee(com.hazelcast.map.impl.querycache.utils.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with Employee

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);
}
Also used : Set(java.util.Set) Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Aggregations

Employee (com.hazelcast.map.impl.querycache.utils.Employee)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)35 QuickTest (com.hazelcast.test.annotation.QuickTest)35 Test (org.junit.Test)35 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)11 AssertTask (com.hazelcast.test.AssertTask)11 PredicateConfig (com.hazelcast.config.PredicateConfig)10 Config (com.hazelcast.config.Config)9 IMap (com.hazelcast.map.IMap)6 AttributeConfig (com.hazelcast.config.AttributeConfig)5 MapConfig (com.hazelcast.config.MapConfig)4 EntryAdapter (com.hazelcast.core.EntryAdapter)4 EntryEvent (com.hazelcast.core.EntryEvent)4 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)4 Set (java.util.Set)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)3 IFunction (com.hazelcast.core.IFunction)3