public async Task PiggyBack_PullRequest_With_Receipt_Operation_Becomes_DeadLettered_When_Retries_Are_Exhausted() { // Arrange string pullSendUrl = RetrievePullingUrlFromConfig(); var user = new UserMessage($"user-{Guid.NewGuid()}", PullRequestMpc); var receipt = new Receipt($"receipt-{Guid.NewGuid()}", user.MessageId); InsertUserMessage(user); long id = InsertReceipt(receipt, pullSendUrl, Operation.ToBePiggyBacked); // Act InsertRetryReliability(id, maxRetryCount: 1); // Assert await PollUntilPresent( () => _databaseSpy.GetOutMessageFor( m => m.EbmsMessageId == receipt.MessageId && m.Operation == Operation.DeadLettered), timeout : TimeSpan.FromSeconds(40)); RetryReliability reliability = await PollUntilPresent( () => _databaseSpy.GetRetryReliabilityFor( r => r.RefToOutMessageId == id && r.Status == RetryStatus.Completed), timeout : TimeSpan.FromSeconds(5)); Assert.True( reliability.CurrentRetryCount > 0, "RetryReliability.CurrentRetryCount should be greater then zero"); }
public void MessageOlderThanRetentionDateWillBeDeleted(string specificSettings) { // Arrange: Insert a "retired" OutMessage with a referenced Reception Awareness. OverrideWithSpecificSettings(specificSettings); IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); string outReferenceId = GenId(), outStandaloneId = GenId(), inMessageId = GenId(), outExceptionId = GenId(), inExceptionId = GenId(); var spy = new DatabaseSpy(config); OutMessage om = CreateOutMessage(outReferenceId, insertionTime: DayBeforeYesterday, type: MessageType.Error); spy.InsertOutMessage(om); spy.InsertRetryReliability(RetryReliability.CreateForOutMessage(om.Id, maxRetryCount: 0, retryInterval: default(TimeSpan), type: RetryType.Send)); spy.InsertOutMessage(CreateOutMessage(outStandaloneId, insertionTime: DayBeforeYesterday, type: MessageType.Receipt)); spy.InsertInMessage(CreateInMessage(inMessageId, DayBeforeYesterday)); spy.InsertOutException(CreateOutException(outExceptionId, DayBeforeYesterday)); spy.InsertInException(CreateInException(inExceptionId, DayBeforeYesterday)); // Act: AS4.NET Component will start the Clean Up Agent. ExerciseStartCleaning(); // Assert: No OutMessage or Reception Awareness entries must be found for a given EbmsMessageId. Assert.Empty(spy.GetOutMessages(outReferenceId, outStandaloneId)); Assert.Null(spy.GetRetryReliabilityFor(r => r.RefToOutMessageId == om.Id)); Assert.Empty(spy.GetInMessages(inMessageId)); Assert.Empty(spy.GetOutExceptions(outExceptionId)); Assert.Empty(spy.GetInExceptions(inExceptionId)); }
public async Task OutMessage_Is_To_Notified_When_Retry_Happen_Withing_Allowed_MaxRetry( HttpStatusCode secondAttemptStatusCode, Operation expected) { await TestComponentWithSettings( "outmessage_notify_reliability_settings.xml", async (settings, as4Msh) => { // Arrange const string url = "http://localhost:7071/business/outmessage/"; string ebmsMessageId = $"error-{Guid.NewGuid()}"; var store = new AS4MessageBodyFileStore(); var om = new OutMessage(ebmsMessageId) { ContentType = Constants.ContentTypes.Soap, MessageLocation = store.SaveAS4Message( as4Msh.GetConfiguration().InMessageStoreLocation, AS4Message.Create( Error.FromErrorResult( ebmsMessageId, refToMessageId: $"user-{Guid.NewGuid()}", result: new ErrorResult( "Invalid header example description failure", ErrorAlias.InvalidHeader)))) }; SendingProcessingMode pmode = NotifySendingPMode(url); Entities.RetryReliability CreateRetry(long id) => Entities.RetryReliability.CreateForOutMessage( refToOutMessageId: id, maxRetryCount: pmode.ErrorHandling.Reliability.RetryCount, retryInterval: pmode.ErrorHandling.Reliability.RetryInterval.AsTimeSpan(), type: RetryType.Notification); // Act InsertMessageEntityWithRetry(om, as4Msh.GetConfiguration(), pmode, CreateRetry); // Assert SimulateNotifyFailureOnFirstAttempt(url, secondAttemptStatusCode); var spy = new DatabaseSpy(as4Msh.GetConfiguration()); OutMessage notified = await PollUntilPresent( () => spy.GetOutMessageFor( m => m.Operation == expected), timeout: TimeSpan.FromSeconds(10)); Assert.Equal(ebmsMessageId, notified.EbmsMessageId); Entities.RetryReliability referenced = await PollUntilPresent( () => spy.GetRetryReliabilityFor(r => r.RefToOutMessageId == notified.Id), timeout: TimeSpan.FromSeconds(5)); Assert.Equal(RetryStatus.Completed, referenced.Status); }); }
public async Task Message_Is_Set_To_Delivered_After_Its_Being_Retried() { // Arrang AS4Message as4Message = CreateAS4Message(); // Act await TestDeliverRetryByBlockingDeliveryLocationFor(as4Message, TimeSpan.FromSeconds(1)); // Assert InMessage actual = await PollUntilPresent( () => _databaseSpy.GetInMessageFor(m => m.Operation == Operation.Delivered), timeout : TimeSpan.FromSeconds(10)); // Assert Assert.Equal(InStatus.Delivered, actual.Status.ToEnum <InStatus>()); Assert.Equal(Operation.Delivered, actual.Operation); RetryReliability rr = _databaseSpy.GetRetryReliabilityFor(r => r.RefToInMessageId == actual.Id); Assert.True(0 < rr.CurrentRetryCount, "0 < actualMessage.CurrentRetryCount"); Assert.Equal(RetryStatus.Completed, rr.Status); }
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); }); }