-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5c5e03e
commit f3f9586
Showing
9 changed files
with
205 additions
and
94 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
70 changes: 70 additions & 0 deletions
70
src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_configuring_queue_name_prefix.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,70 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
class When_configuring_queue_name_prefix : AwsLambdaSQSEndpointTestBase | ||
{ | ||
public string Prefix { get; } = "test-"; | ||
|
||
public override Task Setup() | ||
{ | ||
QueueNamePrefix = Prefix + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()).ToLowerInvariant(); | ||
return base.Setup(); | ||
} | ||
|
||
[Test] | ||
public async Task The_message_should_be_received_from_prefixed_queue() | ||
{ | ||
// the prefix will be configured using the transport's prefix configuration therefore we remove it for the endpoint name | ||
var endpointName = QueueName.Substring(Prefix.Length); | ||
|
||
var receivedMessages = await GenerateAndReceiveSQSEvent<SentMessage>(); | ||
|
||
var context = new TestContext(); | ||
|
||
var endpoint = new AwsLambdaSQSEndpoint(ctx => | ||
{ | ||
var configuration = new AwsLambdaSQSEndpointConfiguration(endpointName, CreateSQSClient(), CreateSNSClient()); | ||
configuration.Transport.QueueNamePrefix = Prefix; | ||
var advanced = configuration.AdvancedConfiguration; | ||
advanced.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); | ||
// SQS will add the specified queue prefix to the configured error queue | ||
advanced.SendFailedMessagesTo(ErrorQueueName.Substring(Prefix.Length)); | ||
return configuration; | ||
}); | ||
|
||
await endpoint.Process(receivedMessages, null); | ||
|
||
Assert.IsTrue(context.MessageHandled); | ||
} | ||
|
||
public class TestContext | ||
{ | ||
public bool MessageHandled { get; set; } | ||
} | ||
|
||
public class SentMessage : ICommand | ||
{ | ||
} | ||
|
||
public class MessageHandlerThatReceivesSentMessage : IHandleMessages<SentMessage> | ||
{ | ||
public MessageHandlerThatReceivesSentMessage(TestContext context) => testContext = context; | ||
|
||
public Task Handle(SentMessage message, IMessageHandlerContext context) | ||
{ | ||
testContext.MessageHandled = true; | ||
return Task.CompletedTask; | ||
} | ||
|
||
readonly TestContext testContext; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_using_queue_prefix.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,68 @@ | ||
namespace NServiceBus.AcceptanceTests; | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
class When_message_fails_using_queue_prefix : AwsLambdaSQSEndpointTestBase | ||
{ | ||
public string Prefix { get; } = "test-"; | ||
|
||
public override Task Setup() | ||
{ | ||
QueueNamePrefix = Prefix + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()).ToLowerInvariant(); | ||
return base.Setup(); | ||
} | ||
|
||
[Test] | ||
public async Task Should_move_message_to_prefixed_error_queue() | ||
{ | ||
// the prefix will be configured using the transport's prefix configuration therefore we remove it for the endpoint name | ||
var endpointName = QueueName.Substring(Prefix.Length); | ||
|
||
var receivedMessages = await GenerateAndReceiveSQSEvent<TestMessage>(); | ||
|
||
var context = new TestContext(); | ||
|
||
var endpoint = new AwsLambdaSQSEndpoint(ctx => | ||
{ | ||
var configuration = new AwsLambdaSQSEndpointConfiguration(endpointName, CreateSQSClient(), CreateSNSClient()); | ||
configuration.Transport.QueueNamePrefix = Prefix; | ||
var advanced = configuration.AdvancedConfiguration; | ||
advanced.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); | ||
advanced.Recoverability().Immediate(i => i.NumberOfRetries(0)); | ||
advanced.SendFailedMessagesTo(ErrorQueueName.Substring(Prefix.Length)); | ||
return configuration; | ||
}); | ||
|
||
Assert.DoesNotThrowAsync(() => endpoint.Process(receivedMessages, null), "message should be moved to the error queue instead"); | ||
|
||
var errorMessages = await RetrieveMessagesInErrorQueue(); | ||
Assert.AreEqual(1, errorMessages.Records.Count); | ||
JsonDocument errorMessage = JsonSerializer.Deserialize<JsonDocument>(errorMessages.Records.First().Body); | ||
var errorMessageHeader = errorMessage.RootElement.GetProperty("Headers"); | ||
Assert.AreEqual("simulated exception", errorMessageHeader.GetProperty("NServiceBus.ExceptionInfo.Message").GetString()); | ||
Assert.AreEqual(endpointName, errorMessageHeader.GetProperty("NServiceBus.ProcessingEndpoint").GetString()); | ||
StringAssert.EndsWith(QueueName, errorMessageHeader.GetProperty("NServiceBus.FailedQ").GetString()); | ||
} | ||
|
||
public class TestContext | ||
{ | ||
} | ||
|
||
public class TestMessage : ICommand | ||
{ | ||
} | ||
|
||
public class FailingMessageHandler : IHandleMessages<TestMessage> | ||
{ | ||
public Task Handle(TestMessage message, IMessageHandlerContext context) => throw new Exception("simulated exception"); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.