-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2589 from Particular/handle-retry-succeeded-notif…
…ications Handle retry succeeded notifications
- Loading branch information
Showing
59 changed files
with
1,209 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/ServiceControl.AcceptanceTests/Recoverability/When_retry_is_confirmed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
namespace ServiceControl.AcceptanceTests.Recoverability | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NUnit.Framework; | ||
using ServiceControl.MessageFailures; | ||
using ServiceControl.MessageFailures.Api; | ||
using TestSupport.EndpointTemplates; | ||
|
||
[RunOnAllTransports] | ||
class When_retry_is_confirmed : AcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_mark_message_as_successfully_resolved() | ||
{ | ||
var context = await Define<Context>() | ||
.WithEndpoint<RetryingEndpoint>(b => b | ||
.DoNotFailOnErrorMessages() | ||
.When(s => s.SendLocal(new RetryMessage()))) | ||
.Do("Wait for failed message", async c => | ||
{ | ||
// wait till the failed message has been ingested | ||
var tryGetMany = await this.TryGetMany<FailedMessageView>("/api/errors"); | ||
return tryGetMany; | ||
}) | ||
.Do("Retry message", async c => | ||
{ | ||
//trigger retry | ||
await this.Post<object>("/api/errors/retry/all"); | ||
}) | ||
.Do("Wait for retry confirmation", async c => | ||
{ | ||
if (!c.ReceivedRetry) | ||
{ | ||
// wait till endpoint processed the retried message | ||
return false; | ||
} | ||
|
||
var failedMessages = await this.TryGetMany<FailedMessageView>("/api/errors"); | ||
if (failedMessages.Items.Any(i => i.Status == FailedMessageStatus.Resolved)) | ||
{ | ||
c.MessagesView = failedMessages.Items; | ||
return true; | ||
} | ||
|
||
return false; | ||
}) | ||
.Done(c => true) | ||
.Run(); | ||
|
||
Assert.AreEqual(1, context.MessagesView.Count); | ||
var failedMessage = context.MessagesView.Single(); | ||
Assert.AreEqual(FailedMessageStatus.Resolved, failedMessage.Status); | ||
Assert.AreEqual(1, failedMessage.NumberOfProcessingAttempts); | ||
} | ||
|
||
class Context : ScenarioContext, ISequenceContext | ||
{ | ||
public bool ThrowOnHandler { get; set; } = true; | ||
public bool ReceivedRetry { get; set; } | ||
public int Step { get; set; } | ||
public List<FailedMessageView> MessagesView { get; set; } | ||
} | ||
|
||
class RetryingEndpoint : EndpointConfigurationBuilder | ||
{ | ||
public RetryingEndpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(c => c.NoRetries()); | ||
} | ||
|
||
class RetryMessageHandler : IHandleMessages<RetryMessage> | ||
{ | ||
Context testContext; | ||
|
||
public RetryMessageHandler(Context testContext) | ||
{ | ||
this.testContext = testContext; | ||
} | ||
|
||
public Task Handle(RetryMessage message, IMessageHandlerContext context) | ||
{ | ||
if (testContext.ThrowOnHandler) | ||
{ | ||
testContext.ThrowOnHandler = false; | ||
throw new Exception("boom"); | ||
} | ||
|
||
testContext.ReceivedRetry = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class RetryMessage : IMessage | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...dit.AcceptanceTests/Recoverability/When_a_successful_retry_at_old_endpoint_is_detected.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
namespace ServiceControl.Audit.AcceptanceTests.Recoverability | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.Features; | ||
using NServiceBus.Pipeline; | ||
using NUnit.Framework; | ||
using TestSupport.EndpointTemplates; | ||
using Conventions = NServiceBus.AcceptanceTesting.Customization.Conventions; | ||
|
||
[RunOnAllTransports] | ||
class When_a_successful_retry_at_old_endpoint_is_detected : AcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_send_acknowledgement() | ||
{ | ||
var failedMessageId = Guid.NewGuid().ToString(); | ||
var context = await Define<Context>() | ||
.WithEndpoint<AcknowledgementSpy>() | ||
.WithEndpoint<Receiver>(b => b.When(s => | ||
{ | ||
var options = new SendOptions(); | ||
|
||
options.SetHeader("ServiceControl.Retry.UniqueMessageId", failedMessageId); | ||
options.SetHeader("ServiceControl.Retry.AcknowledgementQueue", Conventions.EndpointNamingConvention(typeof(AcknowledgementSpy))); | ||
options.RouteToThisEndpoint(); | ||
return s.Send(new MyMessage(), options); | ||
})) | ||
.Done(c => c.AcknowledgementSent) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.AcknowledgementSent); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool AcknowledgementSent { get; set; } | ||
} | ||
|
||
public class AcknowledgementSpy : EndpointConfigurationBuilder | ||
{ | ||
public AcknowledgementSpy() | ||
{ | ||
EndpointSetup<DefaultServerWithoutAudit>(cfg => | ||
{ | ||
cfg.Pipeline.Register(b => new SpyBehavior(b.Build<Context>()), "Spy behavior"); | ||
cfg.Pipeline.Remove("DiscardMessagesBehavior"); //Otherwise the confirmation generated by the audit instance will be discarded | ||
}); | ||
} | ||
|
||
public class SpyBehavior : Behavior<ITransportReceiveContext> | ||
{ | ||
Context scenarioContext; | ||
|
||
public SpyBehavior(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public override Task Invoke(ITransportReceiveContext context, Func<Task> next) | ||
{ | ||
if (context.Message.Headers.ContainsKey("ServiceControl.Retry.Successful")) | ||
{ | ||
scenarioContext.AcknowledgementSent = true; | ||
} | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
EndpointSetup<DefaultServerWithAudit>(cfg => | ||
{ | ||
// disable retry notifications feature to emulate an NServiceBus endpoint older than version 7.5 | ||
cfg.DisableFeature<PlatformRetryNotifications>(); | ||
}); | ||
} | ||
|
||
public class MyMessageHandler : IHandleMessages<MyMessage> | ||
{ | ||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
|
||
public class MyMessage : ICommand | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.