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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 public async Task WaitNoMessageAsync(CancellationToken token)
 {
     WaitNoMessageEntered.Set();
     await BackoffStrategy.WaitNoMessageAsync(token);
 }
Beispiel #6
0
 public void Wait(CancellationToken token)
 {
     BackoffStrategy.Wait(token);
 }
Beispiel #7
0
 public void WaitNoMessage(CancellationToken token)
 {
     BackoffStrategy.WaitNoMessage(token);
 }
Beispiel #8
0
 public void Reset()
 {
     BackoffStrategy.Reset();
 }
Beispiel #9
0
 public Task WaitErrorAsync(CancellationToken token)
 {
     return(BackoffStrategy.WaitErrorAsync(token));
 }
Beispiel #10
0
        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);
        }