Jellyfish.Commands.Metrics.RollingNumber.GetValueOfLatestBucket C# (CSharp) Method

GetValueOfLatestBucket() private method

private GetValueOfLatestBucket ( RollingNumberEvent ev ) : long
ev RollingNumberEvent
return long
        internal long GetValueOfLatestBucket(RollingNumberEvent ev)
        {
            Bucket lastBucket = GetCurrentBucket();
            if (lastBucket == null)
                return 0;
            // we have bucket data so we'll return the lastBucket
            if ((int)ev > (int)RollingNumberEvent.MAX_COUNTER)
                return lastBucket.GetMaxUpdater(ev);
            else
                return lastBucket.GetAdder(ev);
        }

Usage Example

        public void testCumulativeCounterAfterRolling()
        {
            MockedClock time = new MockedClock();
            RollingNumberEvent type = RollingNumberEvent.SUCCESS;
            RollingNumber counter = new RollingNumber(time, 20, 2);

            Assert.Equal(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.BucketSizeInMs);
                }
                catch (Exception)
                {
                    // ignore
                }

                counter.GetValueOfLatestBucket(type);
                Assert.Equal(2, counter.GetValues(type).Count());

            }

            // cumulative count should be 20 (for the number of loops above) regardless of buckets rolling
            Assert.Equal(20, counter.GetCumulativeSum(type));
        }
All Usage Examples Of Jellyfish.Commands.Metrics.RollingNumber::GetValueOfLatestBucket