Beispiel #1
0
        public void TestMaxValue()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumberEvent type = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;

                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                counter.UpdateRollingMax(type, 10);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 30);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 40);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 15);

                Assert.Equal(40, counter.GetRollingMaxValue(type));
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }
Beispiel #2
0
        public void RollingNumber_MaxValue()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumberEvent type = HystrixRollingNumberEvent.ThreadMaxActive;

                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                counter.UpdateRollingMax(type, 10);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 30);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 40);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 15);

                Assert.AreEqual(40, counter.GetRollingMaxValue(type));
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #3
0
        public void RollingNumber_EmptyMax()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.ThreadMaxActive;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.AreEqual(0, counter.GetRollingMaxValue(type));
        }
Beispiel #4
0
        public void TestEmptyMax()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.Equal(0, counter.GetRollingMaxValue(type));
        }
Beispiel #5
0
            public void Returns_Zero_If_No_Values_Have_Been_Recorded()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long rollingMaxValue = rollingNumber.GetRollingMaxValue(HystrixRollingNumberEvent.Success);

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

                // Act
                long rollingMaxValue = rollingNumber.GetRollingMaxValue(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, rollingMaxValue);
            }
Beispiel #7
0
        public void RollingNumber_UpdateMax2()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                // increment
                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 10);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 20);

                // we should have 1 bucket
                Assert.AreEqual(1, counter.Buckets.Size);

                // the count should be 30
                Assert.AreEqual(30, counter.Buckets.GetLast().GetMaxUpdater(HystrixRollingNumberEvent.ThreadMaxActive).Max());
                Assert.AreEqual(30, counter.GetRollingMaxValue(HystrixRollingNumberEvent.ThreadMaxActive));

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds * 3);

                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.ThreadMaxActive, 50);

                // we should have 4 buckets
                Assert.AreEqual(4, counter.Buckets.Size);

                // the count
                Assert.AreEqual(50, counter.Buckets.GetLast().GetMaxUpdater(HystrixRollingNumberEvent.ThreadMaxActive).Max());
                Assert.AreEqual(50, counter.GetValueOfLatestBucket(HystrixRollingNumberEvent.ThreadMaxActive));

                // values per bucket
                long[] values = counter.GetValues(HystrixRollingNumberEvent.ThreadMaxActive);
                Assert.AreEqual(30, values[0]); // oldest bucket
                Assert.AreEqual(0, values[1]);
                Assert.AreEqual(0, values[2]);
                Assert.AreEqual(50, values[3]); // latest bucket
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #8
0
        public void TestUpdateMax2()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                // Increment
                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 10);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 20);

                // we should have 1 bucket
                Assert.Equal(1, counter._buckets.Size);

                // the count should be 30
                Assert.Equal(30, counter._buckets.Last.GetMaxUpdater(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE).Max);
                Assert.Equal(30, counter.GetRollingMaxValue(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE));

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds * 3);

                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 30);
                counter.UpdateRollingMax(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE, 50);

                // we should have 4 buckets
                Assert.Equal(4, counter._buckets.Size);

                // the count
                Assert.Equal(50, counter._buckets.Last.GetMaxUpdater(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE).Max);
                Assert.Equal(50, counter.GetValueOfLatestBucket(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE));

                // values per bucket
                long[] values = counter.GetValues(HystrixRollingNumberEvent.THREAD_MAX_ACTIVE);
                Assert.Equal(30, values[0]); // oldest bucket
                Assert.Equal(0, values[1]);
                Assert.Equal(0, values[2]);
                Assert.Equal(50, values[3]); // latest bucket
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }