use of org.apache.ignite.cache.query.ScanQuery in project camel by apache.
the class IgniteCacheContinuousQueryTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry answer = super.createRegistry();
ScanQuery<Integer, Person> scanQuery1 = new ScanQuery<>(new IgniteBiPredicate<Integer, Person>() {
private static final long serialVersionUID = 1L;
@Override
public boolean apply(Integer key, Person person) {
return person.getId() > 50;
}
});
CacheEntryEventSerializableFilter<Integer, Person> remoteFilter = new CacheEntryEventSerializableFilter<Integer, IgniteCacheContinuousQueryTest.Person>() {
private static final long serialVersionUID = 5624973479995548199L;
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Person> event) throws CacheEntryListenerException {
return event.getValue().getId() > 150;
}
};
answer.bind("query1", scanQuery1);
answer.bind("remoteFilter1", remoteFilter);
return answer;
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCacheNodeJoinAbstractTest method testScanQuery.
/**
* @throws Exception If failed.
*/
public void testScanQuery() throws Exception {
final IgniteCache<Integer, Integer> cache = jcache(0);
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
final IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(1);
return null;
}
});
final AtomicBoolean stop = new AtomicBoolean();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ScanQuery qry = new ScanQuery();
while (!stop.get() && !fut.isDone()) cache.query(qry).getAll();
return null;
}
}, 10, "test-qry");
try {
fut.get(60_000);
} finally {
stop.set(true);
}
stopGrid(1);
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCacheBinaryObjectsScanSelfTest method testScanNoClasses.
/**
* @throws Exception If failed.
*/
public void testScanNoClasses() throws Exception {
Ignite client = grid("client");
IgniteCache<Object, Object> cache = client.cache("testCache");
List<Cache.Entry<Object, Object>> entries = cache.query(new ScanQuery<>()).getAll();
assertEquals(100, entries.size());
for (Cache.Entry<Object, Object> entry : entries) {
assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName());
assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName());
}
entries = new ArrayList<>();
int partCnt = client.affinity("testCache").partitions();
for (int i = 0; i < partCnt; i++) entries.addAll(cache.query(new ScanQuery<>(i)).getAll());
assertEquals(100, entries.size());
for (Cache.Entry<Object, Object> entry : entries) {
assertEquals(PERSON_KEY_CLS_NAME, entry.getKey().getClass().getName());
assertEquals(PERSON_CLS_NAME, entry.getValue().getClass().getName());
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method testContinuousQuery.
/**
* @throws Exception If failed.
*/
public void testContinuousQuery() throws Exception {
runInAllDataModes(new TestRunnable() {
@Override
public void run() throws Exception {
final AtomicInteger updCnt = new AtomicInteger();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setInitialQuery(new ScanQuery<>(new IgniteBiPredicate<Object, Object>() {
@Override
public boolean apply(Object key, Object val) {
return valueOf(key) >= 3;
}
}));
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Object, ? extends Object>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Object, ? extends Object> evt : evts) {
int v = valueOf(evt.getKey());
// Check filter.
assertTrue("v=" + v, v >= 10 && v < 15);
updCnt.incrementAndGet();
}
}
});
qry.setRemoteFilter(new TestCacheEntryEventSerializableFilter());
IgniteCache<Object, Object> cache = jcache();
for (int i = 0; i < 10; i++) cache.put(key(i), value(i));
try (QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry)) {
int cnt = 0;
for (Cache.Entry<Object, Object> e : cur) {
cnt++;
int val = valueOf(e.getKey());
assertTrue("v=" + val, val >= 3);
}
assertEquals(7, cnt);
for (int i = 10; i < 20; i++) cache.put(key(i), value(i));
GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@Override
public boolean applyx() throws IgniteCheckedException {
return updCnt.get() == 5;
}
}, 30_000);
}
}
});
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalFiltered.
/**
* @throws Exception If failed.
*/
public void testLocalFiltered() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteBiPredicate<Integer, Value> filter = new IgniteBiPredicate<Integer, Value>() {
@Override
public boolean apply(Integer k, Value v) {
return v.idx % 1000 == 0;
}
};
IgniteClosure<Cache.Entry<Integer, Value>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, Value>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, Value> e) {
return e.getValue().idx;
}
};
return ignite.cache("test-cache").query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(5, res.size());
Collections.sort(res);
for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
} finally {
cache.destroy();
}
}
Aggregations