use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method testNearExpiresWithCacheStore.
/**
* @throws Exception If failed.
*/
@Test
public void testNearExpiresWithCacheStore() throws Exception {
if (cacheMode() != PARTITIONED)
return;
factory = CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1));
nearCache = true;
startGridsMultiThreaded(gridCount());
IgniteConfiguration clientCfg = getConfiguration("client");
((TcpDiscoverySpi) clientCfg.getDiscoverySpi()).setForceServerMode(false);
Ignite client = startClientGrid("client", clientCfg);
CacheConfiguration ccfg = cacheConfiguration("testCache");
ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(GridCacheTestStore.class));
// ccfg.setExpiryPolicyFactory( CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
Integer key = 1;
cache.put(key, 1);
// Make entry cached in client NearCache.
assertEquals(1, cache.get(key));
assertEquals(1, cache.localPeek(key, CachePeekMode.NEAR));
waitExpired(key);
for (int i = 0; i < gridCount(); i++) assertNull(jcache(i).localPeek(key, CachePeekMode.BACKUP, CachePeekMode.PRIMARY));
assertEquals(null, cache.get(key));
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method testCreateUpdate0.
/**
* @throws Exception if failed.
*/
@Test
public void testCreateUpdate0() throws Exception {
startGrids(1);
long ttl = 60L;
final String key = "key1";
final IgniteCache<String, String> cache = jcache();
for (int i = 0; i < 1000; i++) {
final IgniteCache<String, String> cache0 = cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.HOURS, ttl)));
cache0.put(key, key);
info("PUT DONE");
}
long pSize = grid(0).context().cache().internalCache(DEFAULT_CACHE_NAME).context().ttl().pendingSize();
assertTrue("Too many pending entries: " + pSize, pSize <= 1);
cache.remove(key);
pSize = grid(0).context().cache().internalCache(DEFAULT_CACHE_NAME).context().ttl().pendingSize();
assertEquals(0, pSize);
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpiryPolicyWithStoreAbstractTest method getReadThrough.
/**
* @throws Exception If failed.
*/
protected void getReadThrough(boolean withExcPlc, TransactionConcurrency txConcurrency, TransactionIsolation txIsolation) throws Exception {
IgniteCache<Integer, Integer> cache = jcache(0);
if (withExcPlc)
cache = cache.withExpiryPolicy(new ExpiryPolicy() {
@Override
public Duration getExpiryForCreation() {
return new Duration(TimeUnit.MILLISECONDS, 501);
}
@Override
public Duration getExpiryForAccess() {
return new Duration(TimeUnit.MILLISECONDS, 601);
}
@Override
public Duration getExpiryForUpdate() {
return new Duration(TimeUnit.MILLISECONDS, 701);
}
});
Integer prim = primaryKeys(cache, 1, 1000).get(0);
Integer back = backupKeys(cache, 1, 1000).get(0);
Integer near = nearKeys(cache, 1, 1000).get(0);
Set<Integer> prims = new HashSet<>(primaryKeys(cache, 10, prim + 1));
Set<Integer> backs = new HashSet<>(backupKeys(cache, 10, back + 1));
Set<Integer> nears = new HashSet<>(nearKeys(cache, 10, near + 1));
Set<Integer> keys = new HashSet<>();
keys.add(prim);
keys.add(back);
keys.add(near);
keys.addAll(prims);
keys.addAll(backs);
keys.addAll(nears);
for (Integer key : keys) storeMap.put(key, key);
IgniteTransactions transactions = grid(0).transactions();
Transaction tx = txConcurrency != null ? transactions.txStart(txConcurrency, txIsolation) : null;
try {
Collection<Integer> singleKeys = new HashSet<>();
singleKeys.add(prim);
singleKeys.add(back);
singleKeys.add(near);
assertEquals(3, singleKeys.size());
for (Integer key : singleKeys) assertEquals(key, cache.get(key));
Map<Integer, Integer> res = new HashMap<>();
res.putAll(cache.getAll(prims));
res.putAll(cache.getAll(backs));
res.putAll(cache.getAll(nears));
assertEquals(30, res.size());
for (Map.Entry<Integer, Integer> e : res.entrySet()) assertEquals(e.getKey(), e.getValue());
} finally {
if (tx != null)
tx.rollback();
}
for (Integer key : keys) checkTtl(key, withExcPlc ? 501 : 500, true);
U.sleep(600);
for (Integer key : keys) checkExpired(key);
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpireWhileRebalanceTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
cfg.setFailureHandler(new StopNodeOrHaltFailureHandler());
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(ATOMIC);
ccfg.setCacheMode(PARTITIONED);
ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgnitePdsWithTtlTest2 method getCacheConfiguration.
/**
*/
public CacheConfiguration getCacheConfiguration(String name) {
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setName(name);
ccfg.setAtomicityMode(ATOMIC);
ccfg.setBackups(1);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 32768));
ccfg.setEagerTtl(true);
ccfg.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 20)));
return ccfg;
}
Aggregations