Search in sources :

Example 6 with Employee

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

the class QueryCacheMethodsWithPredicateTest method testKeySetIsNotBackedByQueryCache_nonIndexedAttribute.

@Test
public void testKeySetIsNotBackedByQueryCache_nonIndexedAttribute() {
    Assume.assumeTrue(inMemoryFormat != OBJECT);
    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("salary", Employee.MAX_SALARY);
    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)

Example 7 with Employee

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

the class QueryCacheMethodsWithPredicateTest method testValuesAreNotBackedByQueryCache.

@Test
public void testValuesAreNotBackedByQueryCache() {
    int count = 111;
    IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    populateMap(map, count);
    Predicate<Integer, Employee> predicate = Predicates.lessThan("id", count);
    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 8 with Employee

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

the class QueryCachePredicateConfigTest method test_whenClassNameIsSet.

@Test
public void test_whenClassNameIsSet() {
    String mapName = randomString();
    String cacheName = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
    predicateConfig.setClassName("com.hazelcast.map.impl.querycache.TestPredicate");
    mapConfig.addQueryCacheConfig(cacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Employee> map = getMap(node, mapName);
    for (int i = 0; i < 15; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
    assertEquals(0, cache.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with Employee

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

the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.

@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
    final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 1000);
    IFunction clear = (ignored) -> {
        map.clear();
        return null;
    };
    assertQueryCacheSizeEventually(0, clear, 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 10 with Employee

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

the class QueryCacheTest method testQueryCache_with_attribute_inPredicate.

@Test
public void testQueryCache_with_attribute_inPredicate() {
    String ATTRIBUTE_NAME = "booleanAttribute";
    Config config = new Config();
    config.getMapConfig(mapName).addQueryCacheConfig(new QueryCacheConfig(cacheName).setIncludeValue(true).setPredicateConfig(new PredicateConfig(Predicates.equal(ATTRIBUTE_NAME, true)))).addAttributeConfig(new AttributeConfig().setExtractorClassName(EvenNumberEmployeeValueExtractor.class.getName()).setName(ATTRIBUTE_NAME));
    IMap<Integer, Employee> map = getIMap(config);
    QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 100);
    assertQueryCacheSizeEventually(50, queryCache);
}
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) PredicateConfig(com.hazelcast.config.PredicateConfig) AttributeConfig(com.hazelcast.config.AttributeConfig) 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