@Managed public long getRequestCount() { return loadingCache.stats().requestCount(); } }
@Managed public Double getHitRate() { return loadingCache.stats().hitRate(); }
@Managed public Double getMissRate() { return loadingCache.stats().missRate(); }
/** * Gets the number of ASG queries done in the period. * * @return the long value representing the number of ASG queries done in the * period. */ @com.netflix.servo.annotations.Monitor(name = "numOfASGQueries", description = "Number of queries made to AWS to retrieve ASG information", type = DataSourceType.COUNTER) public long getNumberofASGQueries() { return asgCache.stats().loadCount(); }
/** * Gets the number of ASG queries that failed because of some reason. * * @return the long value representing the number of ASG queries that failed * because of some reason. */ @com.netflix.servo.annotations.Monitor(name = "numOfASGQueryFailures", description = "Number of queries made to AWS to retrieve ASG information and that failed", type = DataSourceType.COUNTER) public long getNumberofASGQueryFailures() { return asgCache.stats().loadExceptionCount(); }
public void testPutAll_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); Object newKey = new Object(); Object newValue = new Object(); cache.asMap().putAll(ImmutableMap.of(newKey, newValue)); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(newKey)); assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testReplace_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().replace(entry.getKey(), newValue)); assertTrue(cache.asMap().replace(entry.getKey(), newValue, entry.getValue())); Object newKey = new Object(); assertNull(cache.asMap().replace(newKey, entry.getValue())); assertFalse(cache.asMap().replace(newKey, entry.getValue(), newValue)); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); assertFalse(cache.asMap().containsKey(newKey)); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPutIfAbsent_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().putIfAbsent(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().putIfAbsent(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testContainsKey_found() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); assertTrue(cache.asMap().containsKey(entry.getKey())); assertTrue(cache.asMap().containsValue(entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPut_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().put(entry.getKey(), newValue)); // don't let the new entry get GCed warmed.add(entryOf(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().put(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPutAll_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed @SuppressWarnings("unused") List<Entry<Object, Object>> warmed = warmUp(cache); Object newKey = new Object(); Object newValue = new Object(); cache.asMap().putAll(ImmutableMap.of(newKey, newValue)); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(newKey)); assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testContainsKey_found() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); assertTrue(cache.asMap().containsKey(entry.getKey())); assertTrue(cache.asMap().containsValue(entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testBulkLoadInterruptedException() { Exception e = new InterruptedException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } assertTrue(currentThread().interrupted()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadCheckedException() { Exception e = new Exception(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadError() throws ExecutionException { Error e = new Error(); CacheLoader<Object, Object> loader = errorLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadNull() throws ExecutionException { LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(constantLoader(null))); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (InvalidCacheLoadException expected) { } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadUncheckedException() throws ExecutionException { Exception e = new RuntimeException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(1, stats.loadSuccessCount()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(1, stats.loadSuccessCount()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(1, stats.loadSuccessCount());