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 f5c8d58  (chores) camel-ftp: replace some Thread.sleep calls with 
awaitility
f5c8d58 is described below

commit f5c8d589785850ba67f6c54556a230533f20b7ac
Author: Otavio Rodolfo Piske <opi...@redhat.com>
AuthorDate: Mon Oct 18 18:40:19 2021 +0200

    (chores) camel-ftp: replace some Thread.sleep calls with awaitility
---
 components/camel-ftp/pom.xml                       |  5 ++++
 .../FromFileToFtpDefaultRootRenameStrategyIT.java  |  9 +++----
 .../remote/integration/FromFtpAsyncProcessIT.java  | 30 +++++++++++----------
 .../remote/integration/FromFtpDeleteFileIT.java    |  7 ++---
 .../FromFtpDoNotDeleteFileIfProcessFailsIT.java    |  7 ++---
 .../file/remote/integration/FromFtpNoFilesIT.java  |  8 +++---
 .../remote/integration/FromFtpPreMoveDeleteIT.java |  6 +++--
 .../remote/integration/FromFtpPreMoveNoopIT.java   |  6 +++--
 .../integration/FromFtpSedaDeleteFileIT.java       |  7 ++---
 .../FromFtpSimulateNetworkIssueRecoverIT.java      |  8 +++---
 .../remote/integration/FromFtpThirdPoolOkIT.java   |  7 ++---
 .../remote/integration/FromFtpUseListFalseIT.java  |  9 ++++---
 .../integration/FtpBadLoginConnectionLeakIT.java   |  4 ++-
 .../FtpBadLoginMockNoopConnectionLeakIT.java       |  4 ++-
 .../integration/FtpConsumerDisconnectIT.java       |  9 ++++---
 .../FtpConsumerDoneFileNameFixedIT.java            | 13 +++++----
 .../integration/FtpConsumerDoneFileNameIT.java     | 10 +++----
 .../integration/FtpConsumerDualDoneFileNameIT.java |  6 ++---
 ...ConsumerLocalWorkDirectoryAsAbsolutePathIT.java |  7 ++---
 .../integration/FtpConsumerMoveExpressionIT.java   |  7 ++---
 .../FtpConsumerPostProcessingOnDisconnectIT.java   |  5 ++--
 .../integration/FtpConsumerRelativeFileNameIT.java | 17 +++++++-----
 .../remote/integration/FtpConsumerTemplateIT.java  | 16 +++++------
 .../FtpConsumerThrowExceptionOnLoginFailedIT.java  |  6 ++---
 ...PollEnrichConsumeWithDisconnectAndDeleteIT.java | 26 ++++--------------
 .../remote/integration/FtpPollingConsumerIT.java   |  7 ++---
 .../FtpProducerDisconnectOnBatchCompleteIT.java    |  8 ++++--
 .../FtpProducerTempFileExistIssueIT.java           | 25 +++++++----------
 .../FtpSimpleConsumeStreamingPartialReadIT.java    |  6 ++---
 .../remote/integration/FtpStreamingMoveIT.java     |  7 ++---
 ...PollEnrichConsumeWithDisconnectAndDeleteIT.java | 31 ++++------------------
 .../sftp/integration/SftpConsumerDisconnectIT.java |  7 ++---
 .../sftp/integration/SftpFromSedaDeleteFileIT.java |  7 ++---
 .../SftpSimpleConsumeStreamingPartialReadIT.java   |  6 ++---
 34 files changed, 171 insertions(+), 172 deletions(-)

diff --git a/components/camel-ftp/pom.xml b/components/camel-ftp/pom.xml
index def2508..cd43779 100644
--- a/components/camel-ftp/pom.xml
+++ b/components/camel-ftp/pom.xml
@@ -99,6 +99,11 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <!-- for unit testing AntPathMatcher -->
         <dependency>
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
index c0c5435..66600ae 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -27,6 +28,8 @@ import org.apache.camel.converter.IOConverter;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.*;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FromFileToFtpDefaultRootRenameStrategyIT extends 
FtpServerTestSupport {
@@ -67,11 +70,7 @@ public class FromFileToFtpDefaultRootRenameStrategyIT 
extends FtpServerTestSuppo
 
         assertMockEndpointsSatisfied();
 
-        // give our mock a chance to delete the file
-        Thread.sleep(250);
-
-        // assert the file is NOT there now
-        assertTrue(!expectedOnFtpServer.exists());
+        await().atMost(250, TimeUnit.MILLISECONDS).untilAsserted(() -> 
assertFalse(expectedOnFtpServer.exists()));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpAsyncProcessIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpAsyncProcessIT.java
index 1cd1328..47621a6 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpAsyncProcessIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpAsyncProcessIT.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.file.remote.integration;
 import java.io.File;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
@@ -26,6 +27,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.support.AsyncProcessorSupport;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 /**
@@ -56,13 +58,15 @@ public class FromFtpAsyncProcessIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time for files to be deleted on ftp server
-        Thread.sleep(1000);
 
         File hello = ftpFile("async/hello.txt").toFile();
-        assertFalse(hello.exists(), "File should not exist " + hello);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(hello.exists(), "File should 
not exist " + hello));
 
         File bye = ftpFile("async/bye.txt").toFile();
-        assertFalse(bye.exists(), "File should not exist " + bye);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(bye.exists(), "File should 
not exist " + bye));
+
     }
 
     @Override
@@ -80,18 +84,16 @@ public class FromFtpAsyncProcessIT extends 
FtpServerTestSupport {
 
         @Override
         public boolean process(final Exchange exchange, final AsyncCallback 
callback) {
-            executor.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException e) {
-                        // ignore
-                    }
-
-                    exchange.getIn().setHeader("foo", 123);
-                    callback.done(false);
+            executor.submit(() -> {
+
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    // ignore
                 }
+
+                exchange.getIn().setHeader("foo", 123);
+                callback.done(false);
             });
 
             return false;
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDeleteFileIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDeleteFileIT.java
index c0142e0..149e554 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDeleteFileIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDeleteFileIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -26,6 +27,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -53,11 +55,10 @@ public class FromFtpDeleteFileIT extends 
FtpServerTestSupport {
 
         mock.assertIsSatisfied();
 
-        Thread.sleep(500);
-
         // assert the file is deleted
         File file = ftpFile("deletefile/hello.txt").toFile();
-        assertFalse(file.exists(), "The file should have been deleted");
+        await().atMost(500, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDoNotDeleteFileIfProcessFailsIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDoNotDeleteFileIfProcessFailsIT.java
index 701cdc7..ab0290c 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDoNotDeleteFileIfProcessFailsIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDoNotDeleteFileIfProcessFailsIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -27,6 +28,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FromFtpDoNotDeleteFileIfProcessFailsIT extends 
FtpServerTestSupport {
@@ -51,11 +53,10 @@ public class FromFtpDoNotDeleteFileIfProcessFailsIT extends 
FtpServerTestSupport
         mock.assertIsSatisfied();
 
         // give time to NOT delete file
-        Thread.sleep(200);
-
         // assert the file is deleted
         File file = ftpFile("deletefile/hello.txt").toFile();
-        assertTrue(file.exists(), "The file should NOT have been deleted");
+        await().atMost(200, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "The file 
should NOT have been deleted"));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpNoFilesIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpNoFilesIT.java
index c4335c8..175d823 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpNoFilesIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpNoFilesIT.java
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.createDirectory;
 import static org.apache.camel.test.junit5.TestSupport.deleteDirectory;
+import static org.awaitility.Awaitility.await;
 
 /**
  * Unit test to verify polling a server with no files to poll.
@@ -39,9 +42,8 @@ public class FromFtpNoFilesIT extends FtpServerTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(0);
 
-        Thread.sleep(3 * 1000L);
-
-        mock.assertIsSatisfied();
+        await().atMost(3, TimeUnit.SECONDS)
+                .untilAsserted(() -> mock.assertIsSatisfied());
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveDeleteIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveDeleteIT.java
index a127a4c..7826af0 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveDeleteIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveDeleteIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -27,6 +28,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -55,9 +57,9 @@ public class FromFtpPreMoveDeleteIT extends 
FtpServerTestSupport {
         mock.assertIsSatisfied();
 
         // and file should be deleted
-        Thread.sleep(1000);
         File file = ftpFile("movefile/work/hello.txt").toFile();
-        assertFalse(file.exists(), "The file should have been deleted");
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveNoopIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveNoopIT.java
index ed997c7..d759b72 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveNoopIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpPreMoveNoopIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -27,6 +28,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
@@ -54,9 +56,9 @@ public class FromFtpPreMoveNoopIT extends 
FtpServerTestSupport {
         mock.assertIsSatisfied();
 
         // and file should be kept there
-        Thread.sleep(1000);
         File file = ftpFile("movefile/work/hello.txt").toFile();
-        assertTrue(file.exists(), "The file should exists");
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "The file 
should exists"));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSedaDeleteFileIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSedaDeleteFileIT.java
index 44fae13..e1d6a33 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSedaDeleteFileIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSedaDeleteFileIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -26,6 +27,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -46,11 +48,10 @@ public class FromFtpSedaDeleteFileIT extends 
FtpServerTestSupport {
 
         mock.assertIsSatisfied();
 
-        Thread.sleep(500);
-
         // assert the file is deleted
         File file = ftpFile("deletefile/hello.txt").toFile();
-        assertFalse(file.exists(), "The file should have been deleted");
+        await().atMost(500, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     @BeforeEach
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSimulateNetworkIssueRecoverIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSimulateNetworkIssueRecoverIT.java
index a484553..f0411e2 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSimulateNetworkIssueRecoverIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSimulateNetworkIssueRecoverIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
@@ -24,6 +26,7 @@ import 
org.apache.camel.component.file.remote.RemoteFilePollingConsumerPollStrat
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -52,9 +55,8 @@ public class FromFtpSimulateNetworkIssueRecoverIT extends 
FtpServerTestSupport {
 
         resultEndpoint.assertIsSatisfied();
 
-        Thread.sleep(2000);
-
-        assertTrue(counter >= 3, "Should have tried at least 3 times was " + 
counter);
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(counter >= 3, "Should have 
tried at least 3 times was " + counter));
         assertEquals(2, rollback);
     }
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
index c22a573..77e0d7f 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
@@ -17,12 +17,14 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -47,9 +49,8 @@ public class FromFtpThirdPoolOkIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time to delete file
-        Thread.sleep(200);
-
-        assertEquals(3, counter);
+        await().atMost(200, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertEquals(3, counter));
 
         // assert the file is deleted
         File file = ftpFile("thirdpool/hello.txt").toFile();
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpUseListFalseIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpUseListFalseIT.java
index 0491fc6..37ec64a 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpUseListFalseIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpUseListFalseIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Producer;
@@ -24,6 +26,8 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Unit test to poll a fixed file from the FTP server without using the list 
command.
  */
@@ -57,9 +61,8 @@ public class FromFtpUseListFalseIT extends 
FtpServerTestSupport {
 
         // just allow to poll a few more times, but we should only get the file
         // once
-        Thread.sleep(1000);
-
-        mock.assertIsSatisfied();
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> mock.assertIsSatisfied());
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginConnectionLeakIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginConnectionLeakIT.java
index 7070138..1d0689a 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginConnectionLeakIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginConnectionLeakIT.java
@@ -22,6 +22,7 @@ import java.net.Socket;
 import java.net.SocketAddress;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.net.SocketFactory;
 
@@ -30,6 +31,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -54,7 +56,7 @@ public class FtpBadLoginConnectionLeakIT extends 
FtpServerTestSupport {
         mock.expectedMessageCount(0);
 
         // let's have several login attempts
-        Thread.sleep(3000L);
+        await().atMost(3, TimeUnit.SECONDS).until(() -> socketAudits.size() > 
0);
 
         stopCamelContext();
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginMockNoopConnectionLeakIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginMockNoopConnectionLeakIT.java
index d374273..fd7ecb4 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginMockNoopConnectionLeakIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpBadLoginMockNoopConnectionLeakIT.java
@@ -22,6 +22,7 @@ import java.net.Socket;
 import java.net.SocketAddress;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.net.SocketFactory;
 
@@ -35,6 +36,7 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -79,7 +81,7 @@ public class FtpBadLoginMockNoopConnectionLeakIT extends 
FtpServerTestSupport {
         mock.expectedMessageCount(0);
 
         // let's have several login attempts
-        Thread.sleep(3000L);
+        await().atMost(3, TimeUnit.SECONDS).until(() -> socketAudits.size() > 
0);
 
         stopCamelContext();
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDisconnectIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDisconnectIT.java
index c26ce51..f4411d8 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDisconnectIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDisconnectIT.java
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.file.remote.FtpEndpoint;
 import org.apache.commons.net.ftp.FTPClient;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -64,10 +67,10 @@ public class FtpConsumerDisconnectIT extends 
FtpServerTestSupport {
         // enough to avoid a second poll cycle before we are done with the
         // asserts
         // below inside the main thread
-        Thread.sleep(2000);
-
         FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl(), 
FtpEndpoint.class);
-        assertFalse(endpoint.getFtpClient().isConnected(), "The FTPClient 
should be already disconnected");
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> 
assertFalse(endpoint.getFtpClient().isConnected(),
+                        "The FTPClient should be already disconnected"));
         assertTrue(endpoint.isDisconnect(), "The FtpEndpoint should be 
configured to disconnect");
     }
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameFixedIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameFixedIT.java
index fd9a6d7..c424198 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameFixedIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameFixedIT.java
@@ -17,11 +17,13 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 public class FtpConsumerDoneFileNameFixedIT extends FtpServerTestSupport {
@@ -38,9 +40,7 @@ public class FtpConsumerDoneFileNameFixedIT extends 
FtpServerTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(1000);
-
-        assertMockEndpointsSatisfied();
+        await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> 
assertMockEndpointsSatisfied());
 
         resetMocks();
 
@@ -52,11 +52,10 @@ public class FtpConsumerDoneFileNameFixedIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time for done file to be deleted
-        Thread.sleep(1000);
-
-        // done file should be deleted now
         File file = new File(service.getFtpRootDir() + "done/fin.dat");
-        assertFalse(file.exists(), "Done file should be deleted: " + file);
+        // done file should be deleted now
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "Done file 
should be deleted: " + file));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameIT.java
index ad468ba..8d6eb62 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDoneFileNameIT.java
@@ -17,11 +17,13 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 public class FtpConsumerDoneFileNameIT extends FtpServerTestSupport {
@@ -38,9 +40,8 @@ public class FtpConsumerDoneFileNameIT extends 
FtpServerTestSupport {
 
         // wait a bit and it should not pickup the written file as there are no
         // done file
-        Thread.sleep(1000);
 
-        assertMockEndpointsSatisfied();
+        assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
 
         resetMocks();
 
@@ -52,11 +53,10 @@ public class FtpConsumerDoneFileNameIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time for done file to be deleted
-        Thread.sleep(1000);
-
         // done file should be deleted now
         File file = new File(service.getFtpRootDir() + "done/hello.dat");
-        assertFalse(file.exists(), "Done file should be deleted: " + file);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "Done file 
should be deleted: " + file));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDualDoneFileNameIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDualDoneFileNameIT.java
index d543422..7488b69 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDualDoneFileNameIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerDualDoneFileNameIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
@@ -47,9 +49,7 @@ public class FtpConsumerDualDoneFileNameIT extends 
FtpServerTestSupport {
         template.sendBodyAndHeader(getFtpUrl(), "Bye World", 
Exchange.FILE_NAME, "bye.txt");
 
         // give chance to poll 2nd file but it lacks the done file
-        Thread.sleep(1000);
-
-        assertMockEndpointsSatisfied();
+        assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerLocalWorkDirectoryAsAbsolutePathIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerLocalWorkDirectoryAsAbsolutePathIT.java
index 4b2aa4e..4843208 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerLocalWorkDirectoryAsAbsolutePathIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerLocalWorkDirectoryAsAbsolutePathIT.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
 import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -31,6 +32,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertFileExists;
 import static org.apache.camel.test.junit5.TestSupport.assertFileNotExists;
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -61,10 +63,9 @@ public class FtpConsumerLocalWorkDirectoryAsAbsolutePathIT 
extends FtpServerTest
         assertMockEndpointsSatisfied();
 
         // give test some time to close file resources
-        Thread.sleep(6000);
-
         // now the lwd file should be deleted
-        assertFileNotExists(base.resolve("hello.txt"));
+        await().atMost(6, TimeUnit.SECONDS)
+                .untilAsserted(() -> 
assertFileNotExists(base.resolve("hello.txt")));
 
         // and the out file should exists
         assertFileExists(testFile("out/hello.txt"), "Hello World");
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerMoveExpressionIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerMoveExpressionIT.java
index b3d8468..70149b9 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerMoveExpressionIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerMoveExpressionIT.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
@@ -25,6 +26,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertFileExists;
+import static org.awaitility.Awaitility.await;
 
 /**
  * Unit test for FTP using expression (file language)
@@ -48,10 +50,9 @@ public class FtpConsumerMoveExpressionIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time for consumer to rename file
-        Thread.sleep(1000);
-
         String now = new SimpleDateFormat("yyyyMMdd").format(new Date());
-        assertFileExists(ftpFile("filelanguage/backup/" + now + 
"/123-report2.bak"));
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> 
assertFileExists(ftpFile("filelanguage/backup/" + now + "/123-report2.bak")));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerPostProcessingOnDisconnectIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerPostProcessingOnDisconnectIT.java
index 24e48d5..bcefc1d 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerPostProcessingOnDisconnectIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerPostProcessingOnDisconnectIT.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.io.IOException;
 import java.nio.file.Files;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -26,6 +27,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertFileNotExists;
+import static org.awaitility.Awaitility.await;
 
 public class FtpConsumerPostProcessingOnDisconnectIT extends 
FtpServerTestSupport {
     private static final String SAMPLE_FILE_NAME_1 = 
String.format("sample-1-%s.txt",
@@ -51,8 +53,7 @@ public class FtpConsumerPostProcessingOnDisconnectIT extends 
FtpServerTestSuppor
         assertMockEndpointsSatisfied();
 
         // File is deleted
-        Thread.sleep(250);
-        assertFileNotExists(ftpFile(SAMPLE_FILE_NAME_1));
+        await().atMost(250, TimeUnit.MILLISECONDS).untilAsserted(() -> 
assertFileNotExists(ftpFile(SAMPLE_FILE_NAME_1)));
     }
 
     @Test
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerRelativeFileNameIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerRelativeFileNameIT.java
index 12502d3..967c847 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerRelativeFileNameIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerRelativeFileNameIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -23,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertDirectoryEquals;
+import static org.awaitility.Awaitility.await;
 
 public class FtpConsumerRelativeFileNameIT extends FtpServerTestSupport {
 
@@ -59,13 +62,15 @@ public class FtpConsumerRelativeFileNameIT extends 
FtpServerTestSupport {
         assertMockEndpointsSatisfied();
 
         // give time for ftp consumer to disconnect
-        Thread.sleep(2000);
-
         // and expect name to contain target/filename-consumer-XXX.txt
-        assertDirectoryEquals("out/filename-consumer-bye.txt",
-                
mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_NAME, 
String.class));
-        assertDirectoryEquals("out/filename-consumer-hello.txt",
-                
mock.getReceivedExchanges().get(1).getIn().getHeader(Exchange.FILE_NAME, 
String.class));
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> isExpectedFile(mock, 
"out/filename-consumer-bye.txt", 0));
+        isExpectedFile(mock, "out/filename-consumer-hello.txt", 1);
+    }
+
+    private void isExpectedFile(MockEndpoint mock, String s, int 
exchangeNumber) {
+        assertDirectoryEquals(s,
+                
mock.getReceivedExchanges().get(exchangeNumber).getIn().getHeader(Exchange.FILE_NAME,
 String.class));
     }
 
 }
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerTemplateIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerTemplateIT.java
index 6011377..9f6c9fd 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerTemplateIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerTemplateIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -24,6 +25,7 @@ import org.apache.camel.Producer;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -52,8 +54,6 @@ public class FtpConsumerTemplateIT extends 
FtpServerTestSupport {
         // must done when we are done using the exchange
         consumer.doneUoW(exchange);
 
-        Thread.sleep(500);
-
         // poll the same file again
         exchange = consumer.receive(getFtpUrl(), 5000);
         assertNotNull(exchange);
@@ -63,10 +63,10 @@ public class FtpConsumerTemplateIT extends 
FtpServerTestSupport {
         // must done when we are done using the exchange
         consumer.doneUoW(exchange);
 
-        // file should still exists
-        Thread.sleep(500);
+        // file should still exist
         File file = ftpFile("template/hello.txt").toFile();
-        assertTrue(file.exists(), "The file should exist: " + file);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "The file 
should exist: " + file));
     }
 
     @Test
@@ -78,8 +78,6 @@ public class FtpConsumerTemplateIT extends 
FtpServerTestSupport {
 
         // forget to call done
 
-        Thread.sleep(500);
-
         // try poll the same file again
         Exchange exchange2 = consumer.receive(getFtpUrl(), 2000);
         assertNull(exchange2);
@@ -95,9 +93,9 @@ public class FtpConsumerTemplateIT extends 
FtpServerTestSupport {
         consumer.doneUoW(exchange2);
 
         // file should still exists
-        Thread.sleep(500);
         File file = ftpFile("template/hello.txt").toFile();
-        assertTrue(file.exists(), "The file should exist: " + file);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "The file 
should exist: " + file));
     }
 
     private void prepareFtpServer() throws Exception {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerThrowExceptionOnLoginFailedIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerThrowExceptionOnLoginFailedIT.java
index 67e7a2f..57456db 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerThrowExceptionOnLoginFailedIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpConsumerThrowExceptionOnLoginFailedIT.java
@@ -29,6 +29,7 @@ import org.apache.camel.support.service.ServiceSupport;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -56,10 +57,9 @@ public class FtpConsumerThrowExceptionOnLoginFailedIT 
extends FtpServerTestSuppo
         assertMockEndpointsSatisfied();
 
         // consumer should be stopped
-        Thread.sleep(1000);
-
         Consumer consumer = context.getRoute("foo").getConsumer();
-        assertTrue(((ServiceSupport) consumer).isStopped(), "Consumer should 
be stopped");
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(((ServiceSupport) 
consumer).isStopped(), "Consumer should be stopped"));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollEnrichConsumeWithDisconnectAndDeleteIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollEnrichConsumeWithDisconnectAndDeleteIT.java
index 926c8e3..d98701c 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollEnrichConsumeWithDisconnectAndDeleteIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollEnrichConsumeWithDisconnectAndDeleteIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
@@ -26,6 +27,7 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 public class FtpPollEnrichConsumeWithDisconnectAndDeleteIT extends 
FtpServerTestSupport {
@@ -49,27 +51,9 @@ public class FtpPollEnrichConsumeWithDisconnectAndDeleteIT 
extends FtpServerTest
 
         assertMockEndpointsSatisfied();
 
-        long startFileDeletionCheckTime = System.currentTimeMillis();
-        boolean fileExists = true;
-        while (System.currentTimeMillis() - startFileDeletionCheckTime < 3000) 
{ // wait
-                                                                               
 // up
-                                                                               
 // to
-                                                                               
 // 3000ms
-                                                                               
 // for
-                                                                               
 // file
-                                                                               
 // to
-                                                                               
 // be
-                                                                               
 // deleted
-            File file = ftpFile("poll/hello.txt").toFile();
-            fileExists = file.exists();
-
-            if (fileExists) {
-                LOG.info("Will check that file has been deleted again in 
200ms");
-                Thread.sleep(200);
-            }
-        }
-
-        assertFalse(fileExists, "The file should have been deleted");
+        File file = ftpFile("poll/hello.txt").toFile();
+        await().atMost(3, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollingConsumerIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollingConsumerIT.java
index 83e1c5a..90d21b6 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollingConsumerIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpPollingConsumerIT.java
@@ -17,11 +17,13 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.PollingConsumer;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -54,10 +56,9 @@ public class FtpPollingConsumerIT extends 
FtpServerTestSupport {
 
         // sleep a bit to ensure polling consumer would not have picked up that
         // file
-        Thread.sleep(1000);
-
         File file = ftpFile("polling/bye.txt").toFile();
-        assertTrue(file.exists(), "File should exist " + file);
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "File should 
exist " + file));
 
         consumer.stop();
     }
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerDisconnectOnBatchCompleteIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerDisconnectOnBatchCompleteIT.java
index 750307b..7487eda 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerDisconnectOnBatchCompleteIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerDisconnectOnBatchCompleteIT.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote.integration;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.remote.FtpEndpoint;
@@ -24,6 +26,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.language.simple.SimpleLanguage.simple;
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -48,9 +51,10 @@ public class FtpProducerDisconnectOnBatchCompleteIT extends 
FtpServerTestSupport
     public void testDisconnectOnBatchComplete() throws Exception {
         sendFile(getFtpUrl(), "Hello World", "claus.txt");
 
-        Thread.sleep(2000);
         FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl(), 
FtpEndpoint.class);
-        assertFalse(endpoint.getFtpClient().isConnected(), "The FTPClient 
should be already disconnected");
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> 
assertFalse(endpoint.getFtpClient().isConnected(),
+                        "The FTPClient should be already disconnected"));
         assertTrue(endpoint.isDisconnectOnBatchComplete(), "The FtpEndpoint 
should be configured to disconnect");
     }
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerTempFileExistIssueIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerTempFileExistIssueIT.java
index ae928aa..5377f31 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerTempFileExistIssueIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpProducerTempFileExistIssueIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Endpoint;
@@ -25,6 +26,7 @@ import 
org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -53,10 +55,8 @@ public class FtpProducerTempFileExistIssueIT extends 
FtpServerTestSupport {
 
         template.sendBodyAndHeader(getFtpUrl() + "&tempPrefix=foo", "Bye 
World", Exchange.FILE_NAME, "hello.txt");
 
-        Thread.sleep(500);
-
         File file = ftpFile("tempprefix/hello.txt").toFile();
-        assertEquals(true, file.exists());
+        await().atMost(500, TimeUnit.MILLISECONDS).untilAsserted(() -> 
assertEquals(true, file.exists()));
         assertEquals("Bye World", 
context.getTypeConverter().convertTo(String.class, file));
     }
 
@@ -69,10 +69,8 @@ public class FtpProducerTempFileExistIssueIT extends 
FtpServerTestSupport {
 
         template.sendBodyAndHeader(getFtpUrl() + "&tempPrefix=foo", "Bye 
World", Exchange.FILE_NAME, "hello.txt");
 
-        Thread.sleep(500);
-
         File file = ftpFile("tempprefix/hello.txt").toFile();
-        assertEquals(true, file.exists());
+        await().atMost(500, TimeUnit.MILLISECONDS).untilAsserted(() -> 
assertEquals(true, file.exists()));
         assertEquals("Bye World", 
context.getTypeConverter().convertTo(String.class, file));
     }
 
@@ -85,10 +83,9 @@ public class FtpProducerTempFileExistIssueIT extends 
FtpServerTestSupport {
         template.sendBodyAndHeader(getFtpUrl() + 
"&tempPrefix=foo&fileExist=Override", "Bye World", Exchange.FILE_NAME,
                 "hello.txt");
 
-        Thread.sleep(500);
-
         File file = ftpFile("tempprefix/hello.txt").toFile();
-        assertEquals(true, file.exists());
+        await().atMost(500, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertEquals(true, file.exists()));
         assertEquals("Bye World", 
context.getTypeConverter().convertTo(String.class, file));
     }
 
@@ -101,11 +98,10 @@ public class FtpProducerTempFileExistIssueIT extends 
FtpServerTestSupport {
         template.sendBodyAndHeader(getFtpUrl() + 
"&tempPrefix=foo&fileExist=Ignore", "Bye World", Exchange.FILE_NAME,
                 "hello.txt");
 
-        Thread.sleep(500);
-
         File file = ftpFile("tempprefix/hello.txt").toFile();
         // should not write new file as we should ignore
-        assertEquals("Hello World", 
context.getTypeConverter().convertTo(String.class, file));
+        await().atMost(500, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertEquals("Hello World", 
context.getTypeConverter().convertTo(String.class, file)));
     }
 
     @Test
@@ -122,10 +118,9 @@ public class FtpProducerTempFileExistIssueIT extends 
FtpServerTestSupport {
                 = 
assertIsInstanceOf(GenericFileOperationFailedException.class, ex.getCause());
         assertTrue(cause.getMessage().startsWith("File already exist"));
 
-        Thread.sleep(500);
-
         File file = ftpFile("tempprefix/hello.txt").toFile();
         // should not write new file as we should ignore
-        assertEquals("Hello World", 
context.getTypeConverter().convertTo(String.class, file));
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertEquals("Hello World", 
context.getTypeConverter().convertTo(String.class, file)));
     }
 }
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingPartialReadIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingPartialReadIT.java
index 391eee3..e862594 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingPartialReadIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingPartialReadIT.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -26,6 +27,7 @@ import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -52,10 +54,8 @@ public class FtpSimpleConsumeStreamingPartialReadIT extends 
FtpServerTestSupport
         assertTrue(remoteFile1.getBody() instanceof InputStream);
 
         // Wait a little bit for the move to finish.
-        Thread.sleep(2000);
-
         File resultFile = new File(path + File.separator + "failed", 
"hello.txt");
-        assertTrue(resultFile.exists());
+        await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> 
assertTrue(resultFile.exists()));
         assertFalse(resultFile.isDirectory());
     }
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpStreamingMoveIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpStreamingMoveIT.java
index 554bc45..ede299a 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpStreamingMoveIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpStreamingMoveIT.java
@@ -18,12 +18,14 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FtpStreamingMoveIT extends FtpServerTestSupport {
@@ -48,10 +50,9 @@ public class FtpStreamingMoveIT extends FtpServerTestSupport 
{
         assertTrue(remoteFile.getBody() instanceof InputStream);
 
         // give time for consumer to rename file
-        Thread.sleep(1000);
-
         File file = ftpFile("mymove/done/hello.txt").toFile();
-        assertTrue(file.exists(), "File should have been renamed");
+        await().atMost(1, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(file.exists(), "File should 
have been renamed"));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/SftpPollEnrichConsumeWithDisconnectAndDeleteIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/SftpPollEnrichConsumeWithDisconnectAndDeleteIT.java
index b675067..8563170 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/SftpPollEnrichConsumeWithDisconnectAndDeleteIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/SftpPollEnrichConsumeWithDisconnectAndDeleteIT.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
@@ -26,16 +27,12 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.condition.EnabledIf;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 @EnabledIf(value = 
"org.apache.camel.component.file.remote.services.SftpEmbeddedService#hasRequiredAlgorithms")
 public class SftpPollEnrichConsumeWithDisconnectAndDeleteIT extends 
SftpServerTestSupport {
-
-    private static final Logger LOG = 
LoggerFactory.getLogger(SftpPollEnrichConsumeWithDisconnectAndDeleteIT.class);
-
     @Timeout(value = 30)
     @Test
     public void testSftpSimpleConsume() throws Exception {
@@ -54,27 +51,9 @@ public class SftpPollEnrichConsumeWithDisconnectAndDeleteIT 
extends SftpServerTe
 
         assertMockEndpointsSatisfied();
 
-        long startFileDeletionCheckTime = System.currentTimeMillis();
-        boolean fileExists = true;
-        while (System.currentTimeMillis() - startFileDeletionCheckTime < 3000) 
{ // wait
-                                                                               
 // up
-                                                                               
 // to
-                                                                               
 // 3000ms
-                                                                               
 // for
-                                                                               
 // file
-                                                                               
 // to
-                                                                               
 // be
-                                                                               
 // deleted
-            File file = ftpFile("hello.txt").toFile();
-            fileExists = file.exists();
-
-            if (fileExists) {
-                LOG.info("Will check that file has been deleted again in 
200ms");
-                Thread.sleep(200);
-            }
-        }
-
-        assertFalse(fileExists, "The file should have been deleted");
+        File file = ftpFile("hello.txt").toFile();
+        await().atMost(3, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     @Override
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerDisconnectIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerDisconnectIT.java
index bbf3799..bba0d91 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerDisconnectIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerDisconnectIT.java
@@ -18,6 +18,7 @@ package 
org.apache.camel.component.file.remote.sftp.integration;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -27,6 +28,7 @@ import org.apache.commons.io.FileUtils;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 @Disabled
@@ -53,11 +55,10 @@ public class SftpConsumerDisconnectIT extends 
SftpServerTestSupport {
         // Check that expectations are satisfied
         assertMockEndpointsSatisfied();
 
-        Thread.sleep(250);
-
         // File is deleted
         File deletedFile = new File(service.getFtpRootDir() + "/" + 
SAMPLE_FILE_NAME_1);
-        assertFalse(deletedFile.exists(), "File should have been deleted: " + 
deletedFile);
+        await().atMost(250, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertFalse(deletedFile.exists(), "File 
should have been deleted: " + deletedFile));
     }
 
     @Test
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpFromSedaDeleteFileIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpFromSedaDeleteFileIT.java
index af645d4..b8835ca 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpFromSedaDeleteFileIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpFromSedaDeleteFileIT.java
@@ -18,6 +18,7 @@ package 
org.apache.camel.component.file.remote.sftp.integration;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -25,6 +26,7 @@ import org.apache.commons.io.FileUtils;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
 /**
@@ -54,11 +56,10 @@ public class SftpFromSedaDeleteFileIT extends 
SftpServerTestSupport {
 
         mock.assertIsSatisfied();
 
-        Thread.sleep(500);
-
         // assert the file is deleted
         File file = ftpFile("hello.txt").toFile();
-        assertFalse(file.exists(), "The file should have been deleted");
+        await().atMost(500, TimeUnit.MILLISECONDS)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file 
should have been deleted"));
     }
 
     private void createSampleFile() throws IOException {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeStreamingPartialReadIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeStreamingPartialReadIT.java
index 804beb2..387d2d0 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeStreamingPartialReadIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeStreamingPartialReadIT.java
@@ -18,6 +18,7 @@ package 
org.apache.camel.component.file.remote.sftp.integration;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -27,6 +28,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledIf;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -54,10 +56,8 @@ public class SftpSimpleConsumeStreamingPartialReadIT extends 
SftpServerTestSuppo
         assertTrue(remoteFile1.getBody() instanceof InputStream);
 
         // Wait a little bit for the move to finish.
-        Thread.sleep(2000);
-
         File resultFile = new File(service.getFtpRootDir() + File.separator + 
"failed", "hello.txt");
-        assertTrue(resultFile.exists());
+        await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> 
assertTrue(resultFile.exists()));
         assertFalse(resultFile.isDirectory());
     }
 

Reply via email to