Ejemplo n.º 1
0
        public void ShouldThrowExhaustedRetriesExceptionWhenRetriesExhausted()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            retryTemplate.RetryPolicy = new NeverRetryPolicy();

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            Assert.Throws <RetryExhaustedException>(() => {
                retryTemplate.DoExecute <string, object>(pendingRetry, (argument) => throw new Exception(), null, CancellationToken.None);
            });
        }
Ejemplo n.º 2
0
        public void ShouldNotListSuccessfullyCompletedRetriesInThePendingRetries()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            retryTemplate.DoExecute(pendingRetry, (argument) => (object)null, null, CancellationToken.None);

            var pendingRetries = retryTemplate.GetPendingRetries <string>(testOperationId);

            Assert.DoesNotContain <PendingRetry <string> >(pendingRetries, (x) =>
                                                           x.OperationId == testOperationId && x.Argument == testArgument);
        }
Ejemplo n.º 3
0
        public void ShouldThrowRetryInterruptedExceptionWhenTheExcutionIsCancelled()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            retryTemplate.RetryPolicy = new NeverRetryPolicy();

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            Assert.Throws <RetryInterruptedException>(() => {
                retryTemplate.DoExecute <string, object>(pendingRetry, (argument) => (object)null,
                                                         null, new CancellationToken(true));
            });
        }
Ejemplo n.º 4
0
        public void ShouldNotListRetriesWithExhaustedRetriesInThePendingRetries()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            retryTemplate.RetryPolicy = new NeverRetryPolicy();

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            try
            {
                retryTemplate.DoExecute <string, object>(pendingRetry, (argument) => throw new Exception(), null, CancellationToken.None);
            }
            catch (RetryExhaustedException) {}

            var pendingRetries = retryTemplate.GetPendingRetries <string>(testOperationId);

            Assert.DoesNotContain <PendingRetry <string> >(pendingRetries, (x) =>
                                                           x.OperationId == testOperationId && x.Argument == testArgument);
        }
Ejemplo n.º 5
0
        public void ShouldListRetriesWithCancelledExcutionInThePendingRetries()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            retryTemplate.RetryPolicy = new NeverRetryPolicy();

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            try
            {
                retryTemplate.DoExecute <string, object>(pendingRetry, (argument) => (object)null,
                                                         null, new CancellationToken(true));
            }
            catch (RetryInterruptedException) {}

            var pendingRetries = retryTemplate.GetPendingRetries <string>(testOperationId);

            Assert.Contains <PendingRetry <string> >(pendingRetries, (x) =>
                                                     x.OperationId == testOperationId && x.Argument == testArgument);
        }
Ejemplo n.º 6
0
        public void ShouldRetryOnExceptionsWhileTheRetryPolicySaysSoAndFinishWithARetryExhaustedException()
        {
            RetryTemplate retryTemplate = new RetryTemplate(new LiteDatabase(Path.GetTempFileName()));

            retryTemplate.RetryPolicy = new SimpleRetryPolicy(3);

            string testOperationId = "test.operation";
            string testArgument    = "test argument";
            var    pendingRetry    = retryTemplate.SaveForRetry <string>(testOperationId, testArgument);

            int executionCounter = 0;

            try
            {
                retryTemplate.DoExecute <string, object>(pendingRetry, (argument) =>
                {
                    executionCounter++;
                    throw new Exception();
                }, null, CancellationToken.None);
            }
            catch (RetryExhaustedException) {}
            Assert.Equal(3, executionCounter);
        }