use of javax.cache.Cache in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedNewQueries.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedNewQueries() throws Exception {
int threadCnt = 50;
final int keyCnt = 10;
final int logMod = 5000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
for (int i = 0; i < keyCnt; i++) {
c.put(i, i);
c.localEvict(Arrays.asList(i));
}
final AtomicInteger cnt = new AtomicInteger();
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
int iter = 0;
while (!done.get() && !Thread.currentThread().isInterrupted()) {
iter++;
Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
assert entries != null;
assertEquals("Entries count is not as expected on iteration: " + iter, keyCnt, entries.size());
if (cnt.incrementAndGet() % logMod == 0) {
GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
assert qryMgr != null;
qryMgr.printMemoryStats();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
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());
}
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteDbPutGetAbstractTest method testPutGetLarge.
/**
* @throws Exception if failed.
*/
public void testPutGetLarge() throws Exception {
IgniteEx ig = grid(0);
IgniteCache<Integer, byte[]> cache = ig.cache(DEFAULT_CACHE_NAME);
final byte[] val = new byte[2048];
ThreadLocalRandom.current().nextBytes(val);
cache.put(0, val);
Assert.assertArrayEquals(val, cache.get(0));
final IgniteCache<Integer, LargeDbValue> cache1 = ig.cache("large");
final LargeDbValue large = new LargeDbValue("str1", "str2", randomInts(1024));
cache1.put(1, large);
assertEquals(large, cache1.get(1));
if (indexingEnabled()) {
final List<Cache.Entry<Integer, LargeDbValue>> all = cache1.query(new SqlQuery<Integer, LargeDbValue>(LargeDbValue.class, "str1='str1'")).getAll();
assertEquals(1, all.size());
final Cache.Entry<Integer, LargeDbValue> entry = all.get(0);
assertEquals(1, entry.getKey().intValue());
assertEquals(large, entry.getValue());
}
cache.remove(0);
cache1.remove(1);
assertNull(cache.get(0));
assertNull(cache1.get(1));
}
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 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());
}
Aggregations