Example #1
0
        public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext <FirstTestCommand> context, CommandErrorDelegate <FirstTestCommand> next)
        {
            await sut.HandleErrorAsync(context, error, next);

            Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
        }
Example #2
0
        public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext <FirstTestCommand> context, CommandErrorDelegate <FirstTestCommand> next)
        {
            context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();

            await sut.HandleErrorAsync(context, error, next);

            Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
            Assert.That(context.Message.Headers[Headers.RetryCount], Is.EqualTo((options.MaxRetries - 1).Stringfy()));
        }
Example #3
0
        public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext <FirstTestCommand> context, CommandErrorDelegate <FirstTestCommand> next)
        {
            await sut.HandleErrorAsync(context, error, next);

            Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
        }
Example #4
0
        public async Task HandleError_invokes_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext <FirstTestCommand> context, CommandErrorDelegate <FirstTestCommand> next)
        {
            context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();

            await sut.HandleErrorAsync(context, error, next);

            Mock.Get(next).Verify(p => p(context, error));
        }
Example #5
0
        public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext <FirstTestCommand> context, CommandErrorDelegate <FirstTestCommand> next)
        {
            context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();

            await sut.HandleErrorAsync(context, error, next);

            Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
        }
Example #6
0
        public async Task HandleErrorAsync_forwards_to_next_if_error_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext <FirstTestCommand> context, Exception exception, Exception discardException, CommandErrorDelegate <FirstTestCommand> next)
        {
            Mock.Get(engine).Setup(p => p.NotifyFailAsync(It.IsAny <Message>())).ThrowsAsync(discardException);

            await sut.HandleErrorAsync(context, exception, next);

            Mock.Get(next).Verify(p => p(context, exception));
        }
Example #7
0
        public async Task HandleErrorAsync_notifies_engine_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext <FirstTestCommand> context, Exception exception, CommandErrorDelegate <FirstTestCommand> next)
        {
            await sut.HandleErrorAsync(context, exception, next);

            Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
        }
Example #8
0
 public async Task HandleErrorAsync <TCommand>(ICommandContext <TCommand> context, Exception exception, CommandErrorDelegate <TCommand> next)
     where TCommand : class, ICommand
 {
     try
     {
         await _engine.NotifyFailAsync(context.Message).ConfigureAwait(false);
     }
     catch (Exception discardException)
     {
         _logger.LogError(discardException, ex => $"Unable to discard message: {ex.Message}");
         await next(context, exception).ConfigureAwait(false);
     }
 }
Example #9
0
 public Task HandleErrorAsync <TCommand>(ICommandContext <TCommand> context, Exception exception, CommandErrorDelegate <TCommand> next)
     where TCommand : class, ICommand
 {
     return(_engine.NotifyFailAsync(context.Message));
 }
Example #10
0
        public async Task HandleErrorAsync <TCommand>(ICommandContext <TCommand> context, Exception exception, CommandErrorDelegate <TCommand> next)
            where TCommand : class, ICommand
        {
            if (context.Message is CommandMessage <TCommand> message)
            {
                var retryCount = RetryCount(message) + 1;

                if (retryCount < _options.MaxRetries)
                {
                    _logger.LogTrace($"Error {retryCount}/{_options.MaxRetries}: will retry");

                    message.Headers[Headers.RetryCount] = retryCount.Stringfy();

                    await _engine.NotifySuccessAsync(message).ConfigureAwait(false);

                    await _engine.SendMessageAsync(message).ConfigureAwait(false);
                }
                else
                {
                    _logger.LogTrace($"Error {retryCount}/{_options.MaxRetries}: will not retry");

                    //await _engine.NotifyFailAsync(message).ConfigureAwait(false);

                    await next(context, exception).ConfigureAwait(false);
                }
            }
        }