Search in sources :

Example 36 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_evictAll.

@Test
public void testQueryCacheCleared_afterCalling_IMap_evictAll() {
    final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 1000);
    IFunction evictAll = (ignored) -> {
        map.evictAll();
        return null;
    };
    assertQueryCacheSizeEventually(0, evictAll, queryCache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AttributeConfig(com.hazelcast.config.AttributeConfig) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) PredicateConfig(com.hazelcast.config.PredicateConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) ValueCollector(com.hazelcast.query.extractor.ValueCollector) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Employee(com.hazelcast.map.impl.querycache.utils.Employee) Predicates(com.hazelcast.query.Predicates) QueryCache(com.hazelcast.map.QueryCache) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) EntryAdapter(com.hazelcast.core.EntryAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Employee(com.hazelcast.map.impl.querycache.utils.Employee) IFunction(com.hazelcast.core.IFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheTest method testDestroy_emptiesQueryCache.

@Test
public void testDestroy_emptiesQueryCache() {
    int entryCount = 1000;
    final CountDownLatch numberOfAddEvents = new CountDownLatch(entryCount);
    IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, (EntryAddedListener<Integer, Employee>) (event) -> numberOfAddEvents.countDown(), TRUE_PREDICATE, false);
    populateMap(map, entryCount);
    assertOpenEventually(numberOfAddEvents);
    queryCache.destroy();
    assertEquals(0, queryCache.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AttributeConfig(com.hazelcast.config.AttributeConfig) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) PredicateConfig(com.hazelcast.config.PredicateConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) ValueCollector(com.hazelcast.query.extractor.ValueCollector) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Employee(com.hazelcast.map.impl.querycache.utils.Employee) Predicates(com.hazelcast.query.Predicates) QueryCache(com.hazelcast.map.QueryCache) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) EntryAdapter(com.hazelcast.core.EntryAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Employee(com.hazelcast.map.impl.querycache.utils.Employee) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 38 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheTest method testWithInitialPopulation.

private void testWithInitialPopulation(boolean enableInitialPopulation, int expectedSize, int numberOfElementsToPut) {
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setPopulate(enableInitialPopulation);
    Config config = new Config();
    config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
    IMap<Integer, Employee> map = getIMap(config);
    populateMap(map, numberOfElementsToPut);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    assertEquals(expectedSize, queryCache.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config)

Example 39 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheDataSyncWithMapTest method test_map_wide_event.

private void test_map_wide_event(MethodName methodName) {
    for (int i = 0; i < 3; i++) {
        callMethod(methodName);
        int start = i * 10;
        for (int j = start; j < start + 10; j++) {
            map.put(j, new Employee(j));
        }
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int mapSize = map.size();
            int queryCacheSize = queryCache.size();
            String msg = "query cache should have same size with underlying imap but" + " its size found %d while map size is %d";
            assertEquals(format(msg, queryCacheSize, mapSize), mapSize, queryCacheSize);
            Collection<Employee> valuesInMap = map.values();
            Collection<Employee> valuesInQueryCache = queryCache.values();
            String msg2 = "valuesInMap %s but valuesInQueryCache %s";
            assertTrue(format(msg2, valuesInMap, valuesInQueryCache), valuesInMap.containsAll(valuesInQueryCache));
        }
    });
}
Also used : Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection)

Example 40 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheMethodsWithPredicateTest method testKeySetIsNotBackedByQueryCache.

@Test
public void testKeySetIsNotBackedByQueryCache() {
    int count = 111;
    IMap<Employee, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    for (int i = 0; i < count; i++) {
        map.put(new Employee(i), new Employee(i));
    }
    Predicate<Employee, Employee> predicate = Predicates.lessThan("id", count);
    QueryCache<Employee, Employee> cache = map.getQueryCache(cacheName);
    cache.addIndex(IndexType.SORTED, "id");
    for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
        entry.getValue().setAge(Employee.MAX_AGE + 1);
    }
    for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
        assertNotEquals(Employee.MAX_AGE + 1, entry.getValue().getAge());
    }
}
Also used : Employee(com.hazelcast.map.impl.querycache.utils.Employee) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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