This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit a3b4c93554794011f6a1066f9140fa46adbd48e4 Author: Nikita Konovalov <[email protected]> AuthorDate: Tue Jul 30 12:28:09 2024 +0200 CAMEL-19538: Fixed awaitility issues in camel-mllp --- .../MllpTcpServerConsumerLenientBindTest.java | 2 +- .../mllp/MllpIdleTimeoutStrategyTest.java | 2 +- ...TcpClientProducerIdleConnectionTimeoutTest.java | 9 ++++----- .../mllp/MllpTcpServerConsumerBindTimeoutTest.java | 23 ++++++++++------------ .../mllp/MllpTcpServerConsumerConnectionTest.java | 19 +++++++++--------- ...rConsumerEndOfDataAndValidationTestSupport.java | 3 ++- .../camel/test/tcp/JavaSocketManualTests.java | 3 ++- 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/components/camel-mllp/src/test/java/org/apache/camel/MllpTcpServerConsumerLenientBindTest.java b/components/camel-mllp/src/test/java/org/apache/camel/MllpTcpServerConsumerLenientBindTest.java index e885463f5e8..953984e6bcd 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/MllpTcpServerConsumerLenientBindTest.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/MllpTcpServerConsumerLenientBindTest.java @@ -90,7 +90,7 @@ public class MllpTcpServerConsumerLenientBindTest extends CamelTestSupport { mllpClient.reset(); portBlocker.close(); - Awaitility.await().pollDelay(2000, TimeUnit.MILLISECONDS) + Awaitility.await().atMost(2000, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertEquals(ServiceStatus.Started, context.getStatus())); mllpClient.connect(); diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpIdleTimeoutStrategyTest.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpIdleTimeoutStrategyTest.java index de9c31457c0..e735790e119 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpIdleTimeoutStrategyTest.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpIdleTimeoutStrategyTest.java @@ -151,7 +151,7 @@ public class MllpIdleTimeoutStrategyTest extends CamelTestSupport { template.sendBody(Hl7TestMessageGenerator.generateMessage()); // Need to send one message to get the connection established - Awaitility.await().pollDelay(IDLE_TIMEOUT * 3, TimeUnit.MILLISECONDS) + Awaitility.await().atMost(IDLE_TIMEOUT * 3, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.MILLISECONDS) .untilAsserted(() -> MockEndpoint.assertIsSatisfied(context, 5, TimeUnit.SECONDS)); } diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleConnectionTimeoutTest.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleConnectionTimeoutTest.java index 9927885d52a..b593b2e1d41 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleConnectionTimeoutTest.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleConnectionTimeoutTest.java @@ -115,7 +115,7 @@ public class MllpTcpClientProducerIdleConnectionTimeoutTest extends CamelTestSup // Need to send one message to get the connection established source.sendBody(Hl7TestMessageGenerator.generateMessage()); - Awaitility.await().untilAsserted(() -> { + Awaitility.await().atMost(IDLE_TIMEOUT / 2, TimeUnit.MILLISECONDS).untilAsserted(() -> { source.sendBody(Hl7TestMessageGenerator.generateMessage()); assertTrue(done.matches(5, TimeUnit.SECONDS), "Should have completed two exchanges"); @@ -123,7 +123,7 @@ public class MllpTcpClientProducerIdleConnectionTimeoutTest extends CamelTestSup MockEndpoint.assertIsSatisfied(context, 5, TimeUnit.SECONDS); }); - Awaitility.await().untilAsserted(() -> { + Awaitility.await().atMost((long) (IDLE_TIMEOUT * 1.1), TimeUnit.MILLISECONDS).untilAsserted(() -> { assertThrows(MllpJUnitResourceException.class, () -> mllpServer.checkClientConnections()); }); @@ -140,14 +140,13 @@ public class MllpTcpClientProducerIdleConnectionTimeoutTest extends CamelTestSup // Need to send one message to get the connection established source.sendBody(Hl7TestMessageGenerator.generateMessage()); - Awaitility.await().untilAsserted(() -> { - Thread.sleep(IDLE_TIMEOUT / 2); + Awaitility.await().atMost(IDLE_TIMEOUT / 2, TimeUnit.MILLISECONDS).untilAsserted(() -> { source.sendBody(Hl7TestMessageGenerator.generateMessage()); assertTrue(done.matches(5, TimeUnit.SECONDS), "Should have completed two exchanges"); }); - Awaitility.await().untilAsserted(() -> { + Awaitility.await().atMost((long) (IDLE_TIMEOUT * 1.1), TimeUnit.MILLISECONDS).untilAsserted(() -> { try { mllpServer.checkClientConnections(); fail("Should receive and exception for the closed connection"); diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerBindTimeoutTest.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerBindTimeoutTest.java index 2419818a579..972294c930e 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerBindTimeoutTest.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerBindTimeoutTest.java @@ -90,20 +90,17 @@ public class MllpTcpServerConsumerBindTimeoutTest extends CamelTestSupport { public void testReceiveSingleMessage() throws Exception { result.expectedMessageCount(1); - Thread tmpThread = new Thread() { - public void run() { - try { - ServerSocket tmpSocket = new ServerSocket(mllpClient.getMllpPort()); - Awaitility.await().untilAsserted(() -> { - tmpSocket.close(); - Assertions.assertTrue(tmpSocket.isClosed()); - }); - } catch (Exception ex) { - throw new RuntimeCamelException("Exception caught in dummy listener", ex); - } + Thread tmpThread = new Thread(() -> { + try { + ServerSocket tmpSocket = new ServerSocket(mllpClient.getMllpPort()); + Awaitility.await().atMost(15, TimeUnit.SECONDS).untilAsserted(() -> { + tmpSocket.close(); + Assertions.assertTrue(tmpSocket.isClosed()); + }); + } catch (Exception ex) { + throw new RuntimeCamelException("Exception caught in dummy listener", ex); } - - }; + }); tmpThread.start(); diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerConnectionTest.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerConnectionTest.java index a4ebc6cc00f..a0e952a94ac 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerConnectionTest.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpServerConsumerConnectionTest.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.shaded.org.awaitility.Awaitility; +import static org.apache.camel.test.junit5.ThrottlingExecutor.slowly; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; @@ -82,10 +83,10 @@ public class MllpTcpServerConsumerConnectionTest extends CamelTestSupport { addTestRouteWithIdleTimeout(-1); - for (int i = 1; i <= connectionCount; ++i) { - mllpClient.connect(); - mllpClient.close(); - } + slowly().repeat(connectionCount).awaiting(connectionMillis, TimeUnit.MILLISECONDS) + .beforeEach((i) -> mllpClient.connect()) + .afterEach((i) -> mllpClient.reset()) + .execute(); // Connect one more time and allow a client thread to start mllpClient.connect(); @@ -104,10 +105,10 @@ public class MllpTcpServerConsumerConnectionTest extends CamelTestSupport { addTestRouteWithIdleTimeout(-1); - for (int i = 1; i <= connectionCount; ++i) { - mllpClient.connect(); - mllpClient.reset(); - } + slowly().repeat(connectionCount).awaiting(connectionMillis, TimeUnit.MILLISECONDS) + .beforeEach((i) -> mllpClient.connect()) + .afterEach((i) -> mllpClient.reset()) + .execute(); // Connect one more time and allow a client thread to start mllpClient.connect(); @@ -134,7 +135,7 @@ public class MllpTcpServerConsumerConnectionTest extends CamelTestSupport { mllpClient.connect(); mllpClient.sendMessageAndWaitForAcknowledgement(testMessage); - Awaitility.await().untilAsserted(() -> { + Awaitility.await().atMost(idleTimeout + RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS).untilAsserted(() -> { try { mllpClient.checkConnection(); fail("The MllpClientResource should have thrown an exception when writing to the reset socket"); diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/TcpServerConsumerEndOfDataAndValidationTestSupport.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/TcpServerConsumerEndOfDataAndValidationTestSupport.java index 4b947ae8075..89b8fe1d0ff 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/TcpServerConsumerEndOfDataAndValidationTestSupport.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/TcpServerConsumerEndOfDataAndValidationTestSupport.java @@ -241,7 +241,8 @@ public abstract class TcpServerConsumerEndOfDataAndValidationTestSupport extends log.info("Sending first message"); mllpClient.sendFramedData(Hl7TestMessageGenerator.generateMessage(10001)); - Awaitility.await().pollDelay(RECEIVE_TIMEOUT * 5, TimeUnit.MILLISECONDS).untilAsserted(() -> { + Awaitility.await().atMost(RECEIVE_TIMEOUT * 5, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.MILLISECONDS) + .untilAsserted(() -> { mllpClient.setSendEndOfBlock(true); mllpClient.setSendEndOfData(true); diff --git a/components/camel-mllp/src/test/java/org/apache/camel/test/tcp/JavaSocketManualTests.java b/components/camel-mllp/src/test/java/org/apache/camel/test/tcp/JavaSocketManualTests.java index 30b8623f0c1..1c0eac3fd42 100644 --- a/components/camel-mllp/src/test/java/org/apache/camel/test/tcp/JavaSocketManualTests.java +++ b/components/camel-mllp/src/test/java/org/apache/camel/test/tcp/JavaSocketManualTests.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketTimeoutException; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -285,7 +286,7 @@ public class JavaSocketManualTests { log.info("Client Socket read() timed-out before close"); } clientSocket.getOutputStream().write(27); - Awaitility.await().untilAsserted(() -> { + Awaitility.await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted(() -> { log.info("Client Socket available() returned {} after close", clientSocket.getInputStream().available()); log.info("Client Socket read() returned {} after close", clientSocket.getInputStream().read()); // Javadoc for Socket says closing the InputStream will close the connection
