From 01c4d8ab2f2d909a85db3cf756c99afa82976145 Mon Sep 17 00:00:00 2001 From: Gaelle Fournier Date: Thu, 19 Dec 2024 12:55:33 +0100 Subject: [PATCH] fix: Set the current parent pid in the Run Camel action --- .../jbang/ProcessAndOutput.java | 19 ++++++++++++++++++- .../actions/CamelRunIntegrationAction.java | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/ProcessAndOutput.java b/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/ProcessAndOutput.java index 598d139630..591836bcf5 100644 --- a/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/ProcessAndOutput.java +++ b/connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/ProcessAndOutput.java @@ -36,7 +36,9 @@ */ public class ProcessAndOutput { - /** Logger */ + /** + * Logger + */ private static final Logger LOG = LoggerFactory.getLogger(ProcessAndOutput.class); private final Process process; @@ -140,6 +142,7 @@ private void readChunk() { * Get the process id of first descendant or the parent process itself in case there is no descendant process. * On Linux the shell command represents the parent process and the JBang command as descendant process. * Typically, we need the JBang command process id. + * * @return */ public Long getProcessId() { @@ -150,9 +153,11 @@ public Long getProcessId() { * Get the process id of first descendant or the parent process itself in case there is no descendant process. * On Linux the shell command represents the parent process and the JBang command as descendant process. * Typically, we need the JBang command process id. + * * @return */ public Long getProcessId(String app) { + try { if (app != null && isUnix()) { // wait for descendant process to be available @@ -173,6 +178,17 @@ public Long getProcessId(String app) { } } + /** + * Get the process id of the parent process. + * Typically, we need the JBang command process id. + * + * @return + */ + public Long getParentProcessId() { + return process.pid(); + } + + private static boolean isUnix() { String os = System.getProperty("os.name").toLowerCase(); return os.contains("nix") || os.contains("nux") || os.contains("aix"); @@ -180,6 +196,7 @@ private static boolean isUnix() { /** * Sets the application name that identifies this process. + * * @param app */ public void setApp(String app) { diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java index 13c36aada2..62a41288e8 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java @@ -124,7 +124,7 @@ public void doExecute(TestContext context) { verifyProcessIsAlive(pao, name); pao.setApp(integrationToRun.getFileName().toString()); - Long pid = pao.getProcessId(); + Long pid = pao.getParentProcessId(); context.setVariable(name + ":pid", pid); context.setVariable(name + ":process:" + pid, pao);