mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(sqs): return MD5 of current request on FIFO dedup replay (#786)
* fix(sqs): return MD5 of current request on FIFO dedup replay On a duplicate SendMessage within the 5-minute FIFO dedup window Floci returned the original message verbatim, including its cached MD5OfMessageBody and MD5OfMessageAttributes. AWS SDK clients validate those MD5s against the body and attributes they sent, so any time the second send differed from the first (or even when the first send had different attribute keys than the second's body alone) the SDK threw "MD5 returned by SQS does not match the calculation on the original request" and never delivered the message. AWS itself returns the original MessageId and SequenceNumber on dedup, but recomputes MD5s from the current request so the validation round-trips. Floci now does the same. A new SDK-driven integration test (sqs Java SDK at test scope) covers the dedup-replay case plus several standard/FIFO/binary/custom-type-name MD5 round-trips. Refs #768. * test(sqs): tighten dedup-replay MD5 test and drop redundant @Inject Address review feedback on #786: - Assert the second SendMessage returns the same MessageId and SequenceNumber as the first, so the test would catch a regression that silently disabled dedup (in which case the MD5 round-trip would also pass for the wrong reason). - Drop the redundant @Inject on the @ConfigProperty-injected field, matching the convention used in other Floci integration tests. * test(sqs): move FIFO MD5 SDK tests to compatibility-tests/sdk-test-java Address maintainer review on #786: - Drop the software.amazon.awssdk:sqs test-scope dependency from the main module's pom.xml. - Move SqsSdkMd5IntegrationTest to the compatibility-tests/sdk-test-java module as SqsMd5Test, where the existing AWS SDK v2 compatibility suite already lives. The test now follows that module's conventions (TestFixtures.sqsClient, AssertJ, lowerCamelCase method names, queue cleanup) and exercises the same scenarios: standard / FIFO / fair MD5 parity, binary and custom-type-name attributes, and the dedup-replay case that asserts the second SendMessage returns the original MessageId and SequenceNumber.
This commit is contained in:
1 parent
6b2c081f0b
commit
734e318278
2 files changed
+210
-2
No files matched your search
@@ -0,0 +1,196 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.sqs.SqsClient;
|
||||
import software.amazon.awssdk.services.sqs.model.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Validates that the AWS SDK Java accepts the MD5OfMessageAttributes Floci
|
||||
* returns for standard, FIFO, and high-throughput FIFO queues. The SDK
|
||||
* validates the MD5 client-side and throws when the response checksum
|
||||
* doesn't match its own canonical recomputation, so a successful
|
||||
* SendMessage is proof of wire-level MD5 parity.
|
||||
*/
|
||||
@DisplayName("SQS MD5OfMessageAttributes wire compatibility")
|
||||
class SqsMd5Test {
|
||||
|
||||
private static SqsClient sqs;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sqs = TestFixtures.sqsClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sqs != null) {
|
||||
sqs.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void standardQueueSendMessageWithAttributesPassesSdkMd5Validation() {
|
||||
String queueName = "md5-std-" + UUID.randomUUID();
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName).build()).queueUrl();
|
||||
|
||||
var attrs = Map.of(
|
||||
"trace-id", MessageAttributeValue.builder()
|
||||
.dataType("String").stringValue("abc-123").build(),
|
||||
"priority", MessageAttributeValue.builder()
|
||||
.dataType("Number").stringValue("42").build());
|
||||
|
||||
var resp = sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl)
|
||||
.messageBody("hello standard")
|
||||
.messageAttributes(attrs)
|
||||
.build());
|
||||
|
||||
assertThat(resp.md5OfMessageAttributes()).isNotNull();
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fifoQueueSendMessageWithAttributesPassesSdkMd5Validation() {
|
||||
String queueName = "md5-fifo-" + UUID.randomUUID() + ".fifo";
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName)
|
||||
.attributes(Map.of(
|
||||
QueueAttributeName.FIFO_QUEUE, "true",
|
||||
QueueAttributeName.CONTENT_BASED_DEDUPLICATION, "true"))
|
||||
.build()).queueUrl();
|
||||
|
||||
var attrs = Map.of(
|
||||
"trace-id", MessageAttributeValue.builder()
|
||||
.dataType("String").stringValue("abc-123").build(),
|
||||
"priority", MessageAttributeValue.builder()
|
||||
.dataType("Number").stringValue("42").build());
|
||||
|
||||
var resp = sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl)
|
||||
.messageBody("hello fifo")
|
||||
.messageGroupId("g1")
|
||||
.messageAttributes(attrs)
|
||||
.build());
|
||||
|
||||
assertThat(resp.md5OfMessageAttributes()).isNotNull();
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fifoDedupReplayReturnsOriginalIdsAndRecomputedMd5() {
|
||||
// Within the 5-minute dedup window, a second SendMessage with the same
|
||||
// MessageDeduplicationId must return MD5s computed from the CURRENT
|
||||
// request body and attributes (not the original message's cached
|
||||
// MD5s), otherwise the SDK throws MD5 mismatch when the two sends
|
||||
// differ at all. The MessageId / SequenceNumber assertions guard
|
||||
// against a regression that silently disabled dedup.
|
||||
String queueName = "md5-dedup-" + UUID.randomUUID() + ".fifo";
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName)
|
||||
.attributes(Map.of(QueueAttributeName.FIFO_QUEUE, "true"))
|
||||
.build()).queueUrl();
|
||||
|
||||
var firstAttrs = Map.of(
|
||||
"k", MessageAttributeValue.builder().dataType("String").stringValue("v1").build());
|
||||
var secondAttrs = Map.of(
|
||||
"k", MessageAttributeValue.builder().dataType("String").stringValue("v2").build());
|
||||
|
||||
var firstResponse = sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl).messageBody("body-1").messageGroupId("g1")
|
||||
.messageDeduplicationId("same-dedup")
|
||||
.messageAttributes(firstAttrs).build());
|
||||
|
||||
var secondResponse = sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl).messageBody("body-2").messageGroupId("g1")
|
||||
.messageDeduplicationId("same-dedup")
|
||||
.messageAttributes(secondAttrs).build());
|
||||
|
||||
assertThat(secondResponse.messageId())
|
||||
.as("FIFO dedup must return the original MessageId")
|
||||
.isEqualTo(firstResponse.messageId());
|
||||
assertThat(secondResponse.sequenceNumber())
|
||||
.as("FIFO dedup must return the original SequenceNumber")
|
||||
.isEqualTo(firstResponse.sequenceNumber());
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fifoQueueBinaryAttributePassesSdkMd5Validation() {
|
||||
String queueName = "md5-fifo-bin-" + UUID.randomUUID() + ".fifo";
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName)
|
||||
.attributes(Map.of(
|
||||
QueueAttributeName.FIFO_QUEUE, "true",
|
||||
QueueAttributeName.CONTENT_BASED_DEDUPLICATION, "true"))
|
||||
.build()).queueUrl();
|
||||
|
||||
var attrs = Map.of(
|
||||
"blob", MessageAttributeValue.builder()
|
||||
.dataType("Binary")
|
||||
.binaryValue(SdkBytes.fromByteArray(new byte[]{1, 2, 3, 4, 5}))
|
||||
.build());
|
||||
|
||||
sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl).messageBody("binary").messageGroupId("g1")
|
||||
.messageAttributes(attrs).build());
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fifoQueueCustomTypeNamePassesSdkMd5Validation() {
|
||||
String queueName = "md5-fifo-custom-" + UUID.randomUUID() + ".fifo";
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName)
|
||||
.attributes(Map.of(
|
||||
QueueAttributeName.FIFO_QUEUE, "true",
|
||||
QueueAttributeName.CONTENT_BASED_DEDUPLICATION, "true"))
|
||||
.build()).queueUrl();
|
||||
|
||||
var attrs = Map.of(
|
||||
"priority", MessageAttributeValue.builder()
|
||||
.dataType("Number.int").stringValue("42").build());
|
||||
|
||||
sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl).messageBody("custom").messageGroupId("g1")
|
||||
.messageAttributes(attrs).build());
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void highThroughputFifoQueueSendMessageWithAttributesPassesSdkMd5Validation() {
|
||||
String queueName = "md5-fair-" + UUID.randomUUID() + ".fifo";
|
||||
String queueUrl = sqs.createQueue(CreateQueueRequest.builder()
|
||||
.queueName(queueName)
|
||||
.attributes(Map.of(
|
||||
QueueAttributeName.FIFO_QUEUE, "true",
|
||||
QueueAttributeName.CONTENT_BASED_DEDUPLICATION, "true",
|
||||
QueueAttributeName.DEDUPLICATION_SCOPE, "messageGroup",
|
||||
QueueAttributeName.FIFO_THROUGHPUT_LIMIT, "perMessageGroupId"))
|
||||
.build()).queueUrl();
|
||||
|
||||
var attrs = Map.of(
|
||||
"key", MessageAttributeValue.builder()
|
||||
.dataType("String").stringValue("value").build());
|
||||
|
||||
sqs.sendMessage(SendMessageRequest.builder()
|
||||
.queueUrl(queueUrl)
|
||||
.messageBody("hello fair")
|
||||
.messageGroupId("g1")
|
||||
.messageAttributes(attrs)
|
||||
.build());
|
||||
|
||||
sqs.deleteQueue(DeleteQueueRequest.builder().queueUrl(queueUrl).build());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user