Search in sources :

Example 11 with Duration

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++;
}
Also used : CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 12 with Duration

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++;
}
Also used : CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 13 with Duration

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++;
}
Also used : CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 14 with Duration

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();
}
Also used : RedisProcess(org.redisson.RedisRunner.RedisProcess) CacheEntryExpiredListener(javax.cache.event.CacheEntryExpiredListener) MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) Duration(javax.cache.expiry.Duration) RedisRunner(org.redisson.RedisRunner) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) MutableConfiguration(javax.cache.configuration.MutableConfiguration) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 15 with Duration

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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) CacheConfig(com.hazelcast.config.CacheConfig) Test(org.junit.Test)

Aggregations

Duration (javax.cache.expiry.Duration)119 Test (org.junit.Test)49 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)36 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)31 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 ModifiedExpiryPolicy (javax.cache.expiry.ModifiedExpiryPolicy)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 Ignite (org.apache.ignite.Ignite)11 Transaction (org.apache.ignite.transactions.Transaction)11 CacheLoaderException (javax.cache.integration.CacheLoaderException)10 ArrayList (java.util.ArrayList)9 IgniteCache (org.apache.ignite.IgniteCache)9 MutableConfiguration (javax.cache.configuration.MutableConfiguration)8 CacheWriterException (javax.cache.integration.CacheWriterException)8 CacheNotExistsException (com.hazelcast.cache.CacheNotExistsException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7