davsclaus commented on code in PR #27985: URL: https://github.com/apache/camel/pull/27985#discussion_r4302183077
########## components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsConsumerExtendMessageVisibilityBatchTest.java: ########## @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.aws2.sqs; + +import java.time.Duration; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.EndpointInject; +import org.apache.camel.ServiceStatus; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequest; +import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchResponse; +import software.amazon.awssdk.services.sqs.model.Message; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +/** + * With {@code extendMessageVisibility=true} and more than one message per poll, the messages that wait in the batch for + * their turn must be kept invisible too: their visibility timeout runs from the receive, not from the start of their + * own processing. + */ +class SqsConsumerExtendMessageVisibilityBatchTest extends CamelTestSupport { + + private static final int VISIBILITY_TIMEOUT_SECONDS = 2; + private static final String FIRST_HANDLE = "receipt-handle-1"; + private static final String SECOND_HANDLE = "receipt-handle-2"; + + private final CountDownLatch firstStarted = new CountDownLatch(1); + private final CountDownLatch releaseFirst = new CountDownLatch(1); + private final CountDownLatch secondExtended = new CountDownLatch(1); + private final ExecutorService suspender = Executors.newSingleThreadExecutor(); + + @EndpointInject("mock:result") + private MockEndpoint mock; + + @BindToRegistry("amazonSQSClient") + private final AmazonSQSClientMock client = new AmazonSQSClientMock() { + @Override + public ChangeMessageVisibilityBatchResponse changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request) { + if (request.entries().stream().anyMatch(e -> SECOND_HANDLE.equals(e.receiptHandle()))) { + secondExtended.countDown(); + } + return super.changeMessageVisibilityBatch(request); + } + }; + + { + // both messages are on the queue before the route starts, so that the first poll receives them together + client.addMessage(Message.builder().body("first").messageId("id-1").receiptHandle(FIRST_HANDLE).build()); + client.addMessage(Message.builder().body("second").messageId("id-2").receiptHandle(SECOND_HANDLE).build()); + } + + @AfterEach + void releaseRoute() { + releaseFirst.countDown(); + suspender.shutdownNow(); + } Review Comment: Optional test hardening, not blocking: the latch is counted down first, and the CamelContext is stopped after this method, so a leftover suspender thread does not reach the next test. Resolving so the fix can be merged; adding `awaitTermination` in a later change to this test is welcome. _Claude Code on behalf of Claus Ibsen_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
