You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "VaishnaviR18 (via GitHub)" <gi...@apache.org> on 2024/04/03 07:11:15 UTC

[PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

VaishnaviR18 opened a new pull request, #13678:
URL: https://github.com/apache/camel/pull/13678

   Issue link - https://issues.apache.org/jira/browse/CAMEL-19533
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally and I have committed all auto-generated changes
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "VaishnaviR18 (via GitHub)" <gi...@apache.org>.
VaishnaviR18 commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1549439333


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java:
##########
@@ -39,14 +43,17 @@ public void testDisconnect() throws Exception {
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "A Bla bla", "Subject", "Hello A");
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "B Bla bla", "Subject", "Hello B");
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E")));

Review Comment:
   Okay, thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "VaishnaviR18 (via GitHub)" <gi...@apache.org>.
VaishnaviR18 commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1552861969


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentsUmlautIssueTest.java:
##########
@@ -71,28 +73,28 @@ public void testSendAndReceiveMailWithAttachments() throws Exception {
         producer.process(exchange);
 
         // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
-        Thread.sleep(2000);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        Exchange out = mock.assertExchangeReceived(0);
-        mock.assertIsSatisfied();
-
-        // plain text
-        assertEquals("Hello World", out.getIn().getBody(String.class));
-
-        // attachment
-        Map<String, DataHandler> attachments = out.getIn(AttachmentMessage.class).getAttachments();
-        assertNotNull(attachments, "Should have attachments");
-        assertEquals(1, attachments.size());
-
-        DataHandler handler = out.getIn(AttachmentMessage.class).getAttachment(name);
-        assertNotNull(handler, "The " + name + " should be there");
-
-        String nameURLEncoded = URLEncoder.encode(name, Charset.defaultCharset().name());
-        assertTrue(handler.getContentType().endsWith(nameURLEncoded), "Handler content type should end with URL-encoded name");
-
-        assertEquals(name, handler.getName(), "Handler name should be the file name");
+        Awaitility.await().pollDelay(2, TimeUnit.SECONDS).untilAsserted(() -> {
+            MockEndpoint mock = getMockEndpoint("mock:result");

Review Comment:
   I have updated the code, can you please review it? 
   Thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske merged PR #13678:
URL: https://github.com/apache/camel/pull/13678


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "VaishnaviR18 (via GitHub)" <gi...@apache.org>.
VaishnaviR18 commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1549618196


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java:
##########
@@ -39,14 +43,17 @@ public void testDisconnect() throws Exception {
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "A Bla bla", "Subject", "Hello A");
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "B Bla bla", "Subject", "Hello B");
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E")));

Review Comment:
   @davsclaus i have updated the code. Can you please review it?
   Thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13678:
URL: https://github.com/apache/camel/pull/13678#issuecomment-2033724240

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :robot: CI automation will test this PR automatically.
   
   :camel: Apache Camel Committers, please review the following items:
   
   * First-time contributors **require MANUAL approval** for the GitHub Actions to run
   
   * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   * You can label PRs using `build-all`, `build-dependents`, `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
   
   * Build and test logs are available in the Summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. 
   
   * :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1549436506


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java:
##########
@@ -39,14 +43,17 @@ public void testDisconnect() throws Exception {
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "A Bla bla", "Subject", "Hello A");
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "B Bla bla", "Subject", "Hello B");
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E")));

Review Comment:
   Yes this is wrong as well, as you can risk having it send the message more than once as the code is called again



##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java:
##########
@@ -39,14 +43,17 @@ public void testDisconnect() throws Exception {
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "A Bla bla", "Subject", "Hello A");
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "B Bla bla", "Subject", "Hello B");
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E")));

Review Comment:
   Yes this is wrong as well, as you can risk having it send the message more than once if the code is called again



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "VaishnaviR18 (via GitHub)" <gi...@apache.org>.
VaishnaviR18 commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1549431082


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailDisconnectTest.java:
##########
@@ -39,14 +43,17 @@ public void testDisconnect() throws Exception {
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "A Bla bla", "Subject", "Hello A");
         template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "B Bla bla", "Subject", "Hello B");
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "C Bla bla", "Subject", "Hello C")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "D Bla bla", "Subject", "Hello D")));
 
-        Thread.sleep(500);
-        template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E");
+        Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(
+                        () -> template.sendBodyAndHeader(jones.uriPrefix(Protocol.smtp), "E Bla bla", "Subject", "Hello E")));

Review Comment:
   @davsclaus this is also not correct, right?



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "VaishnaviR18 (via GitHub)" <gi...@apache.org>.
VaishnaviR18 commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1552822516


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentsUmlautIssueTest.java:
##########
@@ -71,28 +73,28 @@ public void testSendAndReceiveMailWithAttachments() throws Exception {
         producer.process(exchange);
 
         // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
-        Thread.sleep(2000);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        Exchange out = mock.assertExchangeReceived(0);
-        mock.assertIsSatisfied();
-
-        // plain text
-        assertEquals("Hello World", out.getIn().getBody(String.class));
-
-        // attachment
-        Map<String, DataHandler> attachments = out.getIn(AttachmentMessage.class).getAttachments();
-        assertNotNull(attachments, "Should have attachments");
-        assertEquals(1, attachments.size());
-
-        DataHandler handler = out.getIn(AttachmentMessage.class).getAttachment(name);
-        assertNotNull(handler, "The " + name + " should be there");
-
-        String nameURLEncoded = URLEncoder.encode(name, Charset.defaultCharset().name());
-        assertTrue(handler.getContentType().endsWith(nameURLEncoded), "Handler content type should end with URL-encoded name");
-
-        assertEquals(name, handler.getName(), "Handler name should be the file name");
+        Awaitility.await().pollDelay(2, TimeUnit.SECONDS).untilAsserted(() -> {
+            MockEndpoint mock = getMockEndpoint("mock:result");

Review Comment:
   Oh okay. Sorry i was on PTO yesterday. I will adjust it. Thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1553180046


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentsUmlautIssueTest.java:
##########
@@ -71,28 +73,28 @@ public void testSendAndReceiveMailWithAttachments() throws Exception {
         producer.process(exchange);
 
         // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
-        Thread.sleep(2000);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        Exchange out = mock.assertExchangeReceived(0);
-        mock.assertIsSatisfied();
-
-        // plain text
-        assertEquals("Hello World", out.getIn().getBody(String.class));
-
-        // attachment
-        Map<String, DataHandler> attachments = out.getIn(AttachmentMessage.class).getAttachments();
-        assertNotNull(attachments, "Should have attachments");
-        assertEquals(1, attachments.size());
-
-        DataHandler handler = out.getIn(AttachmentMessage.class).getAttachment(name);
-        assertNotNull(handler, "The " + name + " should be there");
-
-        String nameURLEncoded = URLEncoder.encode(name, Charset.defaultCharset().name());
-        assertTrue(handler.getContentType().endsWith(nameURLEncoded), "Handler content type should end with URL-encoded name");
-
-        assertEquals(name, handler.getName(), "Handler name should be the file name");
+        Awaitility.await().pollDelay(2, TimeUnit.SECONDS).untilAsserted(() -> {
+            MockEndpoint mock = getMockEndpoint("mock:result");

Review Comment:
   Thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #13678:
URL: https://github.com/apache/camel/pull/13678#discussion_r1549846065


##########
components/camel-mail/src/test/java/org/apache/camel/component/mail/MailAttachmentsUmlautIssueTest.java:
##########
@@ -71,28 +73,28 @@ public void testSendAndReceiveMailWithAttachments() throws Exception {
         producer.process(exchange);
 
         // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
-        Thread.sleep(2000);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        Exchange out = mock.assertExchangeReceived(0);
-        mock.assertIsSatisfied();
-
-        // plain text
-        assertEquals("Hello World", out.getIn().getBody(String.class));
-
-        // attachment
-        Map<String, DataHandler> attachments = out.getIn(AttachmentMessage.class).getAttachments();
-        assertNotNull(attachments, "Should have attachments");
-        assertEquals(1, attachments.size());
-
-        DataHandler handler = out.getIn(AttachmentMessage.class).getAttachment(name);
-        assertNotNull(handler, "The " + name + " should be there");
-
-        String nameURLEncoded = URLEncoder.encode(name, Charset.defaultCharset().name());
-        assertTrue(handler.getContentType().endsWith(nameURLEncoded), "Handler content type should end with URL-encoded name");
-
-        assertEquals(name, handler.getName(), "Handler name should be the file name");
+        Awaitility.await().pollDelay(2, TimeUnit.SECONDS).untilAsserted(() -> {
+            MockEndpoint mock = getMockEndpoint("mock:result");

Review Comment:
   Setting up the expectations should be done outside the untilAsserted. In general we should have only the assertion code within that.
   
   Can you adjust this, please?



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org