PeakRateCounter extends AbstractMonitor<Number> implements Counter { @Override public void increment() { increment(1L); } PeakRateCounter(MonitorConfig config);   PeakRateCounter(MonitorConfig config, Clock clock); @Override Number getValue(int pollerIdx); @Override boolean equals(Object obj); @Override int hashCode(); String toString(); @Override void increment(); @Override void increment(long amount);  }
@Test public void testIncrement() throws Exception { PeakRateCounter c = newInstance("foo"); assertEquals(c.getValue().longValue(), 0L); for (int i = 0; i < 5; i++) { clock.set(i * 1000L); c.increment(); } assertEquals(c.getValue().longValue(), 1L, "Delta of 5 in 5 seconds, e.g. peak rate = average, 1 per second"); for (int i = 0; i < 5; i++) { clock.set((5 + i) * 1000L); c.increment(3); } assertEquals(c.getValue().longValue(), 3L, "Delta of 15 in 5 seconds, e.g. peak rate = average, 3 per second"); clock.set(10 * 1000L); c.increment(10); for (int i = 0; i < 3; i++) { clock.set((11 + i) * 1000L); c.increment(3); } c.increment(); assertEquals(c.getValue().longValue(), 10L, "Delta of 15 in 5 seconds, e.g. peak rate = 10, average = 3, min = 1 per second"); clock.set(19 * 1000L); assertEquals(c.getValue().longValue(), 10L, "Delta of 0 in 5 seconds, e.g. peak rate = previous max, 10 per second"); }