use of javax.cache.Cache in project ignite by apache.
the class GridCachePreloadingEvictionsSelfTest method testEvictions.
/**
* @throws Exception If failed.
*/
public void testEvictions() throws Exception {
try {
final Ignite ignite1 = startGrid(1);
final IgniteCache<Integer, Object> cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 5000; i++) cache1.put(i, VALUE + i);
info("Finished data population.");
final AtomicBoolean done = new AtomicBoolean();
final CountDownLatch startLatch = new CountDownLatch(1);
int oldSize = cache1.localSize(CachePeekMode.ALL);
IgniteInternalFuture fut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
startLatch.await();
info("Started evicting...");
for (int i = 0; i < 3000 && !done.get(); i++) {
Cache.Entry<Integer, Object> entry = cache1.getEntry(i);
if (entry != null)
ignite1.cache(DEFAULT_CACHE_NAME).localEvict(Collections.<Object>singleton(entry.getKey()));
else
info("Entry is null.");
}
info("Finished evicting.");
return null;
}
}, 1);
ignite1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
startLatch.countDown();
return true;
}
}, EVT_NODE_JOINED);
final Ignite ignite2 = startGrid(2);
done.set(true);
fut.get();
sleepUntilCashesEqualize(ignite1, ignite2, oldSize);
checkCachesConsistency(ignite1, ignite2);
oldSize = cache1.size(CachePeekMode.ALL);
info("Evicting on constant topology.");
for (int i = 0; i < 1000; i++) {
Cache.Entry<Integer, Object> entry = randomEntry(ignite1);
if (entry != null)
cache1.localEvict(Collections.singleton(entry.getKey()));
else
info("Entry is null.");
}
sleepUntilCashesEqualize(ignite1, ignite2, oldSize);
checkCachesConsistency(ignite1, ignite2);
} finally {
stopAllGrids();
}
}
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 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();
}
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteCachePartitionedQueryMultiThreadedSelfTest method testLuceneAndSqlMultithreaded.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testLuceneAndSqlMultithreaded() throws Exception {
// ---------- Test parameters ---------- //
int luceneThreads = 10;
int sqlThreads = 10;
long duration = 10 * 1000;
final int logMod = 100;
final PersonObj p1 = new PersonObj("Jon", 1500, "Master");
final PersonObj p2 = new PersonObj("Jane", 2000, "Master");
final PersonObj p3 = new PersonObj("Mike", 1800, "Bachelor");
final PersonObj p4 = new PersonObj("Bob", 1900, "Bachelor");
final IgniteCache<UUID, PersonObj> cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
cache0.put(p1.id(), p1);
cache0.put(p2.id(), p2);
cache0.put(p3.id(), p3);
cache0.put(p4.id(), p4);
assertEquals(4, cache0.localSize(CachePeekMode.ALL));
assert grid(0).cluster().nodes().size() == GRID_CNT;
final AtomicBoolean done = new AtomicBoolean();
final AtomicLong luceneCnt = new AtomicLong();
// Start lucene query threads.
IgniteInternalFuture<?> futLucene = GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (!done.get()) {
QueryCursor<Cache.Entry<UUID, PersonObj>> master = cache0.query(new TextQuery(PersonObj.class, "Master"));
Collection<Cache.Entry<UUID, PersonObj>> entries = master.getAll();
checkResult(entries, p1, p2);
long cnt = luceneCnt.incrementAndGet();
if (cnt % logMod == 0)
info("Executed LUCENE queries: " + cnt);
}
}
}, luceneThreads, "LUCENE-THREAD");
final AtomicLong sqlCnt = new AtomicLong();
// Start sql query threads.
IgniteInternalFuture<?> futSql = GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (!done.get()) {
QueryCursor<Cache.Entry<UUID, PersonObj>> bachelors = cache0.query(new SqlQuery(PersonObj.class, "degree = 'Bachelor'"));
Collection<Cache.Entry<UUID, PersonObj>> entries = bachelors.getAll();
checkResult(entries, p3, p4);
long cnt = sqlCnt.incrementAndGet();
if (cnt % logMod == 0)
info("Executed SQL queries: " + cnt);
}
}
}, sqlThreads, "SQL-THREAD");
Thread.sleep(duration);
done.set(true);
futLucene.get();
futSql.get();
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSameQuery.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSameQuery() 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("Query results [entries=" + entries + ", aff=" + affinityNodes(entries, g) + ", 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);
info("Finishing test...");
done.set(true);
fut.get();
}
Aggregations