public async Task HandleError_forwards_to_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext <FirstTestEvent> context, EventErrorDelegate <FirstTestEvent> next) { context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy(); await sut.HandleErrorAsync(context, error, next); Mock.Get(engine).VerifyNoOtherCalls(); Mock.Get(next).Verify(p => p(context, error)); }
public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext <FirstTestEvent> context, EventErrorDelegate <FirstTestEvent> next) { await sut.HandleErrorAsync(context, error, next); Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage)); }
public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext <FirstTestEvent> context, EventErrorDelegate <FirstTestEvent> next) { await sut.HandleErrorAsync(context, error, next); Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount)); }
public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext <FirstTestEvent> context, EventErrorDelegate <FirstTestEvent> next) { context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy(); await sut.HandleErrorAsync(context, error, next); Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage)); }
public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext <FirstTestEvent> context, EventErrorDelegate <FirstTestEvent> 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())); }
public async Task HandleErrorAsync_forwards_to_next_if_error_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext <FirstTestEvent> context, Exception exception, Exception discardException, EventErrorDelegate <FirstTestEvent> 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)); }
public async Task HandleErrorAsync_notifies_engine_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext <FirstTestEvent> context, Exception exception, EventErrorDelegate <FirstTestEvent> next) { await sut.HandleErrorAsync(context, exception, next); Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message)); }
public async Task HandleErrorAsync <TEvent>(IEventContext <TEvent> context, Exception exception, EventErrorDelegate <TEvent> next) where TEvent : class, IEvent { 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); } }
public Task HandleErrorAsync <TEvent>(IEventContext <TEvent> context, Exception exception, EventErrorDelegate <TEvent> next) where TEvent : class, IEvent { return(_engine.NotifyFailAsync(context.Message)); }
public async Task HandleErrorAsync <TEvent>(IEventContext <TEvent> context, Exception exception, EventErrorDelegate <TEvent> next) where TEvent : class, IEvent { if (context.Message is EventMessage <TEvent> 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); } } }