@Override public void recordEviction(int weight) { try { delegate.recordEviction(weight); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); } }
@Override @SuppressWarnings("deprecation") public void recordEviction() { try { delegate.recordEviction(); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); } }
/** * Records the eviction of an entry from the cache. This should only been called when an entry is * evicted due to the cache's eviction strategy, and not as a result of manual * {@link Cache#invalidate invalidations}. * * @param weight the weight of the evicted entry */ default void recordEviction(@NonNegative int weight) { // This method will be abstract in version 3.0.0 recordEviction(); }
@Test public void recordStats_custom() { Supplier<StatsCounter> supplier = () -> statsCounter; Caffeine<?, ?> builder = Caffeine.newBuilder().recordStats(supplier); builder.statsCounterSupplier.get().recordEviction(1); verify(statsCounter).recordEviction(1); builder.build(); }
@Test public void guarded_exception() { StatsCounter statsCounter = Mockito.mock(StatsCounter.class); when(statsCounter.snapshot()).thenThrow(new NullPointerException()); doThrow(NullPointerException.class).when(statsCounter).recordEviction(); doThrow(NullPointerException.class).when(statsCounter).recordHits(anyInt()); doThrow(NullPointerException.class).when(statsCounter).recordMisses(anyInt()); doThrow(NullPointerException.class).when(statsCounter).recordEviction(anyInt()); doThrow(NullPointerException.class).when(statsCounter).recordLoadSuccess(anyLong()); doThrow(NullPointerException.class).when(statsCounter).recordLoadFailure(anyLong()); StatsCounter guarded = StatsCounter.guardedStatsCounter(statsCounter); guarded.recordHits(1); guarded.recordMisses(1); guarded.recordEviction(); guarded.recordEviction(10); guarded.recordLoadSuccess(1); guarded.recordLoadFailure(1); assertThat(guarded.snapshot(), is(CacheStats.empty())); verify(statsCounter).recordHits(1); verify(statsCounter).recordMisses(1); verify(statsCounter).recordEviction(); verify(statsCounter).recordEviction(10); verify(statsCounter).recordLoadSuccess(1); verify(statsCounter).recordLoadFailure(1); } }
@Test public void concurrent() { StatsCounter counter = new ConcurrentStatsCounter(); ConcurrentTestHarness.timeTasks(5, () -> { counter.recordHits(1); counter.recordMisses(1); counter.recordEviction(); counter.recordEviction(10); counter.recordLoadSuccess(1); counter.recordLoadFailure(1); }); assertThat(counter.snapshot(), is(new CacheStats(5, 5, 5, 5, 10, 10, 50))); }
@Test public void guarded() { StatsCounter counter = StatsCounter.guardedStatsCounter(new ConcurrentStatsCounter()); counter.recordHits(1); counter.recordMisses(1); counter.recordEviction(); counter.recordEviction(10); counter.recordLoadSuccess(1); counter.recordLoadFailure(1); CacheStats expected = new CacheStats(1, 1, 1, 1, 2, 2, 10); assertThat(counter.snapshot(), is(expected)); assertThat(counter.toString(), is(expected.toString())); assertThat(counter.snapshot().toString(), is(expected.toString())); }
/** * Records the eviction of an entry from the cache. This should only been called when an entry is * evicted due to the cache's eviction strategy, and not as a result of manual * {@link Cache#invalidate invalidations}. * * @param weight the weight of the evicted entry */ default void recordEviction(int weight) { // This method will be abstract in version 3.0.0 recordEviction(); }
@Override @SuppressWarnings("deprecation") public void recordEviction() { try { delegate.recordEviction(); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); } }
@Override public void recordEviction(int weight) { try { delegate.recordEviction(weight); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); } }
notifyRemoval(nodeKey[0], oldValue[0], cause[0]); statsCounter().recordEviction(weight[0]);
statsCounter().recordEviction(weight[0]);
statsCounter().recordEviction(node.getWeight()); if (hasRemovalListener()) {
notifyRemoval(nodeKey[0], oldValue[0], cause[0]); statsCounter().recordEviction(weight[0]);
statsCounter().recordEviction(weight[0]);
statsCounter().recordEviction(node.getWeight()); if (hasRemovalListener()) {