DisabledRateLimitedCache implements RateLimitedCache<K> { @Override public boolean acquire(K key, final Runnable cacheHit) { if (cache.putIfAbsent(key, true) != null) { cacheHit.run(); return false; } return true; } @java.beans.ConstructorProperties({ "cache" })  DisabledRateLimitedCache(final ConcurrentMap<K, Boolean> cache); @Override boolean acquire(K key, final Runnable cacheHit); @Override int size();  }
@Test public void testCache() { final DisabledRateLimitedCache<String> writeCache = new DisabledRateLimitedCache<>(cache); assertTrue(writeCache.acquire("key1", notifier)); assertFalse(writeCache.acquire("key1", notifier)); assertTrue(writeCache.acquire("key2", notifier)); verify(notifier, atLeastOnce()).run(); }