use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheTtlManagerLoadTest method testLoad.
/**
* @throws Exception If failed.
*/
@Test
public void testLoad() throws Exception {
cacheMode = REPLICATED;
final IgniteKernal g = (IgniteKernal) startGrid(0);
try {
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Object, Object> cache = g.cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000)));
long key = 0;
while (!stop.get()) {
cache.put(key, key);
key++;
}
return null;
}
}, 1);
GridCacheTtlManager ttlMgr = g.internalCache(DEFAULT_CACHE_NAME).context().ttl();
for (int i = 0; i < 5; i++) {
U.sleep(5000);
ttlMgr.printMemoryStats();
}
stop.set(true);
fut.get();
} finally {
stopAllGrids();
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheTtlManagerSelfTest method checkTtl.
/**
* @param mode Cache mode.
* @throws Exception If failed.
*/
private void checkTtl(CacheMode mode) throws Exception {
cacheMode = mode;
final IgniteKernal g = (IgniteKernal) startGrid(0);
try {
final String key = "key";
g.cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))).put(key, 1);
assertEquals(1, g.cache(DEFAULT_CACHE_NAME).get(key));
U.sleep(1100);
GridTestUtils.retryAssert(log, 10, 100, new CAX() {
@Override
public void applyx() {
// Check that no more entries left in the map.
assertNull(g.cache(DEFAULT_CACHE_NAME).get(key));
if (!g.internalCache(DEFAULT_CACHE_NAME).context().deferredDelete())
assertNull(g.internalCache(DEFAULT_CACHE_NAME).map().getEntry(g.internalCache(DEFAULT_CACHE_NAME).context(), g.internalCache(DEFAULT_CACHE_NAME).context().toCacheKeyObject(key)));
}
});
} finally {
stopAllGrids();
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class CacheContinuousWithTransformerReplicatedSelfTest method testExpired.
/**
* @throws Exception If failed.
*/
@Test
public void testExpired() throws Exception {
Ignite ignite = gridToRunQuery();
IgniteCache<Integer, Employee> cache = ignite.cache(DEFAULT_CACHE_NAME);
cache = cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, 100)));
final Set<Integer> keys = new GridConcurrentHashSet<>();
final CountDownLatch latch = new CountDownLatch(2);
ContinuousQueryWithTransformer<Integer, Employee, Integer> qry = new ContinuousQueryWithTransformer<>();
qry.setIncludeExpired(true);
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Employee>() {
@Override
public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
return event.getEventType() == EventType.EXPIRED;
}
}));
qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Employee>, Integer>() {
@Override
public Integer apply(CacheEntryEvent<? extends Integer, ? extends Employee> evt) {
assertNotNull(evt.getValue());
assertNotNull(evt.getOldValue());
return evt.getKey();
}
}));
qry.setLocalListener(new EventListener<Integer>() {
@Override
public void onUpdated(Iterable<? extends Integer> evts) {
for (Integer key : evts) {
keys.add(key);
latch.countDown();
}
}
});
try (QueryCursor<Cache.Entry<Integer, Employee>> ignored = cache.query(qry)) {
cache.put(1, new Employee(SARAH_CONNOR, 42));
cache.put(2, new Employee(JOHN_CONNOR, 42));
// Wait for expiration.
latch.await(LATCH_TIMEOUT, MILLISECONDS);
assertEquals(2, keys.size());
assertTrue(keys.contains(1));
assertTrue(keys.contains(2));
}
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class DiagnosticLogForPartitionStatesTest method testShouldNotPrintMessageIfPartitionHasOtherCounterButHasCustomExpiryPolicyCacheGroup.
/**
* Tests that partitions validation is not triggered when a cache in the cache group (at least one of them)
* uses custom expiry policy.
*/
@Test
public void testShouldNotPrintMessageIfPartitionHasOtherCounterButHasCustomExpiryPolicyCacheGroup() throws Exception {
String grpName = "test-group";
CacheConfiguration<Integer, Integer> cfg1 = new CacheConfiguration<Integer, Integer>("cache-1").setBackups(1).setGroupName(grpName);
CacheConfiguration<Integer, Integer> cfg2 = new CacheConfiguration<Integer, Integer>("cache-2").setBackups(1).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1))).setGroupName(grpName);
doTest(Arrays.asList(cfg1, cfg2), false);
}
use of javax.cache.expiry.Duration in project ignite by apache.
the class GridCacheBasicApiAbstractTest method testPutWithExpiration.
/**
* @throws Exception In case of error.
*/
@Test
public void testPutWithExpiration() throws Exception {
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.ENTRY_LOCK);
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.EXPIRATION);
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_EVENTS);
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
CacheEventListener lsnr = new CacheEventListener(new CountDownLatch(1));
ignite.events().localListen(lsnr, EVTS_CACHE);
ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, 200L));
try {
int key = (int) System.currentTimeMillis();
cache.withExpiryPolicy(expiry).put(key, "val");
assert cache.get(key) != null;
cache.withExpiryPolicy(expiry).put(key, "val");
Thread.sleep(500);
assert cache.get(key) == null;
} finally {
ignite.events().stopLocalListen(lsnr, EVTS_CACHE);
}
}
Aggregations