use of javax.cache.expiry.CreatedExpiryPolicy in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method testExpired.
/**
* @throws Exception If failed.
*/
public void testExpired() throws Exception {
IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, 1000)));
final Map<Object, Object> map = new ConcurrentHashMap8<>();
final CountDownLatch latch = new CountDownLatch(2);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setIncludeExpired(true);
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
for (CacheEntryEvent<?, ?> e : evts) {
if (e.getEventType() == EventType.EXPIRED) {
assertNull(e.getValue());
map.put(e.getKey(), e.getOldValue());
latch.countDown();
}
}
}
});
try (QueryCursor<Cache.Entry<Object, Object>> ignored = cache.query(qry)) {
cache.put(1, 1);
cache.put(2, 2);
// Wait for expiration.
Thread.sleep(2000);
assert latch.await(LATCH_TIMEOUT, MILLISECONDS);
assertEquals(2, map.size());
assertEquals(1, (int) map.get(1));
assertEquals(2, (int) map.get(2));
}
}
use of javax.cache.expiry.CreatedExpiryPolicy in project caffeine by ben-manes.
the class JCacheCreationExpiryTest method getConfiguration.
@Override
protected CaffeineConfiguration<Integer, Integer> getConfiguration() {
CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>();
configuration.setExpiryPolicyFactory(() -> new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, EXPIRY_DURATION)));
configuration.setTickerFactory(() -> ticker::read);
return configuration;
}
use of javax.cache.expiry.CreatedExpiryPolicy in project ignite by apache.
the class IgniteCacheExpiryStoreLoadSelfTest method checkLoad.
/**
* @param async If {@code true} uses asynchronous method.
* @throws Exception If failed.
*/
private void checkLoad(boolean async) throws Exception {
IgniteCache<String, Integer> cache = jcache(0).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
List<Integer> keys = new ArrayList<>();
keys.add(primaryKey(jcache(0)));
keys.add(primaryKey(jcache(1)));
keys.add(primaryKey(jcache(2)));
if (async)
cache.loadCacheAsync(null, keys.toArray(new Integer[3])).get();
else
cache.loadCache(null, keys.toArray(new Integer[3]));
assertEquals(3, cache.size(CachePeekMode.PRIMARY));
Thread.sleep(TIME_TO_LIVE + WAIT_TIME);
assertEquals(0, cache.size());
}
use of javax.cache.expiry.CreatedExpiryPolicy in project ignite by apache.
the class IgniteCacheExpiryStoreLoadSelfTest method testLoadAllWithExpiry.
/**
* @throws Exception If failed.
*/
public void testLoadAllWithExpiry() throws Exception {
IgniteCache<Integer, Integer> cache = ignite(0).<Integer, Integer>cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
Set<Integer> keys = new HashSet<>();
keys.add(primaryKey(jcache(0)));
keys.add(primaryKey(jcache(1)));
keys.add(primaryKey(jcache(2)));
CompletionListenerFuture fut = new CompletionListenerFuture();
cache.loadAll(keys, false, fut);
fut.get();
assertEquals(3, cache.size(CachePeekMode.PRIMARY));
Thread.sleep(TIME_TO_LIVE + WAIT_TIME);
assertEquals(0, cache.size());
}
use of javax.cache.expiry.CreatedExpiryPolicy in project ignite by apache.
the class IgniteCacheTtlCleanupSelfTest method testDeferredDeleteTtl.
/**
* @throws Exception If failed.
*/
public void testDeferredDeleteTtl() throws Exception {
IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
int cnt = GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE / PART_NUM + 100;
for (long i = 0; i < cnt; i++) grid(0).cache(DEFAULT_CACHE_NAME).put(i * PART_NUM, i);
for (int i = 0; i < cnt; i++) cache.put(i * PART_NUM, i);
// Wait 5 seconds.
Thread.sleep(6_000);
assertEquals(cnt, grid(0).cache(DEFAULT_CACHE_NAME).size());
GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
for (int i = 0; i < 100; i++) assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true)));
}
Aggregations