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


The following commit(s) were added to refs/heads/main by this push:
     new 7ef392d306a CAMEL-19519: camel-file: replace Thread.sleep in tests. 
(#12844)
7ef392d306a is described below

commit 7ef392d306ad81b35712efdb7feb2740aa731c9b
Author: Vaishnavi R <66722776+vaishnavi...@users.noreply.github.com>
AuthorDate: Mon Jan 22 20:30:47 2024 +0530

    CAMEL-19519: camel-file: replace Thread.sleep in tests. (#12844)
    
    Co-authored-by: Vaishnavi R <v...@var-thinkpadp1gen4i.remote.csb>
---
 .../component/file/DirectoryCreateIssueTest.java     | 12 +++++++-----
 .../file/FileConsumeNoopIdempotentEnabledTest.java   |  9 ++++++---
 .../file/FileConsumePollEnrichFileIdleEventTest.java | 20 ++++++++++++--------
 .../file/FileConsumePollEnrichFileTest.java          | 15 +++++++++------
 .../FileConsumerIdempotentKeyChangedIssue2Test.java  | 10 +++++-----
 .../file/FileConsumerIdempotentRefTest.java          |  7 +++++--
 .../component/file/FileConsumerIdempotentTest.java   |  5 +++--
 .../file/FileConsumerPollStrategyNotBeginTest.java   |  8 +++++---
 .../component/file/FilePollingConsumerTest.java      | 14 +++++++-------
 .../file/FilerConsumerDoneFileNameDeleteTest.java    |  6 ++++--
 .../file/FilerConsumerDoneFileNamePrefixTest.java    |  6 ++++--
 .../FilerConsumerDoneFileNameSimplePrefixTest.java   |  6 ++++--
 .../file/FilerConsumerDoneFileNameSuffixTest.java    |  6 ++++--
 .../file/FilerConsumerDoneFileNameTest.java          |  6 ++++--
 .../file/FilerConsumerDualDoneFileNameTest.java      |  7 ++++---
 .../file/FilerConsumerPreMoveDoneFileNameTest.java   |  6 ++++--
 .../FilerConsumerShouldSkipDoneFilePrefixTest.java   |  6 ++++--
 .../FilerConsumerShouldSkipDoneFileSuffixTest.java   |  6 ++++--
 .../file/FilerConsumerShouldSkipDoneFileTest.java    |  6 ++++--
 .../FileLockClusteredRoutePolicyFactoryTest.java     |  6 +++++-
 .../cluster/FileLockClusteredRoutePolicyTest.java    |  6 +++++-
 21 files changed, 109 insertions(+), 64 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/DirectoryCreateIssueTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/DirectoryCreateIssueTest.java
index e5ece8606f4..7ce9bb9f9e4 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/DirectoryCreateIssueTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/DirectoryCreateIssueTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file;
 
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -24,6 +25,7 @@ import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -63,11 +65,11 @@ public class DirectoryCreateIssueTest extends 
ContextTestSupport {
         assertMockEndpointsSatisfied();
 
         // wait a little while for the files to settle down
-        Thread.sleep(50);
-
-        for (int i = 0; i < numFiles; i++) {
-            assertTrue(Files.isRegularFile(testFile("a/b/c/d/e/f/g/h/file" + i 
+ ".txt")));
-        }
+        Awaitility.await().pollDelay(50, 
TimeUnit.MILLISECONDS).untilAsserted(() -> {
+            for (int i = 0; i < numFiles; i++) {
+                assertTrue(Files.isRegularFile(testFile("a/b/c/d/e/f/g/h/file" 
+ i + ".txt")));
+            }
+        });
     }
 
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeNoopIdempotentEnabledTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeNoopIdempotentEnabledTest.java
index fd262948ff5..cb681b494f6 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeNoopIdempotentEnabledTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeNoopIdempotentEnabledTest.java
@@ -16,10 +16,13 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class FileConsumeNoopIdempotentEnabledTest extends ContextTestSupport {
@@ -33,9 +36,9 @@ public class FileConsumeNoopIdempotentEnabledTest extends 
ContextTestSupport {
         template.sendBodyAndHeader(fileUri(), "Hello World", 
Exchange.FILE_NAME, "hello.txt");
 
         // give some time to let consumer try to read the file multiple times
-        Thread.sleep(50);
-
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(50, 
TimeUnit.MILLISECONDS).untilAsserted(() -> {
+            assertMockEndpointsSatisfied();
+        });
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileIdleEventTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileIdleEventTest.java
index 98e22677da6..48d97292cdd 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileIdleEventTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileIdleEventTest.java
@@ -16,10 +16,13 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class FileConsumePollEnrichFileIdleEventTest extends ContextTestSupport 
{
@@ -38,15 +41,16 @@ public class FileConsumePollEnrichFileIdleEventTest extends 
ContextTestSupport {
                 "Event1.txt");
 
         log.info("Sleeping for 1 sec before writing enrichdata file");
-        Thread.sleep(1000);
-        template.sendBodyAndHeader(fileUri("enrichdata"), "EnrichData",
-                Exchange.FILE_NAME, "AAA.dat");
-        // Trigger second event which should find the EnrichData file
-        template.sendBodyAndHeader(fileUri("enrich"), "Event2", 
Exchange.FILE_NAME,
-                "Event2.txt");
-        log.info("... write done");
 
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(1, TimeUnit.SECONDS).untilAsserted(() -> {
+            template.sendBodyAndHeader(fileUri("enrichdata"), "EnrichData",
+                    Exchange.FILE_NAME, "AAA.dat");
+            // Trigger second event which should find the EnrichData file
+            template.sendBodyAndHeader(fileUri("enrich"), "Event2", 
Exchange.FILE_NAME,
+                    "Event2.txt");
+            log.info("... write done");
+            assertMockEndpointsSatisfied();
+        });
     }
 
     @Test
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
index 0ae99e7e06a..f163a21905d 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
@@ -16,10 +16,13 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class FileConsumePollEnrichFileTest extends ContextTestSupport {
@@ -37,12 +40,12 @@ public class FileConsumePollEnrichFileTest extends 
ContextTestSupport {
                 "AAA.fin");
 
         log.info("Sleeping for 1/4 sec before writing enrichdata file");
-        Thread.sleep(250);
-        template.sendBodyAndHeader(fileUri("enrichdata"), "Big file",
-                Exchange.FILE_NAME, "AAA.dat");
-        log.info("... write done");
-
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> {
+            template.sendBodyAndHeader(fileUri("enrichdata"), "Big file",
+                    Exchange.FILE_NAME, "AAA.dat");
+            log.info("... write done");
+            assertMockEndpointsSatisfied();
+        });
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentKeyChangedIssue2Test.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentKeyChangedIssue2Test.java
index f9171640590..06b74043130 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentKeyChangedIssue2Test.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentKeyChangedIssue2Test.java
@@ -22,6 +22,7 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 public class FileConsumerIdempotentKeyChangedIssue2Test extends 
ContextTestSupport {
@@ -44,11 +45,10 @@ public class FileConsumerIdempotentKeyChangedIssue2Test 
extends ContextTestSuppo
 
         // wait a bit to allow the consumer to poll once and see a non-changed
         // file
-        Thread.sleep(250);
-
-        template.sendBodyAndHeader(endpoint, "Hello World Again", 
Exchange.FILE_NAME, "hello.txt");
-
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> {
+            template.sendBodyAndHeader(endpoint, "Hello World Again", 
Exchange.FILE_NAME, "hello.txt");
+            assertMockEndpointsSatisfied();
+        });
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
index b0d6bfda2fb..48972e94f35 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentRefTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file;
 
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -24,6 +25,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.IdempotentRepository;
 import org.apache.camel.spi.Registry;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -75,8 +77,9 @@ public class FileConsumerIdempotentRefTest extends 
ContextTestSupport {
         Files.move(testFile("done/report.txt"), testFile("report.txt"));
 
         // should NOT consume the file again, let a bit time go
-        Thread.sleep(100);
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(100, 
TimeUnit.MILLISECONDS).untilAsserted(() -> {
+            assertMockEndpointsSatisfied();
+        });
 
         assertTrue(invoked, "MyIdempotentRepository should have been invoked");
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentTest.java
index 0b580e357ad..cad09f8f29a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIdempotentTest.java
@@ -17,12 +17,14 @@
 package org.apache.camel.component.file;
 
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import 
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -64,8 +66,7 @@ public class FileConsumerIdempotentTest extends 
ContextTestSupport {
 
         // should NOT consume the file again, let a bit time pass to let the
         // consumer try to consume it but it should not
-        Thread.sleep(100);
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(100, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
         FileEndpoint fe = context.getEndpoint(fileUri(), FileEndpoint.class);
         assertNotNull(fe);
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java
index 702425408a3..d84fa3f7e88 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 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;
@@ -65,9 +68,8 @@ public class FileConsumerPollStrategyNotBeginTest extends 
ContextTestSupport {
         oneExchangeDone.matchesWaitTime();
 
         // the poll strategy commit is executed after the exchange is done
-        Thread.sleep(100);
-
-        assertTrue(event.startsWith("beginbegincommit"));
+        Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> 
assertTrue(event.startsWith("beginbegincommit")));
     }
 
     private static class MyPollStrategy implements PollingConsumerPollStrategy 
{
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilePollingConsumerTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilePollingConsumerTest.java
index e90479550d2..b18706b7cd8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilePollingConsumerTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilePollingConsumerTest.java
@@ -17,10 +17,13 @@
 package org.apache.camel.component.file;
 
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.PollingConsumer;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -45,16 +48,13 @@ public class FilePollingConsumerTest extends 
ContextTestSupport {
 
         // sleep a bit to ensure polling consumer would be suspended after we
         // have used it
-        Thread.sleep(500);
-
-        // drop a new file which should not be picked up by the consumer
-        template.sendBodyAndHeader(fileUri(), "Bye World", Exchange.FILE_NAME, 
"bye.txt");
+        Awaitility.await().pollDelay(500, 
TimeUnit.MILLISECONDS).untilAsserted(() -> Assertions
+                .assertDoesNotThrow(() -> 
template.sendBodyAndHeader(fileUri(), "Bye World", Exchange.FILE_NAME, 
"bye.txt")));
 
         // sleep a bit to ensure polling consumer would not have picked up that
         // file
-        Thread.sleep(1000);
-
-        assertTrue(Files.exists(testFile("bye.txt")), "File should exist 
bye.txt");
+        Awaitility.await().pollDelay(1000, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> 
assertTrue(Files.exists(testFile("bye.txt")), "File should exist bye.txt"));
 
         consumer.stop();
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameDeleteTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameDeleteTest.java
index fd302d67f72..b47dee59244 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameDeleteTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameDeleteTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerDoneFileNameDeleteTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(50);
+        Awaitility.await().pollDelay(50, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java
index e966115aaa9..8785caee781 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNamePrefixTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerDoneFileNamePrefixTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java
index 0145633d52b..12f53b40d65 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSimplePrefixTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerDoneFileNameSimplePrefixTest 
extends ContextTestSuppor
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java
index 390b7a0b0dc..c403e8ad1a5 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameSuffixTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerDoneFileNameSuffixTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java
index 7cc4ab1aae1..5cec1dd9a14 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDoneFileNameTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerDoneFileNameTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there is no
         // done file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java
index 3c9aa4664f3..ba479c531b3 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerDualDoneFileNameTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -47,9 +50,7 @@ public class FilerConsumerDualDoneFileNameTest extends 
ContextTestSupport {
         template.sendBodyAndHeader(fileUri(), "Bye World", Exchange.FILE_NAME, 
"bye.txt");
 
         // give chance to poll 2nd file but it lacks the done file
-        Thread.sleep(250);
-
-        assertMockEndpointsSatisfied();
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java
index 0d467d15eea..a07406dade9 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerPreMoveDoneFileNameTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -34,9 +37,8 @@ public class FilerConsumerPreMoveDoneFileNameTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java
index 6df1c79ebbd..0523f773c67 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFilePrefixTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -35,9 +38,8 @@ public class FilerConsumerShouldSkipDoneFilePrefixTest 
extends ContextTestSuppor
 
         // wait a bit and it should not pickup the written file as there are no
         // target file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
index f62b1306247..785577d0ab8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -35,9 +38,8 @@ public class FilerConsumerShouldSkipDoneFileSuffixTest 
extends ContextTestSuppor
 
         // wait a bit and it should not pickup the written file as there are no
         // target file
-        Thread.sleep(100);
+        Awaitility.await().pollDelay(100, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java
index eb7c03acc60..8cd9d747236 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -35,9 +38,8 @@ public class FilerConsumerShouldSkipDoneFileTest extends 
ContextTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // target file
-        Thread.sleep(250);
+        Awaitility.await().pollDelay(250, 
TimeUnit.MILLISECONDS).untilAsserted(() -> assertMockEndpointsSatisfied());
 
-        assertMockEndpointsSatisfied();
         resetMocks();
         oneExchangeDone.reset();
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyFactoryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyFactoryTest.java
index 87589ad79cf..4e1ea3124ce 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyFactoryTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyFactoryTest.java
@@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 import org.slf4j.Logger;
@@ -93,7 +95,9 @@ public final class FileLockClusteredRoutePolicyFactoryTest {
 
             // Start the context after some random time so the startup order
             // changes for each test.
-            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            
Awaitility.await().pollDelay(ThreadLocalRandom.current().nextInt(500), 
TimeUnit.MILLISECONDS)
+                    .untilAsserted(() -> 
Assertions.assertDoesNotThrow(context::start));
+
             context.start();
 
             contextLatch.await(10, TimeUnit.SECONDS);
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyTest.java
index 09950d99189..aa912b77734 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/cluster/FileLockClusteredRoutePolicyTest.java
@@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.cluster.ClusteredRoutePolicy;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 import org.slf4j.Logger;
@@ -93,7 +95,9 @@ public final class FileLockClusteredRoutePolicyTest {
 
             // Start the context after some random time so the startup order
             // changes for each test.
-            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            
Awaitility.await().pollDelay(ThreadLocalRandom.current().nextInt(500), 
TimeUnit.MILLISECONDS)
+                    .untilAsserted(() -> 
Assertions.assertDoesNotThrow(context::start));
+
             context.start();
 
             contextLatch.await();

Reply via email to