use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteClientReconnectCacheQueriesFailoverTest method testReconnectScanQuery.
/**
* @throws Exception If failed.
*/
public void testReconnectScanQuery() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Person> cache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
final Affinity<Integer> aff = client.affinity(DEFAULT_CACHE_NAME);
final Map<Integer, Integer> partMap = new HashMap<>();
for (int i = 0; i < aff.partitions(); i++) partMap.put(i, 0);
for (int i = 0; i <= 10_000; i++) {
Integer part = aff.partition(i);
Integer size = partMap.get(part);
partMap.put(part, size + 1);
}
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
ScanQuery<Integer, Person> qry = new ScanQuery<>(new IgniteBiPredicate<Integer, Person>() {
@Override
public boolean apply(Integer key, Person val) {
return val.getId() % 2 == 1;
}
});
assertEquals(5000, cache.query(qry).getAll().size());
ThreadLocalRandom rnd = ThreadLocalRandom.current();
Integer part = rnd.nextInt(0, aff.partitions());
qry = new ScanQuery<>(part);
assertEquals((int) partMap.get(part), cache.query(qry).getAll().size());
return null;
}
});
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteDbPutGetAbstractTest method checkScan.
/**
* @param total Expected total entries.
*/
private void checkScan(int total) {
for (int i = 0; i < gridCount(); i++) {
Set<DbKey> allKeys = new HashSet<>();
Ignite ignite0 = grid(i);
IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache0.query(qry);
for (Cache.Entry<DbKey, DbValue> e : cur) {
allKeys.add(e.getKey());
assertEquals(e.getKey().val, e.getValue().iVal);
}
assertEquals(total, allKeys.size());
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteDbPutGetAbstractTest method checkLocalScan.
/**
* @param total Expected total entries.
* @param cntrs Expected per-node entries count.
*/
private void checkLocalScan(int total, Map<UUID, Integer> cntrs) {
Set<DbKey> allKeys = new HashSet<>();
for (int i = 0; i < gridCount(); i++) {
Ignite ignite0 = grid(i);
IgniteCache<DbKey, DbValue> cache0 = ignite0.cache("non-primitive");
int cnt = 0;
ScanQuery<DbKey, DbValue> qry = new ScanQuery<>();
qry.setLocal(true);
QueryCursor<Cache.Entry<DbKey, DbValue>> cur = cache0.query(qry);
Map<Integer, Integer> partCntrs = new HashMap<>();
Affinity<Object> aff = ignite0.affinity(cache0.getName());
for (Cache.Entry<DbKey, DbValue> e : cur) {
cnt++;
allKeys.add(e.getKey());
assertEquals(e.getKey().val, e.getValue().iVal);
int part = aff.partition(e.getKey());
Integer partCntr = partCntrs.get(part);
if (partCntr == null)
partCntr = 1;
else
partCntr += 1;
partCntrs.put(part, partCntr);
}
assertEquals(cntrs.get(ignite0.cluster().localNode().id()), (Integer) cnt);
checkScanPartition(ignite0, cache0, partCntrs, true);
}
assertEquals(total, allKeys.size());
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class CacheScanPartitionQueryFallbackSelfTest method testScanRemote.
/**
* Scan should perform on the remote node.
*
* @throws Exception If failed.
*/
public void testScanRemote() throws Exception {
cacheMode = CacheMode.PARTITIONED;
backups = 0;
commSpiFactory = new TestRemoteCommunicationSpiFactory();
try {
Ignite ignite = startGrids(GRID_CNT);
IgniteCacheProxy<Integer, Integer> cache = fillCache(ignite);
IgniteBiTuple<Integer, UUID> tup = remotePartition(cache.context());
int part = tup.get1();
expNodeId = tup.get2();
QueryCursor<Cache.Entry<Integer, Integer>> qry = cache.query(new ScanQuery<Integer, Integer>().setPartition(part));
doTestScanQuery(qry, part);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.cache.query.ScanQuery in project ignite by apache.
the class IgniteBinaryObjectFieldsQuerySelfTest method checkQuery.
/**
* @throws Exception If failed.
*/
private void checkQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
IgniteCache<Object, Object> cache = grid(GRID_CNT - 1).getOrCreateCache(cache(cacheMode, atomicity));
try {
populate(cache);
QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(new SqlQuery("Person", "order " + "by id asc"));
List<Cache.Entry<Object, Object>> all = cur.getAll();
assertEquals(100, all.size());
for (int i = 0; i < 100; i++) {
Object person = all.get(i).getValue();
assertEquals(Integer.valueOf(i), U.field(person, "id"));
assertEquals("person-" + i, U.field(person, "name"));
assertEquals("person-last-" + i, U.field(person, "lastName"));
assertEquals((double) (i * 25), U.field(person, "salary"));
}
int max = 49;
// Check local scan query with keepBinary flag set.
ScanQuery<BinaryObject, BinaryObject> scanQry = new ScanQuery<>(new PersonKeyFilter(max));
QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> curs = grid(GRID_CNT - 1).cache(DEFAULT_CACHE_NAME).withKeepBinary().query(scanQry);
List<Cache.Entry<BinaryObject, BinaryObject>> records = curs.getAll();
assertEquals(50, records.size());
for (Cache.Entry<BinaryObject, BinaryObject> entry : records) {
BinaryObject key = entry.getKey();
assertTrue(key.<Integer>field("id") <= max);
assertEquals(PERSON_KEY_CLS_NAME, key.deserialize().getClass().getName());
}
} finally {
grid(GRID_CNT - 1).cache(DEFAULT_CACHE_NAME).removeAll();
grid(GRID_CNT - 1).destroyCache(DEFAULT_CACHE_NAME);
}
}
Aggregations