use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpiryPolicyAbstractTest method testNearExpiresOnClient.
/**
* Put entry to server node and check how its expires in client NearCache.
*
* @throws Exception If failed.
*/
@Test
public void testNearExpiresOnClient() throws Exception {
if (cacheMode() != PARTITIONED)
return;
factory = CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 2));
nearCache = true;
startGrids();
IgniteConfiguration clientCfg = getConfiguration("client");
((TcpDiscoverySpi) clientCfg.getDiscoverySpi()).setForceServerMode(false);
Ignite client = startClientGrid("client", clientCfg);
IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
Integer key = 1;
// Put on server node.
jcache(0).put(key, 1);
// Make entry cached in client NearCache.
assertEquals(1, cache.get(key));
assertEquals(1, cache.localPeek(key, CachePeekMode.NEAR));
waitExpired(key);
// Check client NearCache.
assertNull(cache.localPeek(key, CachePeekMode.NEAR));
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class IgniteCacheExpiryPolicyWithStoreAbstractTest method testLoadAll.
/**
* @throws Exception If failed.
*/
@Test
public void testLoadAll() throws Exception {
IgniteCache<Integer, Integer> cache = jcache(0);
final Integer key = primaryKey(cache);
storeMap.put(key, 100);
try {
CompletionListenerFuture fut = new CompletionListenerFuture();
cache.loadAll(F.asSet(key), false, fut);
fut.get();
checkTtl(key, 500, false);
assertEquals((Integer) 100, cache.localPeek(key, CachePeekMode.ONHEAP));
U.sleep(600);
checkExpired(key);
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);
}
});
fut = new CompletionListenerFuture();
cache.loadAll(F.asSet(key), false, fut);
fut.get();
checkTtl(key, 501, false);
} finally {
cache.removeAll();
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class CacheQueryFilterExpiredTest method checkFilterExpired.
/**
* @param ignite Node.
* @param atomicityMode Cache atomicity mode.
* @param eagerTtl Value for {@link CacheConfiguration#setEagerTtl(boolean)}.
* @throws Exception If failed.
*/
private void checkFilterExpired(Ignite ignite, CacheAtomicityMode atomicityMode, boolean eagerTtl) throws Exception {
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setEagerTtl(eagerTtl);
ccfg.setIndexedTypes(Integer.class, Integer.class);
final IgniteCache<Integer, Integer> cache = ignite.createCache(ccfg);
try {
IgniteCache<Integer, Integer> expCache = cache.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(0, 2000)));
for (int i = 0; i < 10; i++) {
IgniteCache<Integer, Integer> cache0 = i % 2 == 0 ? cache : expCache;
cache0.put(i, i);
}
assertEquals(10, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
assertEquals(10, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size() == 5 && cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size() == 5;
}
}, 5000);
assertEquals(5, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
assertEquals(5, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());
} finally {
ignite.destroyCache(ccfg.getName());
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class Runner method main.
public static void main(String[] args) {
ClientConnectorConfiguration connectorConfiguration = new ClientConnectorConfiguration().setPort(10890);
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder().setAddresses(Collections.singleton("127.0.0.1:47500"));
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi().setIpFinder(ipFinder).setSocketTimeout(300).setNetworkTimeout(300);
CacheConfiguration expiryCacheCfg = new CacheConfiguration("twoSecondCache").setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 2))));
IgniteConfiguration cfg = new IgniteConfiguration().setClientConnectorConfiguration(connectorConfiguration).setDiscoverySpi(discoSpi).setCacheConfiguration(expiryCacheCfg).setLocalHost("127.0.0.1");
Ignition.start(cfg);
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class CacheMvccTransactionsTest method testChangeExpireTime.
/**
* @throws Exception If failed.
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-7311")
@Test
public void testChangeExpireTime() throws Exception {
final IgniteEx node = startGrid(0);
IgniteCache cache = node.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, 64));
cache.put(1, 1);
final IgniteCache expiryCache = cache.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(TimeUnit.SECONDS, 1)));
expiryCache.get(1);
}
Aggregations