コード例 #1
0
        public async Task EnterUpToLimit()
        {
            var gate = new ConcurrentPolicyGate(_counterStore, 2);

            var enter = await gate.TryEnterAsync(new QosGateEnterContext()
            {
                Key = "k"
            });

            Assert.True(enter.Success);
            Assert.Equal(1, _counter);

            enter = await gate.TryEnterAsync(new QosGateEnterContext()
            {
                Key = "k"
            });

            Assert.True(enter.Success);
            Assert.Equal(2, _counter);

            enter = await gate.TryEnterAsync(new QosGateEnterContext()
            {
                Key = "k"
            });

            Assert.False(enter.Success);
            Assert.Equal(2, _counter);
        }
コード例 #2
0
        public async Task EnterThenExit()
        {
            var gate = new ConcurrentPolicyGate(_counterStore, 10);

            var enter = await gate.TryEnterAsync(new QosGateEnterContext()
            {
                Key = "k"
            });

            Assert.True(enter.Success);
            Assert.Equal(1, _counter);

            await gate.ExitAsync(new QosGateExitContext()
            {
                Key = "k"
            });

            Assert.Equal(0, _counter);
        }