Repository navigation
feat(sqs-source): make maximum backoff configurable per queue #7186
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,29 @@ | |
|
|
||
| package org.opensearch.dataprepper.plugins.source.sqs; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| import jakarta.validation.ConstraintViolation; | ||
| import jakarta.validation.Validation; | ||
| import jakarta.validation.Validator; | ||
| import jakarta.validation.ValidatorFactory; | ||
| import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Set; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class QueueConfigTest { | ||
|
|
||
| private static final ObjectMapper YAML_MAPPER = | ||
| new ObjectMapper(new YAMLFactory()).registerModule(new JavaTimeModule()); | ||
|
|
||
| @Test | ||
| void testDefaultValues() { | ||
| final QueueConfig queueConfig = new QueueConfig(); | ||
|
|
@@ -33,5 +47,37 @@ void testDefaultValues() { | |
| assertEquals(Duration.ofHours(2), queueConfig.getVisibilityDuplicateProtectionTimeout(), | ||
| "Visibility duplicate protection timeout should default to 2 hours"); | ||
| assertNull(queueConfig.getWaitTime(), "Wait time should default to null"); | ||
| assertEquals(Duration.ofMinutes(5), queueConfig.getMaximumBackoff(), | ||
| "Maximum backoff should default to 5 minutes"); | ||
| } | ||
|
|
||
| @Test | ||
| void testMaximumBackoffReadsConfiguredValue() throws Exception { | ||
| final String yaml = "url: \"https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue\"\n" | ||
| + "maximum_backoff: \"PT10M\"\n"; | ||
|
|
||
| final QueueConfig queueConfig = YAML_MAPPER.readValue(yaml, QueueConfig.class); | ||
|
|
||
| assertEquals(Duration.ofMinutes(10), queueConfig.getMaximumBackoff(), | ||
| "Maximum backoff should reflect the configured value"); | ||
| } | ||
|
|
||
| @Test | ||
| void testMaximumBackoffBelowMinimumFailsValidation() throws Exception { | ||
| final String yaml = "url: \"https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue\"\n" | ||
| + "maximum_backoff: \"PT10S\"\n"; | ||
|
|
||
| final QueueConfig queueConfig = YAML_MAPPER.readValue(yaml, QueueConfig.class); | ||
|
|
||
| // ParameterMessageInterpolator avoids requiring a Jakarta EL provider on the test classpath. | ||
| try (final ValidatorFactory factory = Validation.byDefaultProvider().configure() | ||
| .messageInterpolator(new ParameterMessageInterpolator()) | ||
| .buildValidatorFactory()) { | ||
| final Validator validator = factory.getValidator(); | ||
| final Set<ConstraintViolation<QueueConfig>> violations = validator.validate(queueConfig); | ||
| assertTrue( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small style request: Data Prepper prefers Hamcrest for new assertions. Could you switch the new ones here (lines 50, 61 and 78) to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will switch the three new assertions to Hamcrest. |
||
| violations.stream().anyMatch(v -> v.getPropertyPath().toString().equals("maximumBackoff")), | ||
| "Expected a validation violation on maximumBackoff for a value below 20 seconds"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test that
maximum_backoffreaches the backoff, or that values under 20s are rejected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. I'll add tests to cover both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests, @LuisNorman! One small gap:
SqsServiceTestdoesn't useMockitoExtension, so thegetMaximumBackoff()stub is lenient, and the tests still pass if this line goes back tocreateExponentialBackoff(). Could you add a check that the configuredmaximum_backoffactually reachesSqsBackoff? AMockedStaticonSqsBackoffwith averifyon the configuredDurationwould do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Will wrap the test in
MockedStatic<SqsBackoff>and verify the configuredDurationreaches the factory.