public async Task Update_RetryReliability_To_Pending_When_Receiver_Is_Offline() { // Arrange string ebmsMessageId = $"user-{Guid.NewGuid()}"; AS4Message tobeSendMessage = AS4Message.Create(new UserMessage(ebmsMessageId)); var outMessage = new OutMessage(ebmsMessageId); GetDataStoreContext.InsertOutMessage(outMessage); GetDataStoreContext.InsertRetryReliability( RetryReliability.CreateForOutMessage( refToOutMessageId: outMessage.Id, maxRetryCount: 2, retryInterval: TimeSpan.FromSeconds(1), type: RetryType.Send)); var ctx = new MessagingContext( tobeSendMessage, new ReceivedEntityMessage( outMessage, tobeSendMessage.ToStream(), tobeSendMessage.ContentType), MessagingContextMode.Send) { SendingPMode = CreateSendPModeWithPushUrl() }; var sabotageException = new WebException("Remote host not available"); IStep sut = CreateSendStepWithResponse( StubHttpClient.ThatThrows(sabotageException)); // Act StepResult result = await sut.ExecuteAsync(ctx); // Assert Assert.False(result.Succeeded); GetDataStoreContext.AssertRetryRelatedOutMessage( outMessage.Id, r => { Assert.NotNull(r); Assert.Equal(RetryStatus.Pending, r.Status); }); }
public async Task Reset_InMessage_Operation_ToBeDelivered_When_CurrentRetry_LessThen_MaxRetry(DeliverRetry input) { // Arrange string id = Guid.NewGuid().ToString(); InMessage im = CreateInMessage(id, InStatus.Received, Operation.Delivering); GetDataStoreContext.InsertInMessage(im); var r = RetryReliability.CreateForInMessage( refToInMessageId: im.Id, maxRetryCount: input.MaxRetryCount, retryInterval: default(TimeSpan), type: RetryType.Notification); r.CurrentRetryCount = input.CurrentRetryCount; GetDataStoreContext.InsertRetryReliability(r); DeliverMessageEnvelope envelope = AnonymousDeliverEnvelope(id); var stub = new Mock <IDeliverSender>(); stub.Setup(s => s.SendAsync(envelope)) .ReturnsAsync(input.SendResult); IStep sut = CreateSendDeliverStepWithSender(stub.Object); // Act await sut.ExecuteAsync(new MessagingContext(envelope) { ReceivingPMode = CreateDefaultReceivingPMode() }); // Assert GetDataStoreContext.AssertInMessage(id, inMessage => { Assert.NotNull(inMessage); Assert.Equal(input.ExpectedStatus, inMessage.Status.ToEnum <InStatus>()); Assert.Equal(input.ExpectedOperation, inMessage.Operation); }); }
public async Task Retries_Uploading_When_Uploader_Returns_RetryableFail_Result(UploadRetry input) { // Arrange string id = "deliver-" + Guid.NewGuid(); InMessage im = InsertInMessage(id); var r = RetryReliability.CreateForInMessage( refToInMessageId: im.Id, maxRetryCount: input.MaxRetryCount, retryInterval: default(TimeSpan), type: RetryType.Delivery); r.CurrentRetryCount = input.CurrentRetryCount; GetDataStoreContext.InsertRetryReliability(r); var a = new FilledAttachment(); var userMessage = new FilledUserMessage(id, a.Id); AS4Message as4Msg = AS4Message.Create(userMessage); as4Msg.AddAttachment(a); MessagingContext fixture = await PrepareAS4MessageForDeliveryAsync(as4Msg, CreateReceivingPModeWithPayloadMethod()); IAttachmentUploader stub = CreateStubAttachmentUploader(fixture.DeliverMessage.Message.MessageInfo, input.UploadResult); // Act await CreateUploadStep(stub).ExecuteAsync(fixture); // Assert GetDataStoreContext.AssertInMessage(id, actual => { Assert.NotNull(actual); Assert.Equal(input.ExpectedStatus, actual.Status.ToEnum <InStatus>()); Assert.Equal(input.ExpectedOperation, actual.Operation); }); }
public async Task All_Attachments_Should_Succeed_Or_Fail(UploadRetry input) { // Arrange string id = "deliver-" + Guid.NewGuid(); InMessage im = InsertInMessage(id); var r = RetryReliability.CreateForInMessage( refToInMessageId: im.Id, maxRetryCount: input.MaxRetryCount, retryInterval: default(TimeSpan), type: RetryType.Delivery); r.CurrentRetryCount = input.CurrentRetryCount; GetDataStoreContext.InsertRetryReliability(r); var a1 = new FilledAttachment("attachment-1"); var a2 = new FilledAttachment("attachment-2"); var userMessage = new FilledUserMessage(id, a1.Id, a2.Id); var as4Msg = AS4Message.Create(userMessage); as4Msg.AddAttachment(a1); as4Msg.AddAttachment(a2); MessagingContext fixture = await PrepareAS4MessageForDeliveryAsync(as4Msg, CreateReceivingPModeWithPayloadMethod()); var stub = new Mock <IAttachmentUploader>(); stub.Setup(s => s.UploadAsync(a1, fixture.DeliverMessage.Message.MessageInfo)) .ReturnsAsync(input.UploadResult); stub.Setup(s => s.UploadAsync(a2, fixture.DeliverMessage.Message.MessageInfo)) .ReturnsAsync( input.UploadResult.Status == SendResult.Success ? UploadResult.FatalFail : UploadResult.RetryableFail); // Act await CreateUploadStep(stub.Object).ExecuteAsync(fixture); // Assert GetDataStoreContext.AssertInMessage(id, actual => { Assert.NotNull(actual); Operation op = actual.Operation; Assert.NotEqual(Operation.Delivered, op); InStatus st = actual.Status.ToEnum <InStatus>(); Assert.NotEqual(InStatus.Delivered, st); bool operationToBeRetried = Operation.ToBeRetried == op; bool uploadResultCanBeRetried = input.UploadResult.Status == SendResult.RetryableFail && input.CurrentRetryCount < input.MaxRetryCount; Assert.True( operationToBeRetried == uploadResultCanBeRetried, "InMessage should update Operation=ToBeDelivered"); bool messageSetToException = Operation.DeadLettered == op && InStatus.Exception == st; bool exhaustRetries = input.CurrentRetryCount == input.MaxRetryCount || input.UploadResult.Status != SendResult.RetryableFail; Assert.True( messageSetToException == exhaustRetries, $"{messageSetToException} != {exhaustRetries} InMessage should update Operation=DeadLettered, Status=Exception"); }); }