Пример #1
0
        public async Task GetAsync_Returns_Available_Tokens_If_Request_Exceeds_Available_Count()
        {
            using (var t = new TokenBucket(10, 10000))
            {
                await t.GetAsync(6);

                var count = await t.GetAsync(6);

                Assert.Equal(4, count);
            }
        }
Пример #2
0
        public async Task GetAsync_Waits_For_Reset_If_Bucket_Is_Depleted()
        {
            using (var t = new TokenBucket(1, 10))
            {
                await t.GetAsync(1);

                await t.GetAsync(1);

                await t.GetAsync(1);

                Assert.True(true);
            }
        }
Пример #3
0
        public async Task GetAsync_Decrements_Count_By_Requested_Count()
        {
            using (var t = new TokenBucket(10, 10000))
            {
                await t.GetAsync(5);

                Assert.Equal(5, t.GetProperty <long>("CurrentCount"));
            }
        }
Пример #4
0
        public async Task GetAsync_Returns_Capacity_If_Request_Exceeds_Capacity()
        {
            using (var t = new TokenBucket(10, 10000))
            {
                int tokens = 0;
                var ex     = await Record.ExceptionAsync(async() => tokens = await t.GetAsync(11));

                Assert.Null(ex);
                Assert.Equal(10, tokens);
            }
        }
Пример #5
0
        public async Task Return_Adds_Given_Value()
        {
            using (var t = new TokenBucket(10, 1000000))
            {
                await t.GetAsync(5);

                Assert.Equal(5, t.GetProperty <long>("CurrentCount"));

                t.Return(5);

                Assert.Equal(10, t.GetProperty <long>("CurrentCount"));
            }
        }
Пример #6
0
        public async Task Return_Does_Not_Change_Count_Given_Negative()
        {
            using (var t = new TokenBucket(10, 1000000))
            {
                await t.GetAsync(5);

                Assert.Equal(5, t.GetProperty <long>("CurrentCount"));

                t.Return(-5);

                Assert.Equal(5, t.GetProperty <long>("CurrentCount"));
            }
        }