} else if (currentTime - (lastBucket.windowStart + this.bucketSizeInMillseconds) > timeInMilliseconds) { reset();
@Test public void testCumulativeCounterAfterRollingAndReset() { MockedTime time = new MockedTime(); HystrixRollingNumberEvent type = HystrixRollingNumberEvent.SUCCESS; HystrixRollingNumber counter = new HystrixRollingNumber(time, 20, 2); assertEquals(0, counter.getCumulativeSum(type)); // iterate over 20 buckets on a queue sized for 2 for (int i = 0; i < 20; i++) { // first bucket counter.increment(type); try { time.increment(counter.bucketSizeInMillseconds); } catch (Exception e) { // ignore } assertEquals(2, counter.getValues(type).length); counter.getValueOfLatestBucket(type); if (i == 5 || i == 15) { // simulate a reset occurring every once in a while // so we ensure the absolute sum is handling it okay counter.reset(); } } // cumulative count should be 20 (for the number of loops above) regardless of buckets rolling assertEquals(20, counter.getCumulativeSum(type)); }
@Test public void testCumulativeCounterAfterRollingAndReset2() { MockedTime time = new MockedTime(); HystrixRollingNumberEvent type = HystrixRollingNumberEvent.SUCCESS; HystrixRollingNumber counter = new HystrixRollingNumber(time, 20, 2); assertEquals(0, counter.getCumulativeSum(type)); counter.increment(type); counter.increment(type); counter.increment(type); // iterate over 20 buckets on a queue sized for 2 for (int i = 0; i < 20; i++) { try { time.increment(counter.bucketSizeInMillseconds); } catch (Exception e) { // ignore } if (i == 5 || i == 15) { // simulate a reset occurring every once in a while // so we ensure the absolute sum is handling it okay counter.reset(); } } // no increments during the loop, just some before and after counter.increment(type); counter.increment(type); // cumulative count should be 5 regardless of buckets rolling assertEquals(5, counter.getCumulativeSum(type)); }
public void resetCounter() { // TODO can we do without this somehow? counter.reset(); lastHealthCountsSnapshot.set(System.currentTimeMillis()); healthCountsSnapshot = new HealthCounts(0, 0, 0); }
} else if (currentTime - (lastBucket.windowStart + this.bucketSizeInMillseconds) > timeInMilliseconds) { reset();