Skip to content

Commit e8f0faa

Browse files
authored
add test to avoid duplicate keys (RedrivePolicy) when retrieving SQS attributes (#8)
1 parent 61d312d commit e8f0faa

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/test/java/cloud/localstack/SQSMessagingTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,40 @@ public void testSendMultiByteCharactersMessage() throws JMSException {
174174
final ReceiveMessageResult messageResult = clientSQS.receiveMessage(queueUrl);
175175
Assert.assertNotNull(messageResult);
176176
}
177+
178+
/**
179+
* java.lang.IllegalArgumentException: Duplicated keys (RedrivePolicy) are provided, when retrieving SQS attributes
180+
* https://github.com/localstack/localstack/issues/1992
181+
*/
182+
@Test
183+
public void testGetQueueRedrivePolicy() {
184+
String srcQueueName = "adapter-queue";
185+
String dlQueueName = "adapter-queue-dlq";
186+
187+
final AmazonSQS clientSQS = TestUtils.getClientSQS();
188+
final String srcQueueUrl = clientSQS.createQueue(srcQueueName).getQueueUrl();
189+
final String dlQueueUrl = clientSQS.createQueue(dlQueueName).getQueueUrl();
190+
191+
GetQueueAttributesResult dlQueueAttrs = clientSQS.getQueueAttributes(
192+
new GetQueueAttributesRequest(dlQueueUrl).withAttributeNames("QueueArn")
193+
);
194+
String dlQueueArn = dlQueueAttrs.getAttributes().get("QueueArn");
195+
196+
final String redrivePolicy = "{\"maxReceiveCount\": 5, \"deadLetterTargetArn\": \"" + dlQueueArn + "\"}";
197+
198+
SetQueueAttributesRequest request = new SetQueueAttributesRequest()
199+
.withQueueUrl(srcQueueUrl)
200+
.addAttributesEntry("RedrivePolicy", redrivePolicy)
201+
.addAttributesEntry("MessageRetentionPeriod", "345600")
202+
.addAttributesEntry("VisibilityTimeout", "30");
203+
204+
clientSQS.setQueueAttributes(request);
205+
206+
GetQueueAttributesResult result = clientSQS.getQueueAttributes(new GetQueueAttributesRequest(dlQueueUrl).withAttributeNames("RedrivePolicy"));
207+
Assert.assertTrue(result.getAttributes().isEmpty());
208+
209+
result = clientSQS.getQueueAttributes(new GetQueueAttributesRequest(srcQueueUrl).withAttributeNames("RedrivePolicy"));
210+
Assert.assertEquals(result.getAttributes().size(), 1);
211+
Assert.assertEquals(result.getAttributes().get("RedrivePolicy"), redrivePolicy);
212+
}
177213
}

0 commit comments

Comments
 (0)