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

GetBuckets() private method

Returns all bucket in reverse order (most recent first)
private GetBuckets ( long startWindowTime ) : IEnumerable
startWindowTime long
return IEnumerable
        internal IEnumerable<Bucket> GetBuckets(long startWindowTime = 0)
        {
            var idx = currentBucketIndex;
            if (startWindowTime == 0)
                startWindowTime = clock.EllapsedTimeInMs - (numberOfBuckets * bucketSizeInMs);

            var cx = numberOfBuckets;
            while (cx-- > 0)
            {
                var b = buckets[idx];
                if (b.bucketStartInMs < startWindowTime) break;
                yield return b;
                idx = (idx - 1);
                if (idx < 0) idx = numberOfBuckets;
            }
        }

Usage Example

        public void testCreatesBuckets()
        {
            var time = new MockedClock();

            var counter = new RollingNumber(time, 200, 10);
            // confirm the initial settings
            Assert.Equal(200, counter.TimeInMs);
            Assert.Equal(10, counter.NumberOfBuckets);
            Assert.Equal(20, counter.BucketSizeInMs);


            // add a Success in each interval which should result in all 10 buckets being created with 1 Success in each
            for (int i = 0; i < counter.NumberOfBuckets; i++)
            {
                counter.Increment(RollingNumberEvent.SUCCESS);
                time.Increment(counter.BucketSizeInMs);
            }

            // confirm we have all 10 buckets
            var buckets = counter.GetBuckets().ToArray();
            Assert.Equal(10, buckets.Length);

            // add 1 more and we should still only have 10 buckets since that's the max
            counter.Increment(RollingNumberEvent.SUCCESS);
            buckets = counter.GetBuckets().ToArray();
            Assert.Equal(10, buckets.Length);
        }
All Usage Examples Of Jellyfish.Commands.Metrics.RollingNumber::GetBuckets