/** * Get the cumulative count since the start of the application for the given {@link HystrixRollingNumberEvent}. * * @param event * {@link HystrixRollingNumberEvent} of the event to retrieve a sum for * @return long cumulative count */ public long getCumulativeCount(HystrixRollingNumberEvent event) { return counter.getCumulativeSum(event); }
@Test public void testCumulativeCounterAfterRolling() { 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); } // cumulative count should be 20 (for the number of loops above) regardless of buckets rolling assertEquals(20, counter.getCumulativeSum(type)); }
@Test public void testCumulativeCounterAfterRollingAndReset3() { 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 } } // since we are rolling over the buckets it should reset naturally // 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)); }
@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)); }
/** * Get the cumulative count since the start of the application for the given {@link HystrixRollingNumberEvent}. * * @param event * {@link HystrixRollingNumberEvent} of the event to retrieve a sum for * @return long cumulative count */ public long getCumulativeCount(HystrixRollingNumberEvent event) { return counter.getCumulativeSum(event); }