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

[camel] branch main updated: (chores) camel-core: file test fixes and cleanups

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new ec2269d7e56 (chores) camel-core: file test fixes and cleanups
ec2269d7e56 is described below

commit ec2269d7e569a15fb83b6580778cdc21da93e613
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jul 14 10:27:19 2023 +0200

    (chores) camel-core: file test fixes and cleanups
    
    - send test kick-off messages earlier
    - increase timeouts
    - replace Thread.sleep with Awaitility
---
 .../file/FileConsumerIdempotentKeyChangedIssue2Test.java  |  2 +-
 .../component/file/FileConsumerSkipDotFilesTest.java      | 15 +++++++++------
 .../file/strategy/FileChangedReadLockZeroTimeoutTest.java |  4 +++-
 3 files changed, 13 insertions(+), 8 deletions(-)

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 1337d7e94ea..4c81def9bd4 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
@@ -44,7 +44,7 @@ public class FileConsumerIdempotentKeyChangedIssue2Test extends ContextTestSuppo
 
         // wait a bit to allow the consumer to poll once and see a non-changed
         // file
-        Thread.sleep(50);
+        Thread.sleep(250);
 
         template.sendBodyAndHeader(endpoint, "Hello World Again", Exchange.FILE_NAME, "hello.txt");
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java
index cbb9304a69f..b78484f1d65 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java
@@ -20,6 +20,7 @@ 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.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -27,7 +28,13 @@ import org.junit.jupiter.api.Test;
  */
 public class FileConsumerSkipDotFilesTest extends ContextTestSupport {
 
-    private String fileUrl = fileUri("?initialDelay=0&delay=10");
+    private final String baseUrl = fileUri();
+    private final String fileUrl = fileUri("?initialDelay=0&delay=10");
+
+    @BeforeEach
+    void sendDotFile() {
+        template.sendBodyAndHeader(baseUrl, "This is a dot file", Exchange.FILE_NAME, ".skipme");
+    }
 
     @Test
     public void testSkipDotFiles() throws Exception {
@@ -35,8 +42,6 @@ public class FileConsumerSkipDotFilesTest extends ContextTestSupport {
         mock.expectedMessageCount(0);
         mock.setResultWaitTime(100);
 
-        template.sendBodyAndHeader(fileUri(), "This is a dot file", Exchange.FILE_NAME, ".skipme");
-
         mock.assertIsSatisfied();
     }
 
@@ -45,9 +50,7 @@ public class FileConsumerSkipDotFilesTest extends ContextTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");
 
-        template.sendBodyAndHeader(fileUri(), "This is a dot file", Exchange.FILE_NAME, ".skipme");
-
-        template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(baseUrl, "Hello World", Exchange.FILE_NAME, "hello.txt");
 
         mock.assertIsSatisfied();
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockZeroTimeoutTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockZeroTimeoutTest.java
index 953a099a31b..9a5e8759156 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockZeroTimeoutTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockZeroTimeoutTest.java
@@ -17,11 +17,13 @@
 package org.apache.camel.component.file.strategy;
 
 import java.nio.file.Files;
+import java.time.Duration;
 
 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 FileChangedReadLockZeroTimeoutTest extends ContextTestSupport {
@@ -34,7 +36,7 @@ public class FileChangedReadLockZeroTimeoutTest extends ContextTestSupport {
 
         template.sendBodyAndHeader(fileUri("in"), "Hello World", Exchange.FILE_NAME, "hello1.txt");
 
-        Thread.sleep(100);
+        Awaitility.await().atMost(Duration.ofSeconds(30)).until(() -> Files.exists(testFile("in/hello1.txt")));
 
         Files.delete(testFile("in/hello1.txt"));