use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testKeySet_onIndexedField.
@Test
public void testKeySet_onIndexedField() {
int count = 111;
populateMap(map, count);
String cacheName = randomString();
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;
assertKeySetSizeEventually(expectedSize, new SqlPredicate("id >= " + equalsOrBiggerThan), cache);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
String mapName = randomMapName("map");
String queryCacheName = randomMapName("cache");
Config config = new Config();
config.setProperty(PARTITION_COUNT.getName(), "1");
factory.newHazelcastInstance(config);
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(1111);
queryCacheConfig.setDelaySeconds(3);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> map = client.getMap(mapName);
// set test sequencer to subscriber
int count = 30;
setTestSequencer(map, 9);
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);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
});
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCache.
private void testQueryCache(boolean includeValue) {
String mapName = randomString();
String queryCacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
for (int i = 0; i < 50; i++) {
map.put(i, i);
}
Predicate<Integer, Integer> predicate = new SqlPredicate("this > 5 AND this < 100");
QueryCache<Integer, Integer> cache = map.getQueryCache(queryCacheName, predicate, includeValue);
for (int i = 50; i < 100; i++) {
map.put(i, i);
}
int expected = 94;
assertQueryCacheSize(expected, cache);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientQueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
String mapName = randomString();
String queryCacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, new SqlPredicate("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, queryCache.size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of add events wrong!", 9, countAddEvent.get());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
}
});
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientQueryCacheIndexTest method test_values_withoutIndex_whenValuesCached.
@Test
public void test_values_withoutIndex_whenValuesCached() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Employee> map = client.getMap(mapName);
int putCount = 111;
for (int i = 0; i < putCount; i++) {
map.put(i, new Employee(i));
}
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
for (int i = 17; i < putCount; i++) {
map.remove(i);
}
// just choose arbitrary numbers to prove whether #entrySet with predicate is working
int smallerThan = 17;
int expectedSize = 17;
assertValuesSizeEventually(expectedSize, new SqlPredicate("__key < " + smallerThan), cache);
}
Aggregations