use of javax.cache.Cache in project ignite by apache.
the class GridCacheFullTextQuerySelfTest method checkForMissedKeys.
/**
* Check if there is missed keys.
*
* @throws IgniteCheckedException if failed.
*/
private static void checkForMissedKeys(IgniteEx ignite, Collection<Integer> exp, List<Cache.Entry<Integer, ?>> all) throws IgniteCheckedException {
if (exp.size() == 0)
return;
IgniteInternalCache<Integer, Person> cache = ignite.cachex(PERSON_CACHE);
assertNotNull(cache);
StringBuilder sb = new StringBuilder();
Affinity<Integer> aff = cache.affinity();
for (Integer key : exp) {
Integer part = aff.partition(key);
sb.append(String.format("Query did not return expected key '%d' (exists: %s), partition '%d', partition nodes: ", key, cache.get(key) != null, part));
Collection<ClusterNode> partNodes = aff.mapPartitionToPrimaryAndBackups(part);
for (ClusterNode node : partNodes) sb.append(node).append(" ");
sb.append(";\n");
}
sb.append("Returned keys: ");
for (Cache.Entry e : all) sb.append(e.getKey()).append(" ");
sb.append(";\n");
fail(sb.toString());
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteDbPutGetAbstractTest method testRandomPutGetRemove.
/**
* @throws Exception If failed.
*/
@Test
public void testRandomPutGetRemove() throws Exception {
final IgniteCache<Integer, DbValue> cache = cache(DEFAULT_CACHE_NAME);
int cnt = KEYS_COUNT;
Map<Integer, DbValue> map = new HashMap<>(cnt);
long seed = System.currentTimeMillis();
int iterations = SF.apply(MvccFeatureChecker.forcedMvcc() ? 30_000 : 90_000);
X.println("Seed: " + seed);
X.println("Iterations total: " + iterations);
Random rnd = new GridRandom(seed);
for (int i = 0; i < iterations; i++) {
if (i % 5000 == 0)
X.println("Iteration #" + i);
int key = rnd.nextInt(cnt);
DbValue v0 = new DbValue(key, "test-value-" + rnd.nextInt(200), rnd.nextInt(500));
switch(rnd.nextInt(3)) {
case 0:
assertEquals(map.put(key, v0), cache.getAndPut(key, v0));
case 1:
assertEquals(map.get(key), cache.get(key));
break;
case 2:
assertEquals(map.remove(key), cache.getAndRemove(key));
assertNull(cache.get(key));
}
}
assertEquals(map.size(), cache.size());
for (Cache.Entry<Integer, DbValue> entry : cache.query(new ScanQuery<Integer, DbValue>())) assertEquals(map.get(entry.getKey()), entry.getValue());
}
use of javax.cache.Cache 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 javax.cache.Cache in project ignite by apache.
the class IgniteDbPutGetAbstractTest method checkLocalEntries.
/**
* @param total Expected total entries.
* @param cntrs Expected per-node entries count.
*/
private void checkLocalEntries(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;
for (Cache.Entry<DbKey, DbValue> e : cache0.localEntries()) {
cnt++;
allKeys.add(e.getKey());
assertEquals(e.getKey().val, e.getValue().iVal);
}
assertEquals(cntrs.get(ignite0.cluster().localNode().id()), (Integer) cnt);
}
assertEquals(total, allKeys.size());
}
use of javax.cache.Cache 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());
}
}
Aggregations