@Test public void testMaxHitRateTracker() { int timeInSec = 60; MaxHitRateTracker hitCounter = new MaxHitRateTracker(timeInSec); long currentTimestamp = System.currentTimeMillis(); for (int i = 0; i < timeInSec; i++) { for (int j = 0; j < 5; j++) { hitCounter.hit(currentTimestamp + i * 1000); } } long latestTimeStamp = currentTimestamp + (timeInSec - 1) * 1000; Assert.assertNotNull(hitCounter); Assert.assertEquals(5, hitCounter.getMaxCountPerBucket(latestTimeStamp)); latestTimeStamp = latestTimeStamp + 2000L; Assert.assertEquals(5, hitCounter.getMaxCountPerBucket(latestTimeStamp)); latestTimeStamp = latestTimeStamp + 2000L; Assert.assertEquals(0, hitCounter.getMaxCountPerBucket(latestTimeStamp)); hitCounter.hit(latestTimeStamp); latestTimeStamp = latestTimeStamp + 2000L; Assert.assertEquals(1, hitCounter.getMaxCountPerBucket(latestTimeStamp)); hitCounter.hit(latestTimeStamp); latestTimeStamp = latestTimeStamp + timeInSec * 2 * 1000L + 2000L; Assert.assertEquals(0, hitCounter.getMaxCountPerBucket(latestTimeStamp)); }
public MaxHitRateTracker(int timeRangeInSeconds) { this(timeRangeInSeconds, timeRangeInSeconds * MAX_TIME_RANGE_FACTOR); }
MaxHitRateTracker extends HitCounter { public MaxHitRateTracker(int timeRangeInSeconds) { this(timeRangeInSeconds, timeRangeInSeconds * MAX_TIME_RANGE_FACTOR); } }
MaxHitRateTracker extends HitCounter { public MaxHitRateTracker(int timeRangeInSeconds) { this(timeRangeInSeconds, timeRangeInSeconds * MAX_TIME_RANGE_FACTOR); } MaxHitRateTracker(int timeRangeInSeconds); private  MaxHitRateTracker(int defaultTimeRangeInSeconds, int maxTimeRangeInSeconds); }
MaxHitRateTracker extends HitCounter { public MaxHitRateTracker(int timeRangeInSeconds) { this(timeRangeInSeconds, timeRangeInSeconds * MAX_TIME_RANGE_FACTOR); } MaxHitRateTracker(int timeRangeInSeconds); private  MaxHitRateTracker(int defaultTimeRangeInSeconds, int maxTimeRangeInSeconds); int getMaxCountPerBucket(); }
MaxHitRateTracker extends HitCounter { public MaxHitRateTracker(int timeRangeInSeconds) { this(timeRangeInSeconds, timeRangeInSeconds * MAX_TIME_RANGE_FACTOR); } MaxHitRateTracker(int timeRangeInSeconds); private  MaxHitRateTracker(int defaultTimeRangeInSeconds, int maxTimeRangeInSeconds); int getMaxCountPerBucket();  }