public void RollingNumber_CumulativeCounterAfterRollingAndReset2() { MockedTime time = new MockedTime(); HystrixRollingNumberEvent type = HystrixRollingNumberEvent.Success; HystrixRollingNumber counter = new HystrixRollingNumber(time, 20, 2); Assert.AreEqual(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.BucketSizeInMilliseconds); } catch (Exception) { // 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 Assert.AreEqual(5, counter.GetCumulativeSum(type)); }
public void RollingNumber_CumulativeCounterAfterRollingAndReset() { MockedTime time = new MockedTime(); HystrixRollingNumberEvent type = HystrixRollingNumberEvent.Success; HystrixRollingNumber counter = new HystrixRollingNumber(time, 20, 2); Assert.AreEqual(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.BucketSizeInMilliseconds); } catch (Exception) { // ignore } Assert.AreEqual(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 Assert.AreEqual(20, counter.GetCumulativeSum(type)); }