mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(sqs): clear SNS FIFO dedup cache on PurgeQueue (#594)
Clear SNS FIFO topic deduplication for topics with SQS subscriptions targeting a purged queue when `clearFifoDeduplicationCacheOnPurge` is enabled.
This commit is contained in:
1 parent
763ea379d7
commit
5ad4c06d74
7 files changed
+120
-11
No files matched your search
+30
@@ -164,4 +164,34 @@ class SnsSqsFanoutFifoDeliveryTest {
|
||||
assertEquals(1, messages.size());
|
||||
assertTrue(messages.get(0).getBody().contains("first"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearFifoDedupForSubscribedQueue_thenRepublishWithSameDedupId_deliversAgain() {
|
||||
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT);
|
||||
SqsService purgeSqsService = SqsServiceFactory.createInMemoryWithFifoDedupPurgeAndSns(
|
||||
BASE_URL, regionResolver, snsService);
|
||||
sqsService.createQueue("manual-sns-dedup-queue.fifo", Map.of("FifoQueue", "true"), REGION);
|
||||
purgeSqsService.createQueue("manual-sns-dedup-queue.fifo", Map.of("FifoQueue", "true"), REGION);
|
||||
String queueArn = "arn:aws:sqs:" + REGION + ":" + ACCOUNT + ":manual-sns-dedup-queue.fifo";
|
||||
|
||||
snsService.createTopic("manual-sns-dedup-topic.fifo", Map.of("FifoTopic", "true"), null, REGION);
|
||||
String topicArn = "arn:aws:sns:" + REGION + ":" + ACCOUNT + ":manual-sns-dedup-topic.fifo";
|
||||
snsService.subscribe(topicArn, "sqs", queueArn, REGION, Map.of());
|
||||
|
||||
String queueUrl = BASE_URL + "/" + ACCOUNT + "/manual-sns-dedup-queue.fifo";
|
||||
|
||||
snsService.publish(topicArn, null, null, "before-clear", null, null, "group-1", "shared-dedup", REGION);
|
||||
List<Message> first = sqsService.receiveMessage(queueUrl, 10, 30, 0, REGION);
|
||||
assertEquals(1, first.size());
|
||||
for (Message m : first) {
|
||||
sqsService.deleteMessage(queueUrl, m.getReceiptHandle(), REGION);
|
||||
}
|
||||
|
||||
purgeSqsService.purgeQueue(queueUrl, REGION);
|
||||
|
||||
snsService.publish(topicArn, null, null, "after-clear", null, null, "group-1", "shared-dedup", REGION);
|
||||
List<Message> after = sqsService.receiveMessage(queueUrl, 10, 30, 0, REGION);
|
||||
assertEquals(1, after.size());
|
||||
assertTrue(after.getFirst().getBody().contains("after-clear"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.sqs;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
|
||||
/**
|
||||
* Test helper to create SqsService instances
|
||||
@@ -12,4 +13,10 @@ public class SqsServiceFactory {
|
||||
return new SqsService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
30, 262144, baseUrl, regionResolver);
|
||||
}
|
||||
|
||||
public static SqsService createInMemoryWithFifoDedupPurgeAndSns(String baseUrl, RegionResolver regionResolver,
|
||||
SnsService snsService) {
|
||||
return new SqsService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
30, 262144, baseUrl, regionResolver, true, snsService);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.sqs;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
import io.github.hectorvent.floci.services.sqs.model.Message;
|
||||
import io.github.hectorvent.floci.services.sqs.model.Queue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -12,6 +13,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
class SqsServiceTest {
|
||||
|
||||
@@ -353,7 +356,7 @@ class SqsServiceTest {
|
||||
void purgeQueueClearsFifoDeduplicationCacheWhenEnabled() {
|
||||
final var service = new SqsService(
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
30, 262144, BASE_URL, new RegionResolver("us-east-1", "000000000000"), true);
|
||||
30, 262144, BASE_URL, new RegionResolver("us-east-1", "000000000000"), true, null);
|
||||
|
||||
final var queue = service.createQueue("dedup-clear.fifo", Map.of("ContentBasedDeduplication", "true"));
|
||||
|
||||
@@ -406,7 +409,7 @@ class SqsServiceTest {
|
||||
final var dedupStore = new InMemoryStorage<String, Map<String, Long>>();
|
||||
final var service = new SqsService(
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), dedupStore,
|
||||
30, 262144, BASE_URL, new RegionResolver("us-east-1", "000000000000"), true);
|
||||
30, 262144, BASE_URL, new RegionResolver("us-east-1", "000000000000"), true, null);
|
||||
|
||||
final var queue = service.createQueue("dedup-store-clear.fifo",
|
||||
Map.of("ContentBasedDeduplication", "true"));
|
||||
@@ -421,4 +424,16 @@ class SqsServiceTest {
|
||||
assertTrue(dedupStore.keys().isEmpty(),
|
||||
"Dedup store must be empty after purge with clearFifoDeduplicationCacheOnPurge=true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void purgeQueueWithClearFifoDelegatesToSnsForFifoDedupOnSubscribedTopics() {
|
||||
final var sns = mock(SnsService.class);
|
||||
final var service = new SqsService(
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
30, 262144, BASE_URL, new RegionResolver("us-east-1", "000000000000"), true, sns);
|
||||
final var queue = service.createQueue("sns-dedup-delegate.fifo", Map.of("FifoQueue", "true"));
|
||||
service.purgeQueue(queue.getQueueUrl());
|
||||
verify(sns).clearFifoDeduplicationCacheForSqsQueueSubscriptions(
|
||||
queue.getQueueUrl(), "us-east-1");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user