public void Set_Retry_Info_When_SendingPMode_Is_Configured_For_Retry( bool enabled, PositiveInt count, TimeSpan interval) { // Arrange ClearOutExceptions(); var sut = new OutboundExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore()); var pmode = new SendingProcessingMode(); pmode.ExceptionHandling.Reliability = new RetryReliability { IsEnabled = enabled, RetryCount = count.Get, RetryInterval = interval.ToString("G") }; var entity = new OutMessage($"entity-{Guid.NewGuid()}"); GetDataStoreContext.InsertOutMessage(entity); // Act sut.HandleExecutionException( new Exception(), new MessagingContext( new ReceivedEntityMessage(entity), MessagingContextMode.Notify) { SendingPMode = pmode }) .GetAwaiter() .GetResult(); // Assert GetDataStoreContext.AssertOutException(ex => { Assert.Null(ex.MessageLocation); GetDataStoreContext.AssertRetryRelatedOutException( ex.Id, rr => { Assert.True( enabled == (0 == rr?.CurrentRetryCount), "CurrentRetryCount != 0 when RetryReliability is enabled"); Assert.True( enabled == (count.Get == rr?.MaxRetryCount), enabled ? $"Max retry count failed on enabled: {count.Get} != {rr?.MaxRetryCount}" : $"Max retry count should be 0 on disabled but is {rr?.MaxRetryCount}"); Assert.True( enabled == (interval == rr?.RetryInterval), enabled ? $"Retry interval failed on enabled: {interval:G} != {rr?.RetryInterval}" : $"Retry interval should be 0:00:00 on disabled but is {rr?.RetryInterval}"); }); }); }
public async Task OutException_Is_Set_To_Notified_When_Retry_Happen_Within_Allowed_MaxRetry( HttpStatusCode secondAttempt, Operation expected) { await TestComponentWithSettings( "outexception_notify_reliability_settings.xml", async (settings, as4Msh) => { // Arrange var handler = new OutboundExceptionHandler( () => new DatastoreContext(as4Msh.GetConfiguration()), as4Msh.GetConfiguration(), Registry.Instance.MessageBodyStore); const string url = "http://localhost:7070/business/outexception/"; string ebmsMessageId = $"entity-{Guid.NewGuid()}"; var spy = new DatabaseSpy(as4Msh.GetConfiguration()); //var entity = new OutMessage(ebmsMessageId); //spy.InsertOutMessage(entity); // Act await handler.HandleExecutionException( new Exception("This is an test exception"), new MessagingContext(new SubmitMessage()) { SendingPMode = NotifySendingPMode(url) }); // Arrange SimulateNotifyFailureOnFirstAttempt(url, secondAttempt); OutException notified = await PollUntilPresent( () => spy.GetOutExceptions( ex => ex.Operation == expected).FirstOrDefault(), timeout: TimeSpan.FromSeconds(10)); Entities.RetryReliability referenced = await PollUntilPresent( () => spy.GetRetryReliabilityFor(r => r.RefToOutExceptionId == notified.Id), timeout: TimeSpan.FromSeconds(5)); Assert.Equal(RetryStatus.Completed, referenced.Status); }); }