Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] CAMEL-19533 - camel-mail: replace Thread.sleep in tests. [camel]
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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org