public void Should_reject_with_throttled_result_when_rejection_probability_allows() { options = new AdaptiveThrottlingOptions(Guid.NewGuid().ToString(), 1, minimumRequests, criticalRatio, 1.0); module = new AdaptiveThrottlingModule(options); Accept(1); while (module.RejectionProbability < 0.999) { Reject(1); } for (var i = 0; i < 100; i++) { var requestsBefore = module.Requests; var acceptsBefore = module.Accepts; var result = Execute(acceptedResult); if (result.Status == ClusterResultStatus.Throttled) { module.Requests.Should().Be(requestsBefore + 1); module.Accepts.Should().Be(acceptsBefore); return; } } throw new AssertionFailedException("No requests were rejected in 100 attempts, which was highly expected."); }
public void Setup() { replica = new Uri("http://replica"); request = Request.Get("foo/bar"); acceptedResult = new ClusterResult(ClusterResultStatus.Success, new[] { new ReplicaResult(replica, new Response(ResponseCode.Accepted), ResponseVerdict.Accept, TimeSpan.Zero) }, null, request); rejectedResult = new ClusterResult(ClusterResultStatus.ReplicasExhausted, new[] { new ReplicaResult(replica, new Response(ResponseCode.TooManyRequests), ResponseVerdict.Reject, TimeSpan.Zero) }, null, request); context = Substitute.For <IRequestContext>(); context.Log.Returns(new SilentLog()); options = new AdaptiveThrottlingOptions(Guid.NewGuid().ToString(), 1, minimumRequests); module = new AdaptiveThrottlingModule(options); }
/// <summary> /// Drops all ClusterClient caches. It also drops cache of <see cref="ReplicaBudgetingModule"/> and <see cref="AdaptiveThrottlingModule"/>. /// </summary> public static void Clean() { ReplicaBudgetingModule.ClearCache(); AdaptiveThrottlingModule.ClearCache(); ReplicaStorageContainer <int> .Shared.Clear(); ReplicaStorageContainer <long> .Shared.Clear(); ReplicaStorageContainer <bool> .Shared.Clear(); ReplicaStorageContainer <double> .Shared.Clear(); ReplicaStorageContainer <DateTime> .Shared.Clear(); ReplicaStorageContainer <HealthWithDecay> .Shared.Clear(); }