public RetryPolicy( int maximumRetryCount, TransientFaultDetectionStrategy <TResult> transientFaultDetectionStrategy, RetryIntervalStrategy retryIntervalStrategy) : base(maximumRetryCount, transientFaultDetectionStrategy, retryIntervalStrategy) { TransientFaultDetectionStrategy = transientFaultDetectionStrategy; }
public void IsTransientResult_returns_false() { var fixture = new Fixture(); var result = fixture.Create <Result>(); var sut = new TransientFaultDetectionStrategy <Result>(); bool actual = sut.IsTransientResult(result); actual.Should().BeFalse(); }
public void IsTransientException_returns_true() { var sut = new TransientFaultDetectionStrategy(); var fixture = new Fixture(); var exception = fixture.Create <Exception>(); bool actual = sut.IsTransientException(exception); actual.Should().BeTrue(); }
public RetryPolicy( int maximumRetryCount, TransientFaultDetectionStrategy transientFaultDetectionStrategy, RetryIntervalStrategy retryIntervalStrategy) { if (maximumRetryCount < 0) { throw new ArgumentOutOfRangeException(nameof(maximumRetryCount), "Value cannot be negative."); } MaximumRetryCount = maximumRetryCount; TransientFaultDetectionStrategy = transientFaultDetectionStrategy ?? throw new ArgumentNullException(nameof(transientFaultDetectionStrategy)); RetryIntervalStrategy = retryIntervalStrategy ?? throw new ArgumentNullException(nameof(retryIntervalStrategy)); }
private async Task PerformRun( Func <CancellationToken, Task> operation, CancellationToken cancellationToken) { int retryCount = 0; Try: try { await operation.Invoke(cancellationToken).ConfigureAwait(false); } catch (Exception exception) when(TransientFaultDetectionStrategy.IsTransientException(exception) && retryCount < MaximumRetryCount) { await Task.Delay(RetryIntervalStrategy.GetInterval(retryCount)); retryCount++; goto Try; } }