use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testEntrySet.
@Test
public void testEntrySet() {
int count = 1;
String cacheName = randomString();
populateMap(map, count);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
cache.addIndex("id", true);
populateMap(map, count, 2 * count);
// just choose arbitrary numbers for querying in order to prove whether #keySet with predicate is correctly working
int equalsOrBiggerThan = 0;
int expectedSize = 2 * count - equalsOrBiggerThan;
assertEntrySetSizeEventually(expectedSize, new SqlPredicate("id >= " + equalsOrBiggerThan), cache);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testEntrySet_whenIncludeValueFalse.
@Test
public void testEntrySet_whenIncludeValueFalse() throws Exception {
int count = 111;
String cacheName = randomString();
populateMap(map, count);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
cache.addIndex("id", true);
removeEntriesFromMap(map, 17, count);
// just choose arbitrary numbers to prove whether #entrySet with predicate is working
int smallerThan = 17;
int expectedSize = 0;
assertEntrySetSizeEventually(expectedSize, new SqlPredicate("id < " + smallerThan), cache);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testValues.
@Test
public void testValues() {
int count = 111;
String cacheName = randomString();
populateMap(map, count);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
cache.addIndex("id", true);
populateMap(map, count, 2 * count);
// just choose arbitrary numbers for querying in order to prove whether #keySet with predicate is correctly working
int equalsOrBiggerThan = 27;
int expectedSize = 2 * count - equalsOrBiggerThan;
assertValuesSizeEventually(expectedSize, new SqlPredicate("id >= " + equalsOrBiggerThan), cache);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
String mapName = randomString();
String queryCacheName = randomString();
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(1111);
queryCacheConfig.setDelaySeconds(3);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
mapConfig.setBackupCount(0);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
setTestSequencer(node, 9);
setTestSequencer(node2, 9);
IMap<Integer, Integer> map = getMap(node, mapName);
node2.getMap(mapName);
//set test sequencer to subscribers.
int count = 30;
final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
queryCache.tryRecover();
}
}, false);
for (int i = 0; i < count; i++) {
map.put(i, i);
}
AssertTask task = new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
};
assertTrueEventually(task);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testEntrySet_withIndexedKeys_whenIncludeValueFalse.
@Test
public void testEntrySet_withIndexedKeys_whenIncludeValueFalse() {
int count = 111;
String cacheName = randomString();
populateMap(map, count);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
// here adding key index. (key --> integer; value --> Employee)
cache.addIndex("__key", true);
removeEntriesFromMap(map, 17, count);
// just choose arbitrary numbers to prove whether #entrySet with predicate is working
int smallerThan = 17;
int expectedSize = 17;
assertEntrySetSizeEventually(expectedSize, new SqlPredicate("__key < " + smallerThan), cache);
}
Aggregations