public GetRollingSum ( HystrixRollingNumberEvent type ) : long | ||
type | HystrixRollingNumberEvent | defining which counter to retrieve values from |
return | long |
public void RollingNumber_EmptySum() { MockedTime time = new MockedTime(); HystrixRollingNumberEvent type = HystrixRollingNumberEvent.Collapsed; HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); Assert.AreEqual(0, counter.GetRollingSum(type)); }
public void RollingNumber_IncrementInMultipleBuckets() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); // increment counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Timeout); counter.Increment(HystrixRollingNumberEvent.Timeout); counter.Increment(HystrixRollingNumberEvent.ShortCircuited); // sleep to get to a new bucket time.Increment(counter.BucketSizeInMilliseconds * 3); // increment counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Timeout); counter.Increment(HystrixRollingNumberEvent.ShortCircuited); // we should have 4 buckets Assert.AreEqual(4, counter.Buckets.Size); // the counts of the last bucket Assert.AreEqual(2, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Success).Sum()); Assert.AreEqual(3, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Failure).Sum()); Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Timeout).Sum()); Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.ShortCircuited).Sum()); // the total counts Assert.AreEqual(6, counter.GetRollingSum(HystrixRollingNumberEvent.Success)); Assert.AreEqual(5, counter.GetRollingSum(HystrixRollingNumberEvent.Failure)); Assert.AreEqual(3, counter.GetRollingSum(HystrixRollingNumberEvent.Timeout)); Assert.AreEqual(2, counter.GetRollingSum(HystrixRollingNumberEvent.ShortCircuited)); // wait until window passes time.Increment(counter.TimeInMilliseconds); // increment counter.Increment(HystrixRollingNumberEvent.Success); // the total counts should now include only the last bucket after a reset since the window passed Assert.AreEqual(1, counter.GetRollingSum(HystrixRollingNumberEvent.Success)); Assert.AreEqual(0, counter.GetRollingSum(HystrixRollingNumberEvent.Failure)); Assert.AreEqual(0, counter.GetRollingSum(HystrixRollingNumberEvent.Timeout)); } catch (Exception e) { TestContext.WriteLine(e.ToString()); Assert.Fail("Exception: " + e.Message); } }
public void RollingNumber_CounterRetrievalRefreshesBuckets() { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); // increment counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Success); counter.Increment(HystrixRollingNumberEvent.Failure); counter.Increment(HystrixRollingNumberEvent.Failure); // sleep to get to a new bucket time.Increment(counter.BucketSizeInMilliseconds * 3); // we should have 1 bucket since nothing has triggered the update of buckets in the elapsed time Assert.AreEqual(1, counter.Buckets.Size); // the total counts Assert.AreEqual(4, counter.GetRollingSum(HystrixRollingNumberEvent.Success)); Assert.AreEqual(2, counter.GetRollingSum(HystrixRollingNumberEvent.Failure)); // we should have 4 buckets as the counter 'gets' should have triggered the buckets being created to fill in time Assert.AreEqual(4, counter.Buckets.Size); // wait until window passes time.Increment(counter.TimeInMilliseconds); // the total counts should all be 0 (and the buckets cleared by the get, not only increment) Assert.AreEqual(0, counter.GetRollingSum(HystrixRollingNumberEvent.Success)); Assert.AreEqual(0, counter.GetRollingSum(HystrixRollingNumberEvent.Failure)); // increment counter.Increment(HystrixRollingNumberEvent.Success); // the total counts should now include only the last bucket after a reset since the window passed Assert.AreEqual(1, counter.GetRollingSum(HystrixRollingNumberEvent.Success)); Assert.AreEqual(0, counter.GetRollingSum(HystrixRollingNumberEvent.Failure)); } catch (Exception e) { TestContext.WriteLine(e.ToString()); Assert.Fail("Exception: " + e.Message); } }
private void TestCounterType(HystrixRollingNumberEvent type) { MockedTime time = new MockedTime(); try { HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10); // increment counter.Increment(type); // we should have 1 bucket Assert.AreEqual(1, counter.Buckets.Size); // the count should be 1 Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(type).Sum()); Assert.AreEqual(1, counter.GetRollingSum(type)); // sleep to get to a new bucket time.Increment(counter.BucketSizeInMilliseconds * 3); // increment again in latest bucket counter.Increment(type); // we should have 4 buckets Assert.AreEqual(4, counter.Buckets.Size); // the counts of the last bucket Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(type).Sum()); // the total counts Assert.AreEqual(2, counter.GetRollingSum(type)); } catch (Exception e) { TestContext.WriteLine(e.ToString()); Assert.Fail("Exception: " + e.Message); } }