@CacheSpec(implementation = Implementation.Caffeine, population = Population.EMPTY, maximumSize = Maximum.DISABLED, weigher = CacheWeigher.DEFAULT, expireAfterAccess = Expire.DISABLED, expireAfterWrite = Expire.DISABLED, refreshAfterWrite = Expire.DISABLED, keys = ReferenceType.STRONG, values = ReferenceType.STRONG) @Test(dataProvider = "caches") public void noPolicy(Cache<Integer, Integer> cache, CacheContext context) { assertThat(cache.policy().eviction(), is(Optional.empty())); assertThat(cache.policy().expireAfterWrite(), is(Optional.empty())); assertThat(cache.policy().expireAfterAccess(), is(Optional.empty())); assertThat(cache.policy().refreshAfterWrite(), is(Optional.empty())); }
@CacheSpec(implementation = Implementation.Caffeine, population = Population.EMPTY, maximumSize = Maximum.DISABLED, weigher = CacheWeigher.DEFAULT, expireAfterAccess = Expire.DISABLED, expireAfterWrite = Expire.DISABLED, refreshAfterWrite = Expire.DISABLED, keys = ReferenceType.STRONG, values = ReferenceType.STRONG) @Test(dataProvider = "caches") public void noPolicy_async(AsyncLoadingCache<Integer, Integer> cache, CacheContext context) { assertThat(cache.synchronous().policy().eviction(), is(Optional.empty())); assertThat(cache.synchronous().policy().expireAfterWrite(), is(Optional.empty())); assertThat(cache.synchronous().policy().expireAfterAccess(), is(Optional.empty())); assertThat(cache.synchronous().policy().refreshAfterWrite(), is(Optional.empty())); } }
/** Returns the fixed expiration policy for the given parameter. */ private static Policy.Expiration<Integer, Integer> expirationPolicy( Parameter parameter, Cache<Integer, Integer> cache) { if (parameter.isAnnotationPresent(ExpireAfterAccess.class)) { return cache.policy().expireAfterAccess().get(); } else if (parameter.isAnnotationPresent(ExpireAfterWrite.class)) { return cache.policy().expireAfterWrite().get(); } else if (parameter.isAnnotationPresent(RefreshAfterWrite.class)) { return cache.policy().refreshAfterWrite().get(); } throw new AssertionError("Expiration parameter must have a qualifier annotation"); }