LoggingRateLimiter { public void resetAfterLimit() { if (System.currentTimeMillis() - limit > lastCleared.getTime()) { frequency = ConcurrentHashMultiset.create(); lastCleared = new Date( System.currentTimeMillis()); } } LoggingRateLimiter(int limit);  LoggingRateLimiter(); void addAndEnsureFrequency(T clazz); void resetAfterLimit(); void capacityAvailable(T t, long max, Runnable run);  }
@Test public void testDoesNotReset(){ ConcurrentHashMultiset freq = rateLimiter.getFrequency(); rateLimiter.resetAfterLimit(); assertThat (freq,is( rateLimiter.getFrequency())); }
@Test public void testResetAfterLimit() throws InterruptedException { rateLimiter = new LoggingRateLimiter(0); ConcurrentHashMultiset freq = rateLimiter.getFrequency(); rateLimiter.resetAfterLimit(); assertTrue (freq != rateLimiter.getFrequency() ); freq = rateLimiter.getFrequency(); Thread.sleep(1); rateLimiter.resetAfterLimit(); assertThat (freq,is( rateLimiter.getFrequency())); }