From 4bd8bf743928b701b14b5dab3f322b8f94662ae7 Mon Sep 17 00:00:00 2001 From: Joey Echeverria Date: Wed, 2 Oct 2024 17:53:41 -0500 Subject: [PATCH] fix: Timeout settings in SqsTemplate * Timeouts were being set by calling Duration#getSecondsPart whic is alwawys a number between 0 and 59 * Update to use Duration#getSeconds to get the full timeout specified, in seconds --- .../java/io/awspring/cloud/sqs/operations/SqsTemplate.java | 4 ++-- .../io/awspring/cloud/sqs/operations/SqsTemplateTests.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java b/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java index 4c6ff0a23..840d2960d 100644 --- a/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java +++ b/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java @@ -602,11 +602,11 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout ReceiveMessageRequest.Builder builder = ReceiveMessageRequest.builder().queueUrl(attributes.getQueueUrl()) .maxNumberOfMessages(maxNumberOfMessages).messageAttributeNames(this.messageAttributeNames) .attributeNamesWithStrings(this.messageSystemAttributeNames) - .waitTimeSeconds(pollTimeout.toSecondsPart()); + .waitTimeSeconds(pollTimeout.toSeconds()); if (additionalHeaders.containsKey(SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER)) { builder.visibilityTimeout( getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class) - .toSecondsPart()); + .toSeconds()); } if (additionalHeaders.containsKey(SqsHeaders.SQS_RECEIVE_REQUEST_ATTEMPT_ID_HEADER)) { builder.receiveRequestAttemptId( diff --git a/spring-cloud-aws-sqs/src/test/java/io/awspring/cloud/sqs/operations/SqsTemplateTests.java b/spring-cloud-aws-sqs/src/test/java/io/awspring/cloud/sqs/operations/SqsTemplateTests.java index f9ab5cec7..a182b2648 100644 --- a/spring-cloud-aws-sqs/src/test/java/io/awspring/cloud/sqs/operations/SqsTemplateTests.java +++ b/spring-cloud-aws-sqs/src/test/java/io/awspring/cloud/sqs/operations/SqsTemplateTests.java @@ -937,7 +937,7 @@ void shouldReceiveFromOptions() { .willReturn(CompletableFuture.completedFuture(deleteResponse)); SqsOperations template = SqsTemplate.newSyncTemplate(mockClient); Optional> receivedMessage = template.receive(from -> from.queue(queue) - .pollTimeout(Duration.ofSeconds(1)).visibilityTimeout(Duration.ofSeconds(5)) + .pollTimeout(Duration.ofSeconds(61)).visibilityTimeout(Duration.ofSeconds(65)) .additionalHeader(headerName1, headerValue1).additionalHeaders(Map.of(headerName2, headerValue2)), String.class); assertThat(receivedMessage).isPresent().hasValueSatisfying(message -> { @@ -949,8 +949,8 @@ void shouldReceiveFromOptions() { then(mockClient).should().receiveMessage(captor.capture()); ReceiveMessageRequest request = captor.getValue(); assertThat(request.maxNumberOfMessages()).isEqualTo(1); - assertThat(request.visibilityTimeout()).isEqualTo(5); - assertThat(request.waitTimeSeconds()).isEqualTo(1); + assertThat(request.visibilityTimeout()).isEqualTo(65); + assertThat(request.waitTimeSeconds()).isEqualTo(61); } @Test