use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheTtlManagerEvictionSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(cacheMode);
ccfg.setEagerTtl(true);
ccfg.setEvictionPolicy(new FifoEvictionPolicy(ENTRIES_LIMIT, 100));
ccfg.setOnheapCacheEnabled(true);
ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheTtlManagerNotificationTest method testThatNotificationWorkAsExpected.
/**
* @throws Exception If failed.
*/
@Test
public void testThatNotificationWorkAsExpected() throws Exception {
try (final Ignite g = startGrid(0)) {
final BlockingArrayQueue<Event> queue = new BlockingArrayQueue<>();
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
queue.add(evt);
return true;
}
}, EventType.EVT_CACHE_OBJECT_EXPIRED);
final String key = "key";
IgniteCache<Object, Object> cache = g.cache(DEFAULT_CACHE_NAME);
ExpiryPolicy plc1 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, 100_000));
cache.withExpiryPolicy(plc1).put(key + 1, 1);
// Cleaner should see entry.
Thread.sleep(1_000);
ExpiryPolicy plc2 = new CreatedExpiryPolicy(new Duration(MILLISECONDS, 1000));
cache.withExpiryPolicy(plc2).put(key + 2, 1);
// We should receive event about second entry expiration.
assertNotNull(queue.poll(5, SECONDS));
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class PendingTreeCorruptionTest method testCorruptionWhileLoadingData.
/**
*/
@Test
public void testCorruptionWhileLoadingData() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
String expireCacheName = "cacheWithExpire";
String regularCacheName = "cacheWithoutExpire";
String grpName = "cacheGroup";
IgniteCache<Object, Object> expireCache = ig.getOrCreateCache(new CacheConfiguration<>(expireCacheName).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(MINUTES, 10))).setGroupName(grpName));
IgniteCache<Object, Object> regularCache = ig.getOrCreateCache(new CacheConfiguration<>(regularCacheName).setGroupName(grpName));
// This will initialize partition and cache structures.
expireCache.put(0, 0);
expireCache.remove(0);
int expireCacheId = CU.cacheGroupId(expireCacheName, grpName);
CacheGroupContext grp = ig.context().cache().cacheGroup(CU.cacheId(grpName));
IgniteCacheOffheapManager.CacheDataStore store = grp.topology().localPartition(0).dataStore();
assertNotNull(store);
// Get pending tree of expire cache.
PendingEntriesTree pendingTree = store.pendingTree();
long year = TimeUnit.DAYS.toMillis(365);
long expiration = System.currentTimeMillis() + year;
ig.context().cache().context().database().checkpointReadLock();
try {
// Carefully calculated number. Just enough for the first split to happen, but not more.
for (int i = 0; i < 202; i++) // link != 0
pendingTree.putx(new PendingRow(expireCacheId, expiration, expiration + i));
// Open cursor, it'll cache first leaf of the tree.
GridCursor<PendingRow> cur = pendingTree.find(null, new PendingRow(expireCacheId, expiration + year, 0), PendingEntriesTree.WITHOUT_KEY);
// Required for "do" loop to work.
assertTrue(cur.next());
int cnt = 0;
// Emulate real expiry loop but with a more precise control.
do {
PendingRow row = cur.get();
pendingTree.removex(row);
// with its sibling, meaning that cached "nextPageId" points to empty page from reuse list.
if (row.link - row.expireTime == 100) {
// Put into another cache will take a page from reuse list first. This means that cached
// "nextPageId" points to a data page.
regularCache.put(0, 0);
}
cnt++;
} while (cur.next());
assertEquals(202, cnt);
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method testExpired.
/**
* @throws Exception If failed.
*/
@Test
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 ConcurrentHashMap<>();
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) {
assertEquals(e.getOldValue(), e.getValue());
map.put(e.getKey(), e.getOldValue());
latch.countDown();
}
}
}
});
try (QueryCursor<Cache.Entry<Object, Object>> ignored = cache.query(qry)) {
cachePut(cache, 1, 1);
cachePut(cache, 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.Duration in project ignite by apache.
the class IgniteCacheWriteBehindNoUpdateSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
CacheConfiguration<String, Long> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
ccfg.setCacheMode(CacheMode.PARTITIONED);
ccfg.setBackups(1);
ccfg.setReadFromBackup(true);
ccfg.setCopyOnRead(false);
ccfg.setName(THROTTLES_CACHE_NAME);
Duration expiryDuration = new Duration(TimeUnit.MINUTES, 1);
ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration));
ccfg.setReadThrough(false);
ccfg.setWriteThrough(true);
ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(new TestCacheStore()));
cfg.setCacheConfiguration(ccfg);
return cfg;
}
Aggregations