/** * Get the total amount for all updates. */ public Long getTotalAmount() { return totalAmount.getCurrentCount(0); }
/** * Get the total number of updates. */ public Long getCount() { return count.getCurrentCount(0); }
/** * Get the total number of updates. */ public Long getCount() { return count.getCurrentCount(0); }
/** * {@inheritDoc} */ @Override public Long getValue(int pollerIndex) { final long cnt = count.getCurrentCount(pollerIndex); final long total = totalAmount.getCurrentCount(pollerIndex); final long value = (long) ((double) total / cnt); return (cnt == 0) ? 0L : value; }
/** * {@inheritDoc} */ @Override public Long getValue(int pollerIndex) { final long cnt = count.getCurrentCount(pollerIndex); final long value = (long) (getTotal(pollerIndex) / cnt); return (cnt == 0) ? 0L : value; }
@Test public void testSimpleTransition() { long start = time(1); clock.set(start); StepCounter c = newInstance("c"); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 0L); clock.set(start + 2000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 1L); clock.set(start + 8000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 0.0, DELTA); assertEquals(c.getCurrentCount(1), 2L); clock.set(start + 12000); c.increment(); assertEquals(c.getValue(1).doubleValue(), 2.0 / 10.0, DELTA); assertEquals(c.getCurrentCount(1), 1L); }
@Test public void testMissedIntervalNoIncrements() { clock.set(time(1)); StepCounter c = newInstance("foo"); c.getValue(1); // Gaps without polling c.increment(5); clock.set(time(34)); // Check counts, previous and current interval should be 0 assertEquals(c.getValue(1).doubleValue(), 0.0); assertEquals(c.getCurrentCount(1), 0); }
@Test public void testNonMonotonicClock() { clock.set(time(1)); StepCounter c = newInstance("foo"); c.getValue(1); c.increment(); c.increment(); clock.set(time(10)); c.increment(); clock.set(time(9)); // Should get ignored c.increment(); assertEquals(c.getCurrentCount(1), 2); c.increment(); clock.set(time(10)); c.increment(); c.increment(); assertEquals(c.getCurrentCount(1), 5); // Check rate for previous interval assertEquals(c.getValue(1).doubleValue(), 0.2, DELTA); }
@Test public void testBoundaryTransition() { clock.set(time(1)); StepCounter c = newInstance("foo"); // Should all go to one bucket c.increment(); clock.set(time(4)); c.increment(); clock.set(time(9)); c.increment(); // Should cause transition clock.set(time(10)); c.increment(); clock.set(time(19)); c.increment(); // Check counts assertEquals(c.getValue(1).doubleValue(), 0.3, DELTA); assertEquals(c.getCurrentCount(1), 2); }
@Test public void testMissedInterval() { clock.set(time(1)); StepCounter c = newInstance("foo"); c.getValue(1); // Multiple updates without polling c.increment(1); clock.set(time(4)); c.increment(1); clock.set(time(14)); c.increment(1); clock.set(time(24)); c.increment(1); clock.set(time(34)); c.increment(1); // Check counts assertEquals(c.getValue(1).doubleValue(), 0.1); assertEquals(c.getCurrentCount(1), 1); }
/** * Get the total amount for all updates. */ public Long getTotalAmount() { return totalAmount.getCurrentCount(0); }
/** * {@inheritDoc} */ @Override public Long getValue(int pollerIndex) { final long cnt = count.getCurrentCount(pollerIndex); final long total = totalAmount.getCurrentCount(pollerIndex); final long value = (long) ((double) total / cnt); return (cnt == 0) ? 0L : value; }
/** * Get the total number of updates. */ public Long getCount() { return count.getCurrentCount(0); }
/** * Get the total number of updates. */ public Long getCount() { return count.getCurrentCount(0); }
/** * {@inheritDoc} */ @Override public Long getValue(int pollerIndex) { final long cnt = count.getCurrentCount(pollerIndex); final long value = (long) (getTotal(pollerIndex) / cnt); return (cnt == 0) ? 0L : value; }