Exemple #1
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)));
        }
Exemple #2
0
        public void TestSetup()
        {
            essentials = new ThrottlingEssentials
            {
                Enabled = true,
                CapacityLimitPerCore = 10,
                QueueLimit           = 123,
                RefreshPeriod        = 1.Seconds()
            };

            builder = new ThrottlingConfigurationBuilder();
            builder.SetEssentials(() => essentials);

            state = new ThrottlingState();
        }
Exemple #3
0
        public void TestSetup()
        {
            essentials = new ThrottlingEssentials {
                RefreshPeriod = TimeSpan.Zero
            };

            configuration = new ThrottlingConfigurationBuilder()
                            .SetEssentials(() => essentials)
                            .Build();

            actualizer = Substitute.For <IThrottlingStateActualizer>();
            provider   = new ThrottlingStateProvider(configuration, actualizer);

            state = provider.ObtainState();

            actualizer.ClearReceivedCalls();
        }
Exemple #4
0
 public void TestSetup()
 => state = new ThrottlingState();