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 c2a17bc4ef3dbe45c2b9ac6e7e712206c447cc37 Author: Nikita Konovalov <nkono...@redhat.com> AuthorDate: Wed Aug 28 13:54:21 2024 +0200 CAMEL-19538: changed some ineffective assertions --- ...rConsumerEndOfDataAndValidationTestSupport.java | 32 +++++++++++----------- .../camel/test/tcp/JavaSocketManualTests.java | 18 ++++++------ 2 files changed, 25 insertions(+), 25 deletions(-) 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 1a3a569ef5a..e1ded8a621e 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 @@ -36,7 +36,6 @@ 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.apache.camel.component.mllp.MllpExceptionTestSupport.LOG_PHI_TRUE; import static org.hamcrest.CoreMatchers.instanceOf; @@ -139,6 +138,8 @@ public abstract class TcpServerConsumerEndOfDataAndValidationTestSupport extends setExpectedCounts(); mllpClient.connect(); + + Thread.sleep(5000); mllpClient.sendMessageAndWaitForAcknowledgement(Hl7TestMessageGenerator.generateMessage(), 10000); } @@ -186,6 +187,7 @@ public abstract class TcpServerConsumerEndOfDataAndValidationTestSupport extends log.info("Expected exception reading response"); } mllpClient.disconnect(); + Thread.sleep(1000); mllpClient.connect(); log.info("Sending TEST_MESSAGE_4"); @@ -241,22 +243,20 @@ public abstract class TcpServerConsumerEndOfDataAndValidationTestSupport extends log.info("Sending first message"); mllpClient.sendFramedData(Hl7TestMessageGenerator.generateMessage(10001)); - Awaitility.await().atMost(RECEIVE_TIMEOUT * 5, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.MILLISECONDS) - .untilAsserted(() -> { - mllpClient.setSendEndOfBlock(true); - mllpClient.setSendEndOfData(true); + Thread.sleep(RECEIVE_TIMEOUT * 5); - try { - log.info("Attempting to send second message"); - String acknowledgement - = mllpClient.sendMessageAndWaitForAcknowledgement(Hl7TestMessageGenerator.generateMessage(10002)); - assertEquals("", acknowledgement, - "If the send doesn't throw an exception, the acknowledgement should be empty"); - } catch (MllpJUnitResourceException expected) { - assertThat("If the send throws an exception, the cause should be a SocketException", expected.getCause(), - instanceOf(SocketException.class)); - } - }); + mllpClient.setSendEndOfBlock(true); + mllpClient.setSendEndOfData(true); + + try { + log.info("Attempting to send second message"); + String acknowledgement + = mllpClient.sendMessageAndWaitForAcknowledgement(Hl7TestMessageGenerator.generateMessage(10002)); + assertEquals("", acknowledgement, "If the send doesn't throw an exception, the acknowledgement should be empty"); + } catch (MllpJUnitResourceException expected) { + assertThat("If the send throws an exception, the cause should be a SocketException", expected.getCause(), + instanceOf(SocketException.class)); + } mllpClient.disconnect(); mllpClient.connect(); 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 4741a539dcd..5358445bb7a 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 @@ -26,13 +26,13 @@ import java.net.Socket; import java.net.SocketTimeoutException; import java.util.concurrent.TimeUnit; +import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.awaitility.Awaitility; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -286,15 +286,15 @@ public class JavaSocketManualTests { log.info("Client Socket read() timed-out before close"); } clientSocket.getOutputStream().write(27); + 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 + clientSocket.getInputStream().close(); + if (!clientSocket.isClosed()) { + log.warn("Closing input stream didn't close socket"); + clientSocket.close(); + } 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 - clientSocket.getInputStream().close(); - if (!clientSocket.isClosed()) { - log.warn("Closing input stream didn't close socket"); - clientSocket.close(); - } assertTrue(clientSocket.isClosed()); });