use of javax.cache.expiry.Duration in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method testBackupQueueEvict.
/**
* @throws Exception If failed.
*/
@Test
public void testBackupQueueEvict() throws Exception {
startGridsMultiThreaded(2);
Ignite qryClient = startClientGrid(2);
CacheEventListener1 lsnr = new CacheEventListener1(false);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
QueryCursor<?> cur = qryClient.cache(DEFAULT_CACHE_NAME).query(qry);
assertEquals(0, backupQueue(ignite(0)).size());
long ttl = 100;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
final IgniteCache<Object, Object> cache0 = ignite(2).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry);
final List<Integer> keys = primaryKeys(ignite(1).cache(DEFAULT_CACHE_NAME), BACKUP_ACK_THRESHOLD);
lsnr.latch = new CountDownLatch(keys.size());
for (Integer key : keys) {
log.info("Put: " + key);
cache0.put(key, key);
}
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return backupQueue(ignite(0)).isEmpty();
}
}, 5000);
assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)), backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
boolean wait = waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return cache0.localPeek(keys.get(0)) == null;
}
}, ttl + 1000);
assertTrue("Entry evicted.", wait);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return backupQueue(ignite(0)).isEmpty();
}
}, 2000);
assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)), backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
if (!backupQueue(ignite(0)).isEmpty()) {
for (Object o : backupQueue(ignite(0))) {
CacheContinuousQueryEntry e = (CacheContinuousQueryEntry) o;
assertNotSame("Evicted entry added to backup queue.", -1L, e.updateCounter());
}
}
cur.close();
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class ScanQueryOffheapExpiryPolicySelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setName(CACHE_NAME);
ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
ccfg.setCacheMode(CacheMode.PARTITIONED);
ccfg.setBackups(1);
ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 10)));
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class WebSessionFilter method cacheWithExpiryPolicy.
/**
* @param maxInactiveInteval Interval to use in expiry policy.
* @param cache Cache.
* @param <T> Cached object type.
* @return Cache with expiry policy if {@code maxInactiveInteval} greater than zero.
*/
private <T> IgniteCache<String, T> cacheWithExpiryPolicy(final int maxInactiveInteval, final IgniteCache<String, T> cache) {
if (maxInactiveInteval > 0) {
long ttl = maxInactiveInteval * 1000L;
ExpiryPolicy plc = new ModifiedExpiryPolicy(new Duration(MILLISECONDS, ttl));
return cache.withExpiryPolicy(plc);
}
return cache;
}
use of javax.cache.expiry.Duration in project wcomponents by BorderTech.
the class PlainTextRendererImpl method getCache.
/**
* @return the cache instance
*/
protected synchronized Cache<String, String> getCache() {
Cache<String, String> cache = Caching.getCache(CACHE_NAME, String.class, String.class);
if (cache == null) {
final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<String, String> config = new MutableConfiguration<>();
config.setTypes(String.class, String.class);
config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
// No need to serialize the result
config.setStoreByValue(false);
cache = mgr.createCache(CACHE_NAME, config);
}
return cache;
}
use of javax.cache.expiry.Duration in project wcomponents by BorderTech.
the class VelocityCacheImpl method getCache.
/**
* @return the cache instance
*/
protected synchronized Cache<Object, Resource> getCache() {
Cache<Object, Resource> cache = Caching.getCache(CACHE_NAME, Object.class, Resource.class);
if (cache == null) {
final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
MutableConfiguration<Object, Resource> config = new MutableConfiguration<>();
config.setTypes(Object.class, Resource.class);
config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
// Velocity template classes are not serializable so use by ref.
config.setStoreByValue(false);
cache = mgr.createCache(CACHE_NAME, config);
}
return cache;
}
Aggregations