/// <summary> /// Constructor for DefaultRetryPolicy. /// </summary> /// <param name="config">The Client config object. This is used to /// retrieve the maximum number of retries before throwing /// back a exception(This does not count the initial request) and /// the service URL for the request.</param> public DefaultRetryPolicy(IClientConfig config) { this.MaxRetries = config.MaxErrorRetry; if (config.ThrottleRetries) { string serviceURL = config.DetermineServiceURL(); _retryCapacity = _capacityManagerInstance.GetRetryCapacity(serviceURL); } }
public void AcquireCapacityInvalidUnitTest() { int throttleRetryCount = 0; int throttleRetryCost = 5; int throttleCost = 1; CapacityManager capacityManagerInstance = new CapacityManager(throttleRetryCount, throttleRetryCost, throttleCost); retryCapacity = capacityManagerInstance.GetRetryCapacity("AcquireCapacityInvalidUnitTest"); Assert.IsNotNull(retryCapacity); Assert.IsFalse(capacityManagerInstance.TryAcquireCapacity(retryCapacity)); Assert.AreEqual(0, retryCapacity.AvailableCapacity); var consumedCapacity = retryCapacity.MaxCapacity - retryCapacity.AvailableCapacity; Assert.AreEqual(0, consumedCapacity); }
public void ReleaseCapacityUnitTest() { int throttleRetryCount = 5; int throttleRetryCost = 5; int throttleCost = 1; CapacityManager capacityManagerInstance = new CapacityManager(throttleRetryCount, throttleRetryCost, throttleCost); retryCapacity = capacityManagerInstance.GetRetryCapacity("ReleaseCapacityUnitTest"); Assert.IsNotNull(retryCapacity); Assert.IsTrue(capacityManagerInstance.TryAcquireCapacity(retryCapacity)); capacityManagerInstance.TryReleaseCapacity(true, retryCapacity); Assert.AreEqual(throttleRetryCost * throttleRetryCount, retryCapacity.AvailableCapacity); var consumedCapacity = retryCapacity.MaxCapacity - retryCapacity.AvailableCapacity; Assert.AreEqual(0, consumedCapacity); capacityManagerInstance.TryReleaseCapacity(false, retryCapacity); Assert.AreEqual(throttleRetryCost * throttleRetryCount, retryCapacity.AvailableCapacity); consumedCapacity = retryCapacity.MaxCapacity - retryCapacity.AvailableCapacity; Assert.AreEqual(0, consumedCapacity); }