Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty Attributes for SQS GetQueueMessages #115

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/SnD.Sdk/Storage/Amazon/AmazonSqsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public Source<QueueElement, NotUsed> GetQueueMessages(string queueName, TimeSpan
Content = BinaryData.FromString(msg.Body),
ElementId = msg.MessageId,
DeleteHandle = msg.ReceiptHandle,
DequeueCount = long.TryParse(msg.Attributes["ApproximateReceiveCount"], out var count) ? (long?)count : null
DequeueCount = msg.Attributes.ContainsKey("ApproximateReceiveCount") && long.TryParse(msg.Attributes["ApproximateReceiveCount"], out var count)
? (long?)count
: null
});
}

Expand Down
10 changes: 5 additions & 5 deletions test/Storage/AmazonSqsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public AmazonSqsServiceTests(AkkaFixture akkaFixture, LoggerFixture loggerFixtur
}

[Theory]
[InlineData(10, 60, 10)]
[InlineData(10, 60, 1)]
[InlineData(10, 10, 1)]
public async Task GetQueueMessages1(int messagesPerCall, int visibilityTimeoutSeconds, int numCalls)
[InlineData(10, 60, 10, false)]
[InlineData(10, 60, 1, false)]
[InlineData(10, 10, 1, true)]
public async Task GetQueueMessages(int messagesPerCall, int visibilityTimeoutSeconds, int numCalls, bool emptyMessageAttributes)
{
var queueUrl = "test-queue-url";
var mockMessages = new List<Message>();
Expand All @@ -44,7 +44,7 @@ public async Task GetQueueMessages1(int messagesPerCall, int visibilityTimeoutSe
MessageId = Guid.NewGuid().ToString(),
ReceiptHandle = Guid.NewGuid().ToString(),
Body = i.ToString(),
Attributes = new Dictionary<string, string>
Attributes = emptyMessageAttributes ? new Dictionary<string, string>() : new Dictionary<string, string>
{
{ "ApproximateReceiveCount", "3" }
}
Expand Down
Loading