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 8fd7ba65d26 (chores) camel-core: fixed timing issue causing test
flakiness
8fd7ba65d26 is described below
commit 8fd7ba65d26234fa04ff4c23d60e6750c11b4de9
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Mon Jul 15 16:38:55 2024 +0200
(chores) camel-core: fixed timing issue causing test flakiness
---
.../file/FileExclusiveReadLockCopyTest.java | 24 ++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileExclusiveReadLockCopyTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileExclusiveReadLockCopyTest.java
index e6ca4c7fb3a..80e51015a59 100644
---
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileExclusiveReadLockCopyTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileExclusiveReadLockCopyTest.java
@@ -16,10 +16,15 @@
*/
package org.apache.camel.component.file;
+import java.io.File;
+import java.nio.file.Path;
+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;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
@@ -27,24 +32,39 @@ import org.junit.jupiter.api.condition.OS;
public class FileExclusiveReadLockCopyTest extends ContextTestSupport {
public static final String FILE_QUERY =
"?readLock=fileLock&initialDelay=0&delay=10";
+ private static final String DEST =
FileExclusiveReadLockCopyTest.class.getSimpleName();
@Test
@DisabledOnOs(OS.WINDOWS)
public void testCopy() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
- mock.expectedFileExists(testFile("out/hello.txt"), "Hello World");
+
+ final Path path = testFile(DEST + File.separator + "hello.txt");
+ mock.expectedFileExists(path, "Hello World");
template.sendBodyAndHeader(fileUri(FILE_QUERY), "Hello World",
Exchange.FILE_NAME, "hello.txt");
+ // The file may have been created, but not yet flushed.
+ Awaitility.await()
+ .atMost(10, TimeUnit.SECONDS).until(this::isFlushed);
+
mock.assertIsSatisfied();
}
+ private boolean isFlushed() {
+ final Path path = testFile(DEST + File.separator + "hello.txt");
+
+ return path.toFile().exists() && "Hello World".length() ==
path.toFile().length();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from(fileUri(FILE_QUERY)).to(fileUri("out")).to("mock:result");
+ from(fileUri(FILE_QUERY))
+ .to(fileUri(DEST))
+ .to("mock:result");
}
};
}