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

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


The following commit(s) were added to refs/heads/main by this push:
     new 4de3d25067 Wait for process to exit when destroying processes created 
from QuarkusProcessExecutor
4de3d25067 is described below

commit 4de3d250671cd310692d8f84b8790216cf8a7b2f
Author: James Netherton <[email protected]>
AuthorDate: Tue Sep 16 07:11:34 2025 +0100

    Wait for process to exit when destroying processes created from 
QuarkusProcessExecutor
---
 .../support/process/QuarkusProcessExecutor.java    | 28 +++++++++++++++++++++-
 .../component/master/it/MasterFileTest.java        |  4 ++--
 .../component/master/it/MasterOpenShiftTest.java   |  4 ++--
 .../component/quartz/it/QuartzClusteredTest.java   |  2 +-
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git 
a/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java
 
b/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java
index e10963583d..d027f441a4 100644
--- 
a/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java
+++ 
b/integration-tests-support/process-executor-support/src/main/java/org/apache/camel/quarkus/test/support/process/QuarkusProcessExecutor.java
@@ -21,6 +21,8 @@ import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.function.Consumer;
 
@@ -39,6 +41,7 @@ public class QuarkusProcessExecutor {
     private final ProcessExecutor executor;
     private final int httpPort = AvailablePortFinder.getNextAvailable();
     private final int httpsPort = AvailablePortFinder.getNextAvailable();
+    private Process process;
 
     public QuarkusProcessExecutor(String... jvmArgs) {
         this(jvmArgs, (String[]) null);
@@ -70,7 +73,30 @@ public class QuarkusProcessExecutor {
     }
 
     public StartedProcess start() throws IOException {
-        return executor.start();
+        StartedProcess startedProcess = executor.start();
+        this.process = startedProcess.getProcess();
+        return startedProcess;
+    }
+
+    public void destroy() {
+        destroy(10, TimeUnit.SECONDS);
+    }
+
+    public void destroy(long timeout, TimeUnit unit) {
+        if (this.process != null) {
+            this.process.destroy();
+            try {
+                LOGGER.infof("Destroying process %d", this.process.pid());
+                this.process.onExit().get(timeout, unit);
+                LOGGER.infof("Process %d completed with exit code %d", 
this.process.pid(), this.process.exitValue());
+            } catch (TimeoutException e) {
+                LOGGER.warnf(e, "Timed out waiting to destroy process %d", 
this.process.pid());
+            } catch (ExecutionException | InterruptedException e) {
+                LOGGER.warnf(e, "Error occurred destroying process %d", 
this.process.pid());
+            } finally {
+                this.process = null;
+            }
+        }
     }
 
     public int getHttpPort() {
diff --git 
a/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
 
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
index 229c3731d7..51f4d52227 100644
--- 
a/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
+++ 
b/integration-tests/master-file/src/test/java/org/apache/camel/quarkus/component/master/it/MasterFileTest.java
@@ -63,7 +63,7 @@ class MasterFileTest {
                 return readLeaderFile("leader").equals("leader");
             });
 
-            // Verify the follower hasn't took leader role
+            // Verify the follower hasn't taken the leader role
             assertThat(readLeaderFile("follower"), emptyString());
 
             // Stop camel leader route to trigger fail-over
@@ -76,7 +76,7 @@ class MasterFileTest {
             });
         } finally {
             if (process != null && process.getProcess().isAlive()) {
-                process.getProcess().destroy();
+                quarkusProcessExecutor.destroy();
             }
         }
     }
diff --git 
a/integration-tests/master-openshift/src/test/java/org/apache/camel/quarkus/component/master/it/MasterOpenShiftTest.java
 
b/integration-tests/master-openshift/src/test/java/org/apache/camel/quarkus/component/master/it/MasterOpenShiftTest.java
index 5e93cb495f..321d04c96b 100644
--- 
a/integration-tests/master-openshift/src/test/java/org/apache/camel/quarkus/component/master/it/MasterOpenShiftTest.java
+++ 
b/integration-tests/master-openshift/src/test/java/org/apache/camel/quarkus/component/master/it/MasterOpenShiftTest.java
@@ -86,7 +86,7 @@ class MasterOpenShiftTest {
             followerProcess = followerProcessExecutor.start();
             awaitStartup(followerProcessExecutor);
 
-            // Verify the follower hasn't took leader role yet
+            // Verify the follower hasn't taken the leader role yet
             assertThat(readLeaderFile("follower"), emptyString());
 
             // Stop camel and delete the lease mock to trigger fail-over
@@ -100,7 +100,7 @@ class MasterOpenShiftTest {
             });
         } finally {
             if (followerProcess != null && 
followerProcess.getProcess().isAlive()) {
-                followerProcess.getProcess().destroy();
+                followerProcessExecutor.destroy();
             }
         }
     }
diff --git 
a/integration-tests/quartz-clustered/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzClusteredTest.java
 
b/integration-tests/quartz-clustered/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzClusteredTest.java
index cfe38bd7f7..a1cf38350a 100644
--- 
a/integration-tests/quartz-clustered/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzClusteredTest.java
+++ 
b/integration-tests/quartz-clustered/src/test/java/org/apache/camel/quarkus/component/quartz/it/QuartzClusteredTest.java
@@ -88,7 +88,7 @@ class QuartzClusteredTest {
                     Files.readAllLines(quarkusLog).stream().anyMatch(line -> 
line.contains("Hello from NodeA")));
 
             // Stop NodeB to trigger failover to NodeA
-            process.getProcess().destroy();
+            quarkusProcessExecutor.destroy();
 
             // Verify failover
             Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> {

Reply via email to