use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method entryShouldNotBeExpiredWhenTimeUnitIsNullAndDurationIsZero.
@Test
public void entryShouldNotBeExpiredWhenTimeUnitIsNullAndDurationIsZero() {
Duration duration = new Duration(null, 0);
CacheConfig<Integer, String> cacheConfig = new CacheConfig<>();
cacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
Cache<Integer, String> cache = createCache(cacheConfig);
cache.put(1, "value");
sleepAtLeastMillis(1);
assertNotNull(cache.get(1));
}
use of javax.cache.expiry.Duration in project pdi-dataservice-server-plugin by pentaho.
the class ServiceCache method ttlMatches.
private boolean ttlMatches(Cache<CachedService.CacheKey, CachedService> cache, LogChannelInterface log) {
CompleteConfiguration config = cache.getConfiguration(CompleteConfiguration.class);
if (getTimeToLive() == null) {
// ttl has not been modified
return true;
}
if (config != null) {
try {
Duration duration = getConfigDuration(config);
long ttl = Long.parseLong(getTimeToLive());
return ttl == duration.getDurationAmount();
} catch (NumberFormatException nfe) {
log.logError(String.format("Failed to determine configured TTL value for cache '%s'. TTL value = '%s'", cache.getName(), getTimeToLive()));
throw nfe;
}
}
log.logError(String.format("Failed to check TTL consistency with cache for name '%s'.\n Assuming cache can be used", cache.getName()));
return true;
}
use of javax.cache.expiry.Duration in project hazelcast-simulator by hazelcast.
the class ListenerICacheTest method putExpiryAsync.
@TimeStep(prob = 0)
public void putExpiryAsync(ThreadState state) {
int expiryDuration = state.randomInt(maxExpiryDurationMs);
ExpiryPolicy expiryPolicy = new CreatedExpiryPolicy(new Duration(MILLISECONDS, expiryDuration));
int key = state.randomInt(keyCount);
cache.putAsync(key, state.randomLong(), expiryPolicy);
state.putAsyncExpiry++;
}
use of javax.cache.expiry.Duration in project redisson by redisson.
the class JCacheTest method testCreatedExpiryPolicy.
@Test
public void testCreatedExpiryPolicy() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
MutableConfiguration c = new MutableConfiguration();
c.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(MILLISECONDS, 500)));
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg, c);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
cache.put("1", "2");
Thread.sleep(500);
assertThat(cache.get("1")).isNull();
cache.put("1", "3");
assertThat(cache.get("1")).isEqualTo("3");
Thread.sleep(500);
assertThat(cache.get("1")).isNull();
cache.put("1", "4");
assertThat(cache.get("1")).isEqualTo("4");
Thread.sleep(100);
cache.put("1", "5");
assertThat(cache.get("1")).isEqualTo("5");
cache.close();
runner.stop();
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheExpirationPromotionTest method promoted_replica_should_send_eviction_to_other_backup.
@Test
public void promoted_replica_should_send_eviction_to_other_backup() {
final CachingProvider provider = createServerCachingProvider(instances[0]);
provider.getCacheManager().createCache(cacheName, getCacheConfig());
HazelcastCacheManager cacheManager = (HazelcastServerCacheManager) provider.getCacheManager();
final String keyOwnedByLastInstance = generateKeyOwnedBy(instances[nodeCount - 1]);
ICache<String, String> cache = cacheManager.getCache(cacheName).unwrap(ICache.class);
cache.put(keyOwnedByLastInstance, "dummyVal", new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
final BackupAccessor<String, String> backupAccessor = TestBackupUtils.newCacheAccessor(instances, cacheName, 1);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotNull(backupAccessor.get(keyOwnedByLastInstance));
}
});
instances[nodeCount - 1].shutdown();
// the backup replica became the primary, now the backup is the other node.
// we check if the newly appointed replica sent expiration to backups
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, backupAccessor.size());
}
});
}
Aggregations