public async Task WhenBatchContainsAnyMessage_ShouldResetTime() { var strategy = new BackoffStrategy(peekInterval, maxWaitTime); const int emptyBatchCount = 5; for (var i = 0; i < emptyBatchCount; i++) { await strategy.OnBatch(0, CancellationToken.None); } var task = strategy.OnBatch(1, CancellationToken.None); Assert.True(task.IsCompleted); }
public async Task WhenBatchesAreEmpty_ShouldIncreaseWaitTime() { var strategy = new BackoffStrategy(peekInterval, maxWaitTime); const int emptyBatchCount = 5; for (var i = 0; i < emptyBatchCount; i++) { await strategy.OnBatch(0, CancellationToken.None); } var lowerBoundary = (int)(peekInterval.TotalMilliseconds * (emptyBatchCount - 1)); var delay = Task.Delay(lowerBoundary); Assert.AreSame(delay, await Task.WhenAny(strategy.OnBatch(0, CancellationToken.None), delay)); }
public IImmutableErrorContext MarkExceptionHandlerForRetry <TException, TResult>(int retryCount, int millisecondsInterval = 0, BackoffStrategy backoff = BackoffStrategy.None) where TException : Exception { var elevatedHandlerProvider = this.handlerProvider.MarkExceptionHandlerForRetry <TException, TResult>(retryCount, millisecondsInterval, backoff); return(new ImmutableErrorContext(this.log, this.tryCatchBlockProvider, elevatedHandlerProvider)); }
public IResultContractContext <TResult> WithRetryOf(int count, int millisecondsInterval = 0, BackoffStrategy backoff = BackoffStrategy.None) { var elevatedErrorContext = this.bundle.Errors.MarkExceptionHandlerForRetry <TException, TResult>(count, millisecondsInterval, backoff); var elevatedBundle = this.bundle.Copy(errorContext: elevatedErrorContext); return(Copy(elevatedBundle)); }
public async Task WaitNoMessageAsync(CancellationToken token) { WaitNoMessageEntered.Set(); await BackoffStrategy.WaitNoMessageAsync(token); }
public void Wait(CancellationToken token) { BackoffStrategy.Wait(token); }
public void WaitNoMessage(CancellationToken token) { BackoffStrategy.WaitNoMessage(token); }
public void Reset() { BackoffStrategy.Reset(); }
public Task WaitErrorAsync(CancellationToken token) { return(BackoffStrategy.WaitErrorAsync(token)); }
public IVoidReturnContractContext WithRetryOf(int count, int millisecondsInterval = 0, BackoffStrategy backoff = BackoffStrategy.None) { var elevatedErrorContext = this.bundle.Errors.MarkExceptionHandlerForRetry <TException>(count, millisecondsInterval, backoff); var elevatedBundle = this.bundle.Copy(errorContext: elevatedErrorContext); return(new VoidReturnContractContext(elevatedBundle, this.contractBundle, this.originalContext)); }
public IExceptionHandlerProvider MarkExceptionHandlerForRetry <TException, TResult>(int retryCount, int millisecondsInterval = 0, BackoffStrategy backoff = BackoffStrategy.None) where TException : Exception { var handler = this.handlers[typeof(TException)]; handler.RetryCount = retryCount; handler.RetryIntervalInMilliseconds = millisecondsInterval; handler.Backoff = backoff; return(this); }