This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 e3dbaac34082 CAMEL-26911: camel-jbang - camel trace and camel receive
clear empty the file, so the next batch is not lost (#29825)
e3dbaac34082 is described below
commit e3dbaac34082e5070c8556986672efe4034d89e9
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 13 16:39:58 2026 +0100
CAMEL-26911: camel-jbang - camel trace and camel receive clear empty the
file, so the next batch is not lost (#29825)
The clear wrote an empty JSON object without a new line, which the next
batch
of the connector joined on the same line, so that batch did not parse.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../dsl/jbang/core/commands/action/CamelReceiveAction.java | 4 +++-
.../camel/dsl/jbang/core/commands/action/CamelTraceAction.java | 4 +++-
.../dsl/jbang/core/commands/action/CamelReceiveActionTest.java | 10 +++++++++-
.../dsl/jbang/core/commands/action/CamelTraceActionTest.java | 10 +++++++++-
4 files changed, 24 insertions(+), 4 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
index 898ba35b2feb..80e5d91fcf2b 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java
@@ -281,7 +281,9 @@ public class CamelReceiveAction extends ActionBaseCommand {
if ("clear".equals(action)) {
Path f = getReceiveFile(Long.toString(process.pid()));
if (Files.exists(f)) {
- Files.writeString(f, "{}");
+ // empty: the connector appends a line of JSON per batch,
which an empty JSON object without
+ // a new line would join, and that batch would be lost
(CAMEL-26911)
+ Files.writeString(f, "");
}
} else {
printer().println("Starting to receive messages from existing
Camel: " + process.name() + " (pid: "
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
index de80c0e8a4af..62848187ca09 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
@@ -226,7 +226,9 @@ public class CamelTraceAction extends ActionBaseCommand {
for (CamelProcess process : findProcesses(name)) {
Path f = getTraceFile(Long.toString(process.pid()));
if (Files.exists(f)) {
- Files.writeString(f, "{}");
+ // empty: the connector appends a line of JSON per batch,
which an empty JSON object without
+ // a new line would join, and that batch would be lost
(CAMEL-26911)
+ Files.writeString(f, "");
}
}
return 0;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveActionTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveActionTest.java
index f47af3f9030c..6a94828f2475 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveActionTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveActionTest.java
@@ -27,6 +27,7 @@ import org.apache.camel.dsl.jbang.core.common.CliException;
import org.apache.camel.dsl.jbang.core.common.CliExitCode;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.apache.camel.dsl.jbang.core.common.CommandLineTestHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
import org.apache.camel.util.json.Jsoner;
@@ -113,7 +114,14 @@ class CamelReceiveActionTest extends
ActionCommandTestSupport {
assertThat(callWithSingleProcess(command("myApp",
"--action=clear"))).isZero();
- assertThat(Files.readString(received)).isEqualTo("{}");
+ assertThat(received).isEmptyFile();
+ // the next batch of the connector, which appends a line, is read
+ IOHelper.appendText(batch(message(2, "Bye Camel")).toJson() +
System.lineSeparator(), received.toFile());
+ List<String> lines = Files.readAllLines(received);
+ assertThat(lines).hasSize(1);
+ JsonObject next = (JsonObject) Jsoner.deserialize(lines.get(0));
+ JsonArray messages = next.getCollection("messages");
+ assertThat(messages).hasSize(1);
}
@Test
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceActionTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceActionTest.java
index ddad6edd82a3..75eae0167617 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceActionTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceActionTest.java
@@ -27,6 +27,7 @@ import org.apache.camel.dsl.jbang.core.common.CliException;
import org.apache.camel.dsl.jbang.core.common.CliExitCode;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.apache.camel.dsl.jbang.core.common.CommandLineTestHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
import org.apache.camel.util.json.Jsoner;
@@ -96,7 +97,14 @@ class CamelTraceActionTest extends ActionCommandTestSupport {
assertThat(callWithSingleProcess(command("--action=clear"))).isZero();
- assertThat(Files.readString(traceFile)).isEqualTo("{}");
+ assertThat(traceFile).isEmptyFile();
+ // the next batch of the connector, which appends a line, is read
+ IOHelper.appendText("{\"traces\":[{\"uid\":2}]}" +
System.lineSeparator(), traceFile.toFile());
+ List<String> lines = Files.readAllLines(traceFile);
+ assertThat(lines).hasSize(1);
+ JsonObject next = (JsonObject) Jsoner.deserialize(lines.get(0));
+ JsonArray traces = next.getCollection("traces");
+ assertThat(traces).hasSize(1);
}
@Test