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

ShannonDing pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 79e29dd46c [ISSUE #11608] fix(srvutil): watch configured files that 
are created after startup (#11609)
79e29dd46c is described below

commit 79e29dd46c421ff5ee6269e9d473b0bee52bc632
Author: zjt0926 <[email protected]>
AuthorDate: Thu Nov 26 09:42:12 2026 +0800

    [ISSUE #11608] fix(srvutil): watch configured files that are created after 
startup (#11609)
    
    * [ISSUE #11608] fix(srvutil): watch configured files that are created 
after startup
    
    * [ISSUE #11608] test(srvutil): cover null and empty watch file paths
---
 .../apache/rocketmq/srvutil/FileWatchService.java  |  5 +--
 .../rocketmq/srvutil/FileWatchServiceTest.java     | 41 ++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git 
a/srvutil/src/main/java/org/apache/rocketmq/srvutil/FileWatchService.java 
b/srvutil/src/main/java/org/apache/rocketmq/srvutil/FileWatchService.java
index 9b203e88ef..83bac91628 100644
--- a/srvutil/src/main/java/org/apache/rocketmq/srvutil/FileWatchService.java
+++ b/srvutil/src/main/java/org/apache/rocketmq/srvutil/FileWatchService.java
@@ -18,7 +18,6 @@
 package org.apache.rocketmq.srvutil;
 
 import com.google.common.base.Strings;
-import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -49,7 +48,9 @@ public class FileWatchService extends 
LifecycleAwareServiceThread {
         this.listener = listener;
         this.watchInterval = watchInterval;
         for (String file : watchFiles) {
-            if (!Strings.isNullOrEmpty(file) && new File(file).exists()) {
+            if (!Strings.isNullOrEmpty(file)) {
+                // Register files that do not exist yet as well. They may be 
created after startup, for example a
+                // certificate provisioned later, and only registered paths 
are checked on every watch round.
                 currentHash.put(file, md5Digest(file));
             }
         }
diff --git 
a/srvutil/src/test/java/org/apache/rocketmq/srvutil/FileWatchServiceTest.java 
b/srvutil/src/test/java/org/apache/rocketmq/srvutil/FileWatchServiceTest.java
index aeae625314..ffa6818d12 100644
--- 
a/srvutil/src/test/java/org/apache/rocketmq/srvutil/FileWatchServiceTest.java
+++ 
b/srvutil/src/test/java/org/apache/rocketmq/srvutil/FileWatchServiceTest.java
@@ -71,6 +71,47 @@ public class FileWatchServiceTest {
         fileWatchService.shutdown();
     }
 
+    @Test
+    public void watchSingleFile_CreatedAfterStart() throws Exception {
+        final File file = new File(tempFolder.getRoot(), 
"certificate-created-later.pem");
+        assertThat(file.exists()).isFalse();
+        final Semaphore waitSemaphore = new Semaphore(0);
+        FileWatchService fileWatchService = new FileWatchService(new String[] 
{file.getAbsolutePath()}, path -> {
+            assertThat(path).isEqualTo(file.getAbsolutePath());
+            waitSemaphore.release();
+        });
+        fileWatchService.start();
+        fileWatchService.awaitStarted(1000);
+        try {
+            assertThat(file.createNewFile()).isTrue();
+            modifyFile(file);
+            boolean result = waitSemaphore.tryAcquire(1, 2000, 
TimeUnit.MILLISECONDS);
+            assertThat(result).isTrue();
+        } finally {
+            fileWatchService.shutdown();
+        }
+    }
+
+    @Test
+    public void watchFiles_IgnoreNullOrEmptyPath() throws Exception {
+        final File file = tempFolder.newFile();
+        final Semaphore waitSemaphore = new Semaphore(0);
+        FileWatchService fileWatchService = new FileWatchService(
+            new String[] {null, "", file.getAbsolutePath()}, path -> {
+                assertThat(path).isEqualTo(file.getAbsolutePath());
+                waitSemaphore.release();
+            });
+        fileWatchService.start();
+        fileWatchService.awaitStarted(1000);
+        try {
+            modifyFile(file);
+            boolean result = waitSemaphore.tryAcquire(1, 2000, 
TimeUnit.MILLISECONDS);
+            assertThat(result).isTrue();
+        } finally {
+            fileWatchService.shutdown();
+        }
+    }
+
     @Test
     public void watchTwoFile_FileDeleted() throws Exception {
         File fileA = tempFolder.newFile();

Reply via email to