-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide ability to return messages forwarded to Bridge error queue ba…
…ck to originating Bridge queue - 2.0 branch (#275) Co-authored-by: Ramon Smits <ramon.smits@gmail.com>
- Loading branch information
1 parent
843308a
commit a57b5f2
Showing
12 changed files
with
156 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace AcceptanceTesting | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public class FakeShovelHeader | ||
{ | ||
public const string FailureHeader = "FakeShovelFailure"; | ||
} | ||
|
||
class FakeShovel : IMessageShovel | ||
{ | ||
|
||
readonly IMessageShovel messageShovel; | ||
|
||
public FakeShovel(MessageShovel shovel) | ||
{ | ||
messageShovel = shovel; | ||
} | ||
|
||
public Task TransferMessage(TransferContext transferContext, CancellationToken cancellationToken = default) | ||
{ | ||
var messageContext = transferContext.MessageToTransfer; | ||
if (messageContext.Headers.ContainsKey(FakeShovelHeader.FailureHeader)) | ||
{ | ||
throw new Exception("Incoming message has `FakeShovelFailure` header to test infrastructure failures"); | ||
} | ||
|
||
return messageShovel.TransferMessage(transferContext, cancellationToken); | ||
} | ||
} | ||
} |
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,89 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
public class TransferFailureTests : BridgeAcceptanceTest | ||
{ | ||
const string ReceiveDummyQueue = "TransferFailureTests_DummyQueue"; // Required because Bridge needs endpoints on both sides. | ||
const string ErrorQueue = "TransferFailureTests_BridgeErrorQueue"; | ||
const string FailedQHeader = "NServiceBus.MessagingBridge.FailedQ"; | ||
|
||
[Test] | ||
public async Task Should_add_failedq_header_when_transfer_fails() | ||
{ | ||
var ctx = await Scenario.Define<Context>() | ||
.WithEndpoint<ErrorSpy>() | ||
.WithEndpoint<Sender>(b => b | ||
.When(c => c.EndpointsStarted, async (session, c) => | ||
{ | ||
var opts = new SendOptions(); | ||
opts.SetHeader(FakeShovelHeader.FailureHeader, string.Empty); | ||
await session.Send(new FaultyMessage(), opts); | ||
})) | ||
.WithBridge(bridgeConfiguration => | ||
{ | ||
var bridgeTransport = new TestableBridgeTransport(TransportBeingTested); | ||
bridgeTransport.AddTestEndpoint<Sender>(); | ||
bridgeConfiguration.AddTransport(bridgeTransport); | ||
bridgeTransport.ErrorQueue = ErrorQueue; | ||
|
||
var subscriberEndpoint = new BridgeEndpoint(ReceiveDummyQueue); | ||
bridgeConfiguration.AddTestTransportEndpoint(subscriberEndpoint); | ||
}) | ||
.Done(c => c.MessageFailed) | ||
.Run(); | ||
|
||
Assert.IsTrue(ctx.MessageFailed, "Message did not fail"); | ||
Assert.IsTrue(ctx.FailedMessageHeaders.ContainsKey(FailedQHeader), | ||
$"Failed message headers does not contain {FailedQHeader}"); | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() => | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.ConfigureRouting().RouteToEndpoint(typeof(FaultyMessage), ReceiveDummyQueue); | ||
}); | ||
} | ||
|
||
public class ErrorSpy : EndpointConfigurationBuilder | ||
{ | ||
public ErrorSpy() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.OverrideLocalAddress(ErrorQueue); | ||
}); | ||
} | ||
|
||
class FailedMessageHander : IHandleMessages<FaultyMessage> | ||
{ | ||
public FailedMessageHander(Context context) => testContext = context; | ||
|
||
public Task Handle(FaultyMessage message, IMessageHandlerContext context) | ||
{ | ||
testContext.FailedMessageHeaders = | ||
new ReadOnlyDictionary<string, string>((IDictionary<string, string>)context.MessageHeaders); | ||
testContext.MessageFailed = true; | ||
return Task.CompletedTask; | ||
} | ||
|
||
readonly Context testContext; | ||
} | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool MessageFailed { get; set; } | ||
public IReadOnlyDictionary<string, string> FailedMessageHeaders { get; set; } | ||
} | ||
|
||
public class FaultyMessage : 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class BridgeHeaders | ||
{ | ||
public static string Transfer = "NServiceBus.Bridge.Transfer"; | ||
} | ||
public const string Transfer = "NServiceBus.Bridge.Transfer"; | ||
public const string FailedQ = "NServiceBus.MessagingBridge.FailedQ"; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
interface IMessageShovel | ||
{ | ||
Task TransferMessage(TransferContext transferContext, CancellationToken cancellationToken = default); | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/UnitTests/ApprovalFiles/APIApprovals.PublicApi.approved.txt
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