use of javax.cache.expiry.Duration in project hazelcast-simulator by hazelcast.
the class ListenerICacheTest method putExpiry.
@TimeStep(prob = 0)
public void putExpiry(ThreadState state) {
int expiryDuration = state.randomInt(maxExpiryDurationMs);
ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
int key = state.randomInt(keyCount);
cache.put(key, state.randomLong(), expiryPolicy);
state.putExpiry++;
}
use of javax.cache.expiry.Duration in project hazelcast-simulator by hazelcast.
the class ListenerICacheTest method getExpiryAsync.
@TimeStep(prob = 0)
public void getExpiryAsync(ThreadState state) throws ExecutionException, InterruptedException {
int expiryDuration = state.randomInt(maxExpiryDurationMs);
ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
int key = state.randomInt(keyCount);
Future<Long> future = cache.getAsync(key, expiryPolicy);
future.get();
state.getAsyncExpiry++;
}
use of javax.cache.expiry.Duration in project hazelcast-simulator by hazelcast.
the class ListenerICacheTest method getExpiry.
@TimeStep(prob = 0)
public void getExpiry(ThreadState state) {
int expiryDuration = state.randomInt(maxExpiryDurationMs);
ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
int key = state.randomInt(keyCount);
cache.get(key, expiryPolicy);
state.getExpiry++;
}
use of javax.cache.expiry.Duration in project redisson by redisson.
the class JCacheTest method testExpiration.
@Test
public void testExpiration() throws InterruptedException, IllegalArgumentException, URISyntaxException, FailedToStartRedisException, IOException {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
MutableConfiguration<String, String> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
config.setStoreByValue(true);
URI configUri = getClass().getResource("redisson-jcache.yaml").toURI();
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null).createCache("test", config);
CountDownLatch latch = new CountDownLatch(1);
String key = "123";
ExpiredListener clientListener = new ExpiredListener(latch, key, "90");
MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(clientListener), null, true, true);
cache.registerCacheEntryListener(listenerConfiguration);
cache.put(key, "90");
Assertions.assertNotNull(cache.get(key));
latch.await();
Assertions.assertNull(cache.get(key));
cache.close();
runner.stop();
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method testRecordExpiryPolicyTakesPrecedenceOverCachePolicy.
@Test
public void testRecordExpiryPolicyTakesPrecedenceOverCachePolicy() {
final int updatedTtlMillis = 1000;
CacheConfig<Integer, String> cacheConfig = new CacheConfig<>();
cacheConfig.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_DAY));
ICache<Integer, String> cache = createCache(cacheConfig);
cache.put(1, "value");
cache.setExpiryPolicy(1, new TouchedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, updatedTtlMillis)));
sleepAtLeastMillis(updatedTtlMillis + 1);
assertNull(cache.get(1));
}
Aggregations