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());
}
}
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());
}
}
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());
}
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);
}
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);
}
Aggregations