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

gnodet 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 e4878810af67 CAMEL-23893: Fix flaky 
SpringFileWatcherTest.testDefaultConfig on JDK 25
e4878810af67 is described below

commit e4878810af67a75b75250e096feaf71d89a7433d
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Jul 3 17:53:14 2026 +0200

    CAMEL-23893: Fix flaky SpringFileWatcherTest.testDefaultConfig on JDK 25
    
    On JDK 25, the WatchService initializes faster and delivers CREATE
    events from file creation in @BeforeEach, causing testDefaultConfig to
    receive 3 events (1 CREATE + 2 MODIFY) instead of the expected 2.
    
    - Use expectedMinimumMessageCount(2) instead of exact count to tolerate
      CREATE events from @BeforeEach file creation on JDK 25+
    - Replace Thread.sleep(50) with Awaitility to wait for the watcher to
      process and hash the first write before the second one
    - Increase result wait time from 1s to 2s for CI robustness
    
    Closes #24403
---
 .../file/watch/SpringFileWatcherTest.java          | 25 +++++++++++++---------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/SpringFileWatcherTest.java
 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/SpringFileWatcherTest.java
index 46fecb2bd0be..4560e84e0616 100644
--- 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/SpringFileWatcherTest.java
+++ 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/SpringFileWatcherTest.java
@@ -21,9 +21,11 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.spring.junit6.CamelSpringTestSupport;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -47,29 +49,32 @@ public class SpringFileWatcherTest extends 
CamelSpringTestSupport {
     @Test
     public void testDefaultConfig() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:springTest");
-        mock.setExpectedCount(2); // two MODIFY events
-        mock.setResultWaitTime(1000);
+        // Use minimum count to tolerate CREATE events from file creation in 
@BeforeEach,
+        // which may be delivered on JDK 25+ due to faster WatchService 
initialization
+        mock.expectedMinimumMessageCount(2);
+        mock.setResultWaitTime(2000);
 
         Files.write(springTestFile.toPath(), "modification".getBytes(), 
StandardOpenOption.SYNC);
-        // Adding few millis to avoid flaky tests
-        // The file hasher could sometimes evaluate these two changes as 
duplicate, as the second modification of file could be done before hashing is 
done
-        Thread.sleep(50);
+        // Wait for the watcher to process and hash the first write before the 
second one,
+        // so the file hasher can distinguish the two modifications as 
separate events
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .until(() -> mock.getReceivedCounter() >= 1);
         Files.write(springTestFile.toPath(), "modification 2".getBytes(), 
StandardOpenOption.SYNC);
 
         mock.assertIsSatisfied();
-
     }
 
     @Test
     public void testCustomHasher() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:springTestCustomHasher");
         mock.setExpectedCount(1); // We passed dummy TestHasher which returns 
constant hashcode. This should cause, that second MODIFY event is discarded
-        mock.setResultWaitTime(1000);
+        mock.setResultWaitTime(2000);
 
         Files.write(springTestCustomHasherFile.toPath(), "first 
modification".getBytes(), StandardOpenOption.SYNC);
-        // Adding few millis to avoid flaky tests
-        // The file hasher could sometimes evaluate these two changes as 
duplicate, as the second modification of file could be done before hashing is 
done
-        Thread.sleep(50);
+        // Wait for the watcher to process and hash the first write before the 
second one,
+        // so the file hasher evaluates them as separate events (deduplicating 
via constant hash)
+        Awaitility.await().atMost(5, TimeUnit.SECONDS)
+                .until(() -> mock.getReceivedCounter() >= 1);
         Files.write(springTestCustomHasherFile.toPath(), "second 
modification".getBytes(), StandardOpenOption.SYNC);
 
         mock.assertIsSatisfied();

Reply via email to