@Test public void maximumWeight_large() { Caffeine<?, ?> builder = Caffeine.newBuilder() .maximumWeight(Integer.MAX_VALUE).weigher(Weigher.singletonWeigher()); assertThat(builder.maximumWeight, is((long) Integer.MAX_VALUE)); assertThat(builder.weigher, is(Weigher.singletonWeigher())); Eviction<?, ?> eviction = builder.build().policy().eviction().get(); assertThat(eviction.getMaximum(), is((long) Integer.MAX_VALUE)); assertThat(eviction.isWeighted(), is(true)); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, maximumSize = Maximum.FULL, population = Population.EMPTY) public void isWeighted(CacheContext context, Eviction<Integer, Integer> eviction) { assertThat(eviction.isWeighted(), is(context.isWeighted())); }
@Test public void maximumWeight_small() { Caffeine<?, ?> builder = Caffeine.newBuilder() .maximumWeight(0).weigher(Weigher.singletonWeigher()); assertThat(builder.weigher, is(Weigher.singletonWeigher())); assertThat(builder.maximumWeight, is(0L)); Eviction<?, ?> eviction = builder.build().policy().eviction().get(); assertThat(eviction.getMaximum(), is(0L)); assertThat(eviction.isWeighted(), is(true)); }
@Override public io.druid.client.cache.CacheStats getStats() { final CacheStats stats = cache.stats(); final long size = cache .policy().eviction() .map(eviction -> eviction.isWeighted() ? eviction.weightedSize() : OptionalLong.empty()) .orElse(OptionalLong.empty()).orElse(-1); return new io.druid.client.cache.CacheStats( stats.hitCount(), stats.missCount(), cache.estimatedSize(), size, stats.evictionCount(), 0, stats.loadFailureCount() ); }
@Override public org.apache.druid.client.cache.CacheStats getStats() { final CacheStats stats = cache.stats(); final long size = cache .policy().eviction() .map(eviction -> eviction.isWeighted() ? eviction.weightedSize() : OptionalLong.empty()) .orElse(OptionalLong.empty()).orElse(-1); return new org.apache.druid.client.cache.CacheStats( stats.hitCount(), stats.missCount(), cache.estimatedSize(), size, stats.evictionCount(), 0, stats.loadFailureCount() ); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL, maximumSize = { Maximum.ZERO, Maximum.ONE, Maximum.FULL }, weigher = {CacheWeigher.DEFAULT, CacheWeigher.TEN}) public void evict(Cache<Integer, Integer> cache, CacheContext context, Eviction<Integer, Integer> eviction) { cache.putAll(context.absent()); if (eviction.isWeighted()) { assertThat(eviction.weightedSize().getAsLong(), is(context.maximumWeight())); } else { assertThat(cache.estimatedSize(), is(context.maximumSize())); } int count = context.absentKeys().size(); assertThat(context, hasEvictionCount(count)); assertThat(cache, hasRemovalNotifications(context, count, RemovalCause.SIZE)); verifyWriter(context, (verifier, writer) -> { Map<Integer, Integer> all = new HashMap<>(context.original()); all.putAll(context.absent()); MapDifference<Integer, Integer> diff = Maps.difference(all, cache.asMap()); verifier.deletedAll(diff.entriesOnlyOnLeft(), RemovalCause.SIZE); }); }
@Override public org.apache.druid.client.cache.CacheStats getStats() { final CacheStats stats = cache.stats(); final long size = cache .policy().eviction() .map(eviction -> eviction.isWeighted() ? eviction.weightedSize() : OptionalLong.empty()) .orElse(OptionalLong.empty()).orElse(-1); return new org.apache.druid.client.cache.CacheStats( stats.hitCount(), stats.missCount(), cache.estimatedSize(), size, stats.evictionCount(), 0, stats.loadFailureCount() ); }