use of javax.cache.Cache in project ignite by apache.
the class IndexingSpiQuerySelfTest method testNonBinaryIndexingSpi.
/**
* @throws Exception If failed.
*/
public void testNonBinaryIndexingSpi() throws Exception {
System.setProperty(IgniteSystemProperties.IGNITE_UNWRAP_BINARY_FOR_INDEXING_SPI, "true");
IgniteConfiguration cfg = configuration();
cfg.setIndexingSpi(new MyIndexingSpi());
Ignite ignite = Ignition.start(cfg);
CacheConfiguration<PersonKey, Person> ccfg = cacheConfiguration(CACHE_NAME);
IgniteCache<PersonKey, Person> cache = ignite.createCache(ccfg);
for (int i = 0; i < 10; i++) {
PersonKey key = new PersonKey(i);
cache.put(key, new Person("John Doe " + i));
}
QueryCursor<Cache.Entry<PersonKey, Person>> cursor = cache.query(new SpiQuery<PersonKey, Person>().setArgs(new PersonKey(2), new PersonKey(5)));
for (Cache.Entry<PersonKey, Person> entry : cursor) System.out.println(entry);
cache.remove(new PersonKey(9));
}
use of javax.cache.Cache in project ignite by apache.
the class GridCacheEvictionTouchSelfTest method testPolicyConsistency.
/**
* @throws Exception If failed.
*/
public void testPolicyConsistency() throws Exception {
FifoEvictionPolicy<Object, Object> plc = new FifoEvictionPolicy<>();
plc.setMaxSize(500);
this.plc = plc;
try {
Ignite ignite = startGrid(1);
final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
final Random rnd = new Random();
try (Transaction tx = ignite.transactions().txStart()) {
int iterCnt = 20;
int keyCnt = 5000;
for (int i = 0; i < iterCnt; i++) {
int j = rnd.nextInt(keyCnt);
// Put or remove?
if (rnd.nextBoolean())
cache.put(j, j);
else
cache.remove(j);
if (i != 0 && i % 1000 == 0)
info("Stats [iterCnt=" + i + ", size=" + cache.size() + ']');
}
FifoEvictionPolicy<Integer, Integer> plc0 = (FifoEvictionPolicy<Integer, Integer>) this.plc;
if (!plc0.queue().isEmpty()) {
for (Cache.Entry<Integer, Integer> e : plc0.queue()) U.warn(log, "Policy queue item: " + e);
fail("Test failed, see logs for details.");
}
tx.commit();
}
} catch (Throwable t) {
error("Test failed.", t);
fail("Test failed, see logs for details.");
} finally {
stopAllGrids();
}
}
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 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