ShardedCounter { CounterSnapshot getCounterSnapshot(String counterId) throws IOException { final CounterSnapshot snapshot = inMemSnapshot.getIfPresent(counterId); if (snapshot != null) { stats.recordCounterCacheHit(); return snapshot; } stats.recordCounterCacheMiss(); return refreshCounterSnapshot(counterId); } ShardedCounter(Stats stats, CounterSnapshotFactory counterSnapshotFactory); boolean counterHasSpareCapacity(String resourceId); void updateCounter(StorageTransaction transaction, String counterId, long delta); static final int NUM_SHARDS; static final String KIND_COUNTER_LIMIT; static final String PROPERTY_LIMIT; static final String KIND_COUNTER_SHARD; static final String PROPERTY_SHARD_VALUE; static final String PROPERTY_SHARD_INDEX; static final String PROPERTY_COUNTER_ID; }
@Test public void shouldReportCacheHitMissMetrics() throws IOException { InOrder inOrder = Mockito.inOrder(stats, counterSnapshotFactory); shardedCounter.getCounterSnapshot(COUNTER_ID1); inOrder.verify(stats).recordCounterCacheMiss(); inOrder.verify(counterSnapshotFactory).create(COUNTER_ID1); shardedCounter.getCounterSnapshot(COUNTER_ID1); inOrder.verify(stats).recordCounterCacheHit(); shardedCounter.getCounterSnapshot(COUNTER_ID1); inOrder.verify(stats).recordCounterCacheHit(); shardedCounter.inMemSnapshot.invalidate(COUNTER_ID1); shardedCounter.getCounterSnapshot(COUNTER_ID1); inOrder.verify(stats).recordCounterCacheMiss(); inOrder.verify(counterSnapshotFactory).create(COUNTER_ID1); inOrder.verifyNoMoreInteractions(); }