use of javax.cache.expiry.ModifiedExpiryPolicy in project ignite by apache.
the class CacheOperationsWithExpirationTest method concurrentPutGetRemoveExpireAndQuery.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void concurrentPutGetRemoveExpireAndQuery(CacheConfiguration<String, TestIndexedType> ccfg) throws Exception {
Ignite ignite = ignite(0);
final IgniteCache<String, TestIndexedType> cache = ignite.createCache(ccfg);
final boolean qryEnabled = !F.isEmpty(ccfg.getQueryEntities());
try {
final long stopTime = U.currentTimeMillis() + 30_000;
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer idx) {
while (U.currentTimeMillis() < stopTime) {
if (!qryEnabled || idx % 2 == 0)
putGet(cache);
else
query(cache);
}
}
void putGet(IgniteCache<String, TestIndexedType> cache) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
cache = cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(MILLISECONDS, rnd.nextLong(100) + 1)));
for (int i = 0; i < KEYS; i++) {
String key = String.valueOf(rnd.nextInt(KEYS));
cache.put(key, testValue(rnd));
}
Set<String> s = new TreeSet<>();
for (int i = 0; i < 1000; i++) {
String key = String.valueOf(rnd.nextInt(KEYS));
s.add(key);
}
cache.getAll(s);
cache.removeAll(s);
}
void query(IgniteCache<String, TestIndexedType> cache) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
String k = String.valueOf(rnd.nextInt(KEYS));
SqlFieldsQuery qry1;
if (rnd.nextBoolean()) {
qry1 = new SqlFieldsQuery("select _key, _val from TestIndexedType where key1=? and intVal=?");
qry1.setArgs(k, k);
} else
qry1 = new SqlFieldsQuery("select _key, _val from TestIndexedType");
List res = cache.query(qry1).getAll();
assertNotNull(res);
}
}, 10, "test-thread");
} finally {
ignite.destroyCache(cache.getName());
}
}
Aggregations