Exemplo n.º 1
0
        public void ThrottleAsync_should_reject_if_quotas_recheck_after_waiting_fails()
        {
            quota2.Check(properties, state).Returns(ThrottlingQuotaVerdict.Allow(), ThrottlingQuotaVerdict.Reject("for reasons"));

            DrainSemaphore();

            var task = ThrottleAsync();

            state.Semaphore.Release();

            task.Result.Status.Should().Be(ThrottlingStatus.RejectedDueToQuota);

            VerifyThereAreNoSideEffects(1);

            quota2.Received(2).Check(properties, state);
        }
Exemplo n.º 2
0
        public void TestSetup()
        {
            state = new ThrottlingState
            {
                Enabled       = true,
                CapacityLimit = Capacity,
                QueueLimit    = QueueLimit
            };

            state.Semaphore.Release(Capacity);

            stateProvider = Substitute.For <IThrottlingStateProvider>();
            stateProvider.ObtainState().Returns(state);

            quota1 = Substitute.For <IThrottlingQuota>();
            quota1.Check(Arg.Any <IReadOnlyDictionary <string, string> >(), Arg.Any <IThrottlingQuotaContext>()).Returns(ThrottlingQuotaVerdict.Allow());

            quota2 = Substitute.For <IThrottlingQuota>();
            quota2.Check(Arg.Any <IReadOnlyDictionary <string, string> >(), Arg.Any <IThrottlingQuotaContext>()).Returns(ThrottlingQuotaVerdict.Allow());

            state.Quotas = new[] { quota1, quota2 };

            errorCallback = Substitute.For <Action <Exception> >();
            provider      = new ThrottlingProvider(stateProvider, errorCallback);

            properties = new Dictionary <string, string> {
                ["foo"] = "bar"
            };
            events  = new List <IThrottlingEvent>();
            results = new List <IThrottlingResult>();

            provider.Subscribe(new TestObserver <IThrottlingEvent>(evt => events.Add(evt)));
            provider.Subscribe(new TestObserver <IThrottlingResult>(res => results.Add(res)));
        }
Exemplo n.º 3
0
        public void ThrottleAsync_should_reject_when_quotas_check_fails()
        {
            quota2.Check(properties, state).Returns(ThrottlingQuotaVerdict.Reject("for reasons"));

            Throttle().Status.Should().Be(ThrottlingStatus.RejectedDueToQuota);
        }