gnodet-bot commented on code in PR #27916:
URL: https://github.com/apache/camel/pull/27916#discussion_r4289398544
##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/action/ActionCommandTestSupport.java:
##########
@@ -103,64 +112,91 @@ protected static void writeMessageHistoryFile(long pid,
JsonObject line) throws
}
/**
- * Reads back the action file an action command wrote for the given pid.
+ * The action the fake integration took last (see {@link
#callWithResponse}).
*
- * @return the deserialized action JSON, or {@code null} if no action file
exists
+ * @return the action JSON, or {@code null} if the command sent no action
*/
- protected static JsonObject readActionFile(long pid) throws Exception {
- Path f = CommandLineHelper.getCamelDir().resolve(pid + "-action.json");
- if (!Files.exists(f)) {
- return null;
- }
- return (JsonObject) Jsoner.deserialize(Files.readString(f));
+ protected static JsonObject readActionFile(long pid) {
+ return lastAction;
}
/**
* Runs the command with ProcessHandle mocked so a single test process
(TEST_PID) is discoverable and the current
- * process is a distinct pid. Returns the exit code; any action/output
files the command wrote persist on disk and
- * can be asserted after this returns.
+ * process is a distinct pid. The test process confirms an action like the
camel-cli-connector of Camel 4.24 does,
+ * and {@link #readActionFile(long)} returns the action. Returns the exit
code.
*/
protected static int callWithSingleProcess(CamelCommand command) throws
Exception {
- try (MockedStatic<ProcessHandle> mocked =
mockStatic(ProcessHandle.class)) {
- ProcessHandle ph = mockProcessHandle(TEST_PID);
- ProcessHandle current = mockCurrentHandle();
- mocked.when(ProcessHandle::current).thenReturn(current);
- mocked.when(ProcessHandle::allProcesses).thenAnswer(inv ->
Stream.of(ph));
- return command.doCall();
- }
+ return call(command, CONFIRMED);
}
/**
- * Runs a request/response reader command end to end. Mocks a single
discoverable process (TEST_PID) and, in a
- * background thread, simulates the running Camel writing {@code response}
to its output file once the command has
- * written its action request.
- * <p>
- * The reader commands delete any stale output file <em>before</em>
writing the action file and only then poll for
- * the output, so the responder waits for the action file to appear: that
guarantees the response lands after the
- * command's own delete and cannot be wiped out. No {@code Thread.sleep}
is used; the wait is driven by Awaitility.
+ * Runs a request/response reader command end to end. Mocks a single
discoverable process (TEST_PID) that answers
+ * the action of the command with {@code response}, like the
camel-cli-connector does: it writes the answer next to
+ * the request, then deletes the request.
*
* @return the command exit code; rendered output can be asserted
afterwards via {@code printer.getOutput()}
*/
protected int callWithResponse(CamelCommand command, JsonObject response)
throws Exception {
- Path actionFile = CommandLineHelper.getCamelDir().resolve(TEST_PID +
"-action.json");
- Path outputFile = CommandLineHelper.getCamelDir().resolve(TEST_PID +
"-output.json");
+ return call(command, response);
+ }
+
+ private static int call(CamelCommand command, JsonObject response) throws
Exception {
+ lastAction = null;
+ AtomicBoolean running = new AtomicBoolean(true);
Thread responder = new Thread(() -> {
- await().atMost(5, TimeUnit.SECONDS).until(() ->
Files.exists(actionFile));
- try {
- Files.writeString(outputFile, response.toJson());
- } catch (IOException e) {
- throw new UncheckedIOException(e);
+ Path dir = CommandLineHelper.getCamelDir();
+ while (running.get()) {
+ // the integration polls for actions
+ await().pollInterval(Duration.ofMillis(10)).atMost(1,
TimeUnit.HOURS)
Review Comment:
💡 **Style nit:** The `atMost(1, TimeUnit.HOURS)` ceiling is functionally
correct (the `until()` condition exits immediately when `running` is cleared or
a request appears), but the 1-hour value reads as surprisingly large to future
readers. A shorter safety ceiling like 30 seconds would better signal that this
wait is expected to be brief:
```suggestion
await().pollInterval(Duration.ofMillis(10)).atMost(30,
TimeUnit.SECONDS)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]