You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/07/14 08:23:26 UTC

[camel] 01/05: (chores) camel-core: file test fixes and cleanups

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 38aa89cc942c156695808afde7479aa321fcf11d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 08:33:06 2023 +0200

    (chores) camel-core: file test fixes and cleanups
    
    - adjust timeouts for less flakiness on slower hosts
    - replace Thread.sleep with Awaitility
    - other minor cleanups
---
 .../component/file/watch/FileWatchComponentTest.java   | 18 +++++++++---------
 .../file/FileConsumerDeleteAndMoveFailedTest.java      |  2 ++
 .../component/file/FileConsumerPollStrategyTest.java   |  9 +++++----
 .../component/file/FileConsumerPreMoveNoopTest.java    |  8 +++++---
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
index be1cd855318..22765424c11 100644
--- a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
+++ b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTest.java
@@ -125,7 +125,7 @@ public class FileWatchComponentTest extends FileWatchComponentTestBase {
                 .getHeader(FileWatchConstants.EVENT_TYPE_HEADER, FileEventEnum.class) == FileEventEnum.CREATE);
 
         for (int i = 0; i < 10; i++) {
-            createFile(testPath(), i + "");
+            createFile(testPath(), String.valueOf(i));
         }
 
         MockEndpoint.assertIsSatisfied(context);
@@ -135,32 +135,32 @@ public class FileWatchComponentTest extends FileWatchComponentTestBase {
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("file-watch://" + testPath())
+                fromF("file-watch://%s", testPath())
                         .routeId("watchAll")
                         .to("mock:watchAll");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=*.txt", testPath())
                         .routeId("onlyTxtInRoot")
                         .to("mock:onlyTxtInRoot");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=*/*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=*/*.txt", testPath())
                         .routeId("onlyTxtInSubdirectory")
                         .to("mock:onlyTxtInSubdirectory");
 
-                from("file-watch://" + testPath() + "?events=CREATE&antInclude=**/*.txt")
+                fromF("file-watch://%s?events=CREATE&antInclude=**/*.txt", testPath())
                         .routeId("onlyTxtAnywhere")
                         .to("mock:onlyTxtAnywhere");
 
-                from("file-watch://" + testPath() + "?events=CREATE")
+                fromF("file-watch://%s?events=CREATE", testPath())
                         .to("mock:watchCreate");
 
-                from("file-watch://" + testPath() + "?events=MODIFY")
+                fromF("file-watch://%s?events=MODIFY", testPath())
                         .to("mock:watchModify");
 
-                from("file-watch://" + testPath() + "?events=DELETE,CREATE")
+                fromF("file-watch://%s?events=DELETE,CREATE", testPath())
                         .to("mock:watchDeleteOrCreate");
 
-                from("file-watch://" + testPath() + "?events=DELETE,MODIFY")
+                fromF("file-watch://%s?events=DELETE,MODIFY", testPath())
                         .to("mock:watchDeleteOrModify");
             }
         };
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
index a7fe5a9eb2c..b3944bb96c9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailedTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.file;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.parallel.Isolated;
 
+@Isolated("Flaky and may have conflicts if running along with its parent class")
 public class FileConsumerDeleteAndMoveFailedTest extends FileConsumerDeleteAndFailureTest {
 
     @Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
index 07fbf9fe01d..b3abb6ef1cd 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file;
 
+import java.time.Duration;
+
 import org.apache.camel.Consumer;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
@@ -24,6 +26,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.apache.camel.spi.Registry;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -64,10 +67,8 @@ public class FileConsumerPollStrategyTest extends ContextTestSupport {
 
         oneExchangeDone.matchesWaitTime();
 
-        // give file consumer a bit time
-        Thread.sleep(20);
-
-        assertTrue(event.startsWith("rollbackcommit"));
+        // give the file consumer a bit of time
+        Awaitility.await().atMost(Duration.ofSeconds(1)).untilAsserted(() -> assertTrue(event.startsWith("rollbackcommit")));
     }
 
     private static class MyPollStrategy implements PollingConsumerPollStrategy {
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
index 699cd606002..65ea7399225 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java
@@ -29,12 +29,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
 
+    private final String endpointUri = fileUri();
+
     @Test
     public void testPreMoveNoop() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
 
-        template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
 
@@ -48,7 +50,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");
 
-        template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
         oneExchangeDone.matchesWaitTime();
@@ -58,7 +60,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport {
         oneExchangeDone.reset();
         mock.expectedBodiesReceived("Hello Again World");
 
-        template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(endpointUri, "Hello Again World", Exchange.FILE_NAME, "hello.txt");
 
         assertMockEndpointsSatisfied();
         oneExchangeDone.matchesWaitTime();