Пример #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)));
        }
Пример #2
0
 public IVostokThrottlingBuilder UseCustomQuota(IThrottlingQuota quota)
 {
     configurationBuilder.AddCustomQuota(quota);
     return(this);
 }
Пример #3
0
 public ThrottlingConfigurationBuilder AddCustomQuota([NotNull] IThrottlingQuota quota)
 {
     customQuotas.Add(quota ?? throw new ArgumentNullException(nameof(quota)));
     return(this);
 }