@Override public CacheStats snapshot() { return CacheStats.empty(); }
@Override public CacheStats snapshot() { try { return delegate.snapshot(); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); return CacheStats.empty(); } }
@Test public void empty() { CacheStats stats = new CacheStats(0, 0, 0, 0, 0, 0, 0); checkStats(stats, 0, 0, 1.0, 0, 0.0, 0, 0, 0.0, 0, 0, 0.0, 0, 0); assertThat(stats, is(equalTo(CacheStats.empty()))); assertThat(stats, is(not(equalTo(null)))); assertThat(stats, is(not(equalTo(new Object())))); assertThat(stats, is(equalTo(CacheStats.empty()))); assertThat(stats.hashCode(), is(CacheStats.empty().hashCode())); assertThat(stats, hasToString(CacheStats.empty().toString())); }
@Test public void populated() { CacheStats stats = new CacheStats(11, 13, 17, 19, 23, 27, 54); checkStats(stats, 24, 11, 11.0/24, 13, 13.0/24, 17, 19, 19.0/36, 17 + 19, 23, 23.0/(17 + 19), 27, 54); assertThat(stats, is(equalTo(stats))); assertThat(stats, is(not(equalTo(CacheStats.empty())))); assertThat(stats.hashCode(), is(not(CacheStats.empty().hashCode()))); assertThat(stats, hasToString(not(CacheStats.empty().toString()))); CacheStats expected = new CacheStats(11, 13, 17, 19, 23, 27, 54); assertThat(stats, is(equalTo(expected))); assertThat(stats.hashCode(), is(expected.hashCode())); assertThat(stats, hasToString(expected.toString())); }
@Test public void minus() { CacheStats one = new CacheStats(11, 13, 17, 19, 23, 27, 54); CacheStats two = new CacheStats(53, 47, 43, 41, 37, 31, 62); CacheStats diff = two.minus(one); checkStats(diff, 76, 42, 42.0 / 76, 34, 34.0 / 76, 26, 22, 22.0 / 48, 26 + 22, 14, 14.0 / (26 + 22), 4, 8); assertThat(one.minus(two), is(CacheStats.empty())); }
@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); } }
@Override public CacheStats snapshot() { return CacheStats.empty(); }
@Override public CacheStats snapshot() { try { return delegate.snapshot(); } catch (Throwable t) { logger.log(Level.WARNING, "Exception thrown by stats counter", t); return CacheStats.empty(); } }
@Override public CacheStats cacheStats() { return cache != null ? cache.stats() : CacheStats.empty(); }
@Override public CacheStats cacheStats() { return cache != null ? cache.stats() : CacheStats.empty(); }
@Override public CacheStats cacheStats() { return cache != null ? cache.stats() : CacheStats.empty(); }