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 ae071ab4eb0946fd75c35e09ab6ac67466c472f2 Author: Nikita Konovalov <[email protected]> AuthorDate: Wed Jul 31 12:57:24 2024 +0200 CAMEL-19538: added assertThrows where needed --- ...lpTcpClientProducerIdleConnectionTimeoutTest.java | 15 ++++++--------- .../mllp/MllpTcpServerConsumerBindTimeoutTest.java | 8 ++------ .../mllp/MllpTcpServerConsumerConnectionTest.java | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 25 deletions(-) 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 02d79063651..6718eb0a3c4 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 @@ -31,15 +31,14 @@ import org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException; import org.apache.camel.test.junit.rule.mllp.MllpServerResource; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.camel.test.mllp.Hl7TestMessageGenerator; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.awaitility.Awaitility; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; public class MllpTcpClientProducerIdleConnectionTimeoutTest extends CamelTestSupport { @@ -146,13 +145,11 @@ public class MllpTcpClientProducerIdleConnectionTimeoutTest extends CamelTestSup assertTrue(done.matches(5, TimeUnit.SECONDS), "Should have completed two exchanges"); }); - Awaitility.await().atMost((long) (IDLE_TIMEOUT * 1.1), TimeUnit.MILLISECONDS).untilAsserted(() -> { - try { - mllpServer.checkClientConnections(); - fail("Should receive and exception for the closed connection"); - } catch (MllpJUnitResourceException expectedEx) { - // Eat this - } + Awaitility.await().untilAsserted(() -> { + assertThrows(MllpJUnitResourceException.class, () -> + mllpServer.checkClientConnections(), + "Should receive and exception for the closed connection"); + source.sendBody(Hl7TestMessageGenerator.generateMessage()); 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 bc74e1d7137..234f6ae09d8 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 @@ -30,10 +30,8 @@ import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit.rule.mllp.MllpClientResource; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.camel.test.mllp.Hl7TestMessageGenerator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import org.awaitility.Awaitility; public class MllpTcpServerConsumerBindTimeoutTest extends CamelTestSupport { @@ -93,10 +91,8 @@ public class MllpTcpServerConsumerBindTimeoutTest extends CamelTestSupport { Thread tmpThread = new Thread(() -> { try { ServerSocket tmpSocket = new ServerSocket(mllpClient.getMllpPort()); - Awaitility.await().atMost(15, TimeUnit.SECONDS).untilAsserted(() -> { - tmpSocket.close(); - Assertions.assertTrue(tmpSocket.isClosed()); - }); + Thread.sleep(15000); + tmpSocket.close(); } catch (Exception ex) { throw new RuntimeCamelException("Exception caught in dummy listener", ex); } 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 4ebe99d56bd..005ea041b01 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 @@ -26,14 +26,14 @@ import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit.rule.mllp.MllpClientResource; import org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException; import org.apache.camel.test.junit5.CamelTestSupport; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import 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; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MllpTcpServerConsumerConnectionTest extends CamelTestSupport { static final int RECEIVE_TIMEOUT = 1000; @@ -135,14 +135,14 @@ public class MllpTcpServerConsumerConnectionTest extends CamelTestSupport { mllpClient.connect(); mllpClient.sendMessageAndWaitForAcknowledgement(testMessage); - 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"); - } catch (MllpJUnitResourceException expectedEx) { - assertEquals("checkConnection failed - read() returned END_OF_STREAM", expectedEx.getMessage()); - assertNull(expectedEx.getCause()); - } + Awaitility.await().untilAsserted(() -> { + + MllpJUnitResourceException ex = assertThrows(MllpJUnitResourceException.class, () -> + mllpClient.checkConnection(), + "The MllpClientResource should have thrown an exception when writing to the reset socket"); + + assertEquals("checkConnection failed - read() returned END_OF_STREAM", ex.getMessage()); + assertNull(ex.getCause()); MockEndpoint.assertIsSatisfied(context, 15, TimeUnit.SECONDS); });
