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 96da1154ec..eee247a7f2 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 @@ -96,7 +96,7 @@ public void doExecute(TestContext context) { context.setVariable(name + ":pid", pid); context.setVariable(name + ":process:" + pid, pao); - logger.info("Started Camel integration '%s'".formatted(name)); + logger.info("Started Camel integration '%s' (%s)".formatted(name, pid)); } catch (IOException e) { throw new CitrusRuntimeException("Failed to create temporary file from Camel integration"); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelStopIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelStopIntegrationAction.java index 1c833dd40b..4fcec820f4 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelStopIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelStopIntegrationAction.java @@ -59,7 +59,7 @@ public void doExecute(TestContext context) { camelJBang().stop(pid); - logger.info("Stopped Camel integration '%s'".formatted(name)); + logger.info("Stopped Camel integration '%s' (%s)".formatted(name, pid)); } public String getIntegrationName() { diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java index ed2c5667d5..68461c4dd6 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java @@ -82,7 +82,7 @@ public void doExecute(TestContext context) { private void verifyRouteLogs(Long pid, String name, String message, TestContext context) { if (printLogs) { - INTEGRATION_LOG.info(String.format("Waiting for integration '%s' to log message", name)); + INTEGRATION_LOG.info(String.format("Waiting for Camel integration '%s' to log message", name)); } String log; @@ -98,55 +98,66 @@ private void verifyRouteLogs(Long pid, String name, String message, TestContext } if (log.contains(message)) { - logger.info("Verified integration logs - All values OK!"); + logger.info("Verified Camel integration logs - All values OK!"); return; } if (!printLogs) { - logger.warn(String.format("Waiting for integration '%s' to log message - retry in %s ms", name, delayBetweenAttempts)); + logger.warn(String.format("Waiting for Camel integration '%s' to log message - retry in %s ms", name, delayBetweenAttempts)); } try { Thread.sleep(delayBetweenAttempts); } catch (InterruptedException e) { - logger.warn("Interrupted while waiting for integration logs", e); + logger.warn("Interrupted while waiting for Camel integration logs", e); } } throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), - new CitrusRuntimeException(String.format("Failed to verify integration '%s' - " + + new CitrusRuntimeException(String.format("Failed to verify Camel integration '%s' - " + "has not printed message '%s' after %d attempts", name, message, maxAttempts))); } private Long verifyRouteStatus(String name, String phase, TestContext context) { - INTEGRATION_STATUS_LOG.info(String.format("Waiting for integration '%s' to be in state '%s'", name, phase)); + INTEGRATION_STATUS_LOG.info(String.format("Waiting for Camel integration '%s' to be in state '%s'", name, phase)); for (int i = 0; i < maxAttempts; i++) { if (context.getVariables().containsKey(name + ":pid")) { Long pid = context.getVariable(name + ":pid", Long.class); Map properties = camelJBang().get(pid); if ((phase.equals("Stopped") && properties.isEmpty()) || (!properties.isEmpty() && properties.get("STATUS").equals(phase))) { - logger.info(String.format("Verified integration '%s' state '%s' - All values OK!", name, phase)); + logger.info(String.format("Verified Camel integration '%s' state '%s' - All values OK!", name, phase)); return pid; } else if (phase.equals("Error")) { - logger.info(String.format("Integration '%s' is in state 'Error'", name)); + logger.info(String.format("Camel integration '%s' is in state 'Error'", name)); if (stopOnErrorStatus) { - throw new CitrusRuntimeException(String.format("Failed to verify integration '%s' - is in state 'Error'", name)); + throw new CitrusRuntimeException(String.format("Failed to verify Camel integration '%s' - is in state 'Error'", name)); + } + } + + if (context.getVariables().containsKey(name + ":process:" + pid)) { + // check if process is still alive + ProcessAndOutput pao = context.getVariable(name + ":process:" + pid, ProcessAndOutput.class); + if (!pao.getProcess().isAlive()) { + logger.info("Failed to verify Camel integration '%s'".formatted(name)); + logger.info(pao.getOutput()); + + throw new CitrusRuntimeException(String.format("Failed to verify Camel integration - exit code %s", pao.getProcess().exitValue())); } } } logger.info(System.lineSeparator() + camelJBang().ps()); - logger.info(String.format("Waiting for integration '%s' to be in state '%s'- retry in %s ms", name, phase, delayBetweenAttempts)); + logger.info(String.format("Waiting for Camel integration '%s' to be in state '%s'- retry in %s ms", name, phase, delayBetweenAttempts)); try { Thread.sleep(delayBetweenAttempts); } catch (InterruptedException e) { - logger.warn("Interrupted while waiting for integration state", e); + logger.warn("Interrupted while waiting for Camel integration state", e); } } throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), - new CitrusRuntimeException(String.format("Failed to verify integration '%s' - " + + new CitrusRuntimeException(String.format("Failed to verify Camel integration '%s' - " + "is not in state '%s' after %d attempts", name, phase, maxAttempts))); }