public TryAcquireCapacity ( |
||
retryCapacity | Contains the RetryCapacity object for the said ServiceURL. | |
Résultat | bool |
public override bool OnRetry(IExecutionContext executionContext) { if (executionContext.RequestContext.ClientConfig.ThrottleRetries && _retryCapacity != null) { return(_capacityManagerInstance.TryAcquireCapacity(_retryCapacity)); } return(true); }
/// <summary> /// Virtual method that gets called when a retry request is initiated. If retry throttling is /// enabled, the value returned is true if the required capacity is retured, false otherwise. /// If retry throttling is disabled, true is returned. /// </summary> /// <param name="executionContext">The execution context which contains both the /// requests and response context.</param> /// <param name="bypassAcquireCapacity">true to bypass any attempt to acquire capacity on a retry</param> /// <param name="isThrottlingError">true if the error that will be retried is a throtting error</param> public override bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity, bool isThrottlingError) { if (!bypassAcquireCapacity && executionContext.RequestContext.ClientConfig.ThrottleRetries && RetryCapacity != null) { return(_capacityManagerInstance.TryAcquireCapacity(RetryCapacity, executionContext.RequestContext.LastCapacityType)); } return(true); }
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); }