Beispiel #1
0
        public void RollingNumber_CumulativeCounterAfterRollingAndReset3()
        {
            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
                }
            }

            // 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
            Assert.AreEqual(5, counter.GetCumulativeSum(type));
        }
Beispiel #2
0
        public void RollingNumber_CumulativeCounterAfterRolling()
        {
            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);
            }

            // cumulative count should be 20 (for the number of loops above) regardless of buckets rolling
            Assert.AreEqual(20, counter.GetCumulativeSum(type));
        }
Beispiel #3
0
            public void NotImplemented()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long cumulativeSum = rollingNumber.GetCumulativeSum(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, cumulativeSum);
            }
Beispiel #4
0
            public void NotImplemented()
            {
                var dateTimeProvider = new Mock <IDateTimeProvider>();
                var rollingNumber    = new HystrixRollingNumber(dateTimeProvider.Object, 10000, 10);

                // Act
                long cumulativeSum = rollingNumber.GetCumulativeSum(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, cumulativeSum);
            }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
 public virtual long GetCumulativeCount(HystrixRollingNumberEvent @event)
 {
     return(counter.GetCumulativeSum(@event));
 }