davsclaus commented on code in PR #29853:
URL: https://github.com/apache/camel/pull/29853#discussion_r4565882055


##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java:
##########
@@ -124,6 +127,89 @@ void noAnswerIsATimeout() throws Exception {
         assertNoFilesLeft();
     }
 
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void integrationThatStopsIsNotWaitedFor() throws Exception {
+        // a process of its own, as the client only watches a process it can 
see
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                // stops while it has the action (such as a send that waits 
for a reply), without answering it
+                await().atMost(5, TimeUnit.SECONDS).until(() -> 
!requestFiles(CommandLineHelper.getCamelDir(), pid).isEmpty());
+                integration.destroy();
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "send");
+            StopWatch watch = new StopWatch();
+
+            ActionResult result = ActionClient.execute(pid, request, 30000);
+
+            assertThat(watch.taken()).isLessThan(10000);
+            assertThat(result.status()).isEqualTo(Status.ERROR);
+            assertThat(result.exitCode()).isEqualTo(CliExitCode.NOT_FOUND);
+            assertThat(result.error())
+                    .isEqualTo("The integration with pid " + pid + " stopped 
before it answered the action send");
+            assertNoFilesLeft();
+        } finally {
+            integration.destroyForcibly();
+        }
+    }
+
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void textOfAnIntegrationThatStopsIsAnError() throws Exception {
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                await().atMost(5, TimeUnit.SECONDS).until(() -> 
!requestFiles(CommandLineHelper.getCamelDir(), pid).isEmpty());
+                integration.destroy();
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "route-dump");
+
+            // the tools of camel ask and the TUI say so, instead of that the 
integration did not answer in time
+            assertThatThrownBy(() -> ActionClient.executeText(pid, request, 
30000))
+                    .isInstanceOf(ActionClient.StoppedException.class)
+                    .hasMessage("The integration with pid " + pid + " stopped 
before it answered the action route-dump");
+            assertNoFilesLeft();
+        } finally {
+            integration.destroyForcibly();
+        }
+    }
+
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void answerOfAnIntegrationThatStopsRightAfterIsRead() throws Exception {
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                Path dir = CommandLineHelper.getCamelDir();
+                Path request = await().atMost(5, TimeUnit.SECONDS)
+                        .until(() -> requestFiles(dir, pid), files -> 
!files.isEmpty()).get(0);
+                String id = request.getFileName().toString().substring((pid + 
"-action-").length()).replace(".json", "");
+                Files.writeString(dir.resolve(pid + "-output-" + id + 
".json"), "{\"status\":\"success\",\"value\":42}");
+                integration.destroy();
+                integration.waitFor(5, TimeUnit.SECONDS);
+                Files.deleteIfExists(request);
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "jvm");
+
+            ActionResult result = ActionClient.execute(pid, request, 30000);
+
+            assertThat(result.status()).isEqualTo(Status.OK);
+            assertThat(result.reply().getInteger("value")).isEqualTo(42);
+        } finally {
+            integration.destroyForcibly();
+        }
+    }

Review Comment:
   Added in c3a81388d647: `answerOfAnIntegrationThatStopsRightAfterIsRead` now 
calls `assertNoFilesLeft()` like the other two tests. `ActionClientTest` passes 
(15 tests).
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java:
##########
@@ -124,6 +127,89 @@ void noAnswerIsATimeout() throws Exception {
         assertNoFilesLeft();
     }
 
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void integrationThatStopsIsNotWaitedFor() throws Exception {
+        // a process of its own, as the client only watches a process it can 
see
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                // stops while it has the action (such as a send that waits 
for a reply), without answering it
+                await().atMost(5, TimeUnit.SECONDS).until(() -> 
!requestFiles(CommandLineHelper.getCamelDir(), pid).isEmpty());
+                integration.destroy();
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "send");
+            StopWatch watch = new StopWatch();
+
+            ActionResult result = ActionClient.execute(pid, request, 30000);
+
+            assertThat(watch.taken()).isLessThan(10000);
+            assertThat(result.status()).isEqualTo(Status.ERROR);
+            assertThat(result.exitCode()).isEqualTo(CliExitCode.NOT_FOUND);
+            assertThat(result.error())
+                    .isEqualTo("The integration with pid " + pid + " stopped 
before it answered the action send");
+            assertNoFilesLeft();
+        } finally {
+            integration.destroyForcibly();
+        }
+    }
+
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void textOfAnIntegrationThatStopsIsAnError() throws Exception {
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                await().atMost(5, TimeUnit.SECONDS).until(() -> 
!requestFiles(CommandLineHelper.getCamelDir(), pid).isEmpty());
+                integration.destroy();
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "route-dump");
+
+            // the tools of camel ask and the TUI say so, instead of that the 
integration did not answer in time
+            assertThatThrownBy(() -> ActionClient.executeText(pid, request, 
30000))
+                    .isInstanceOf(ActionClient.StoppedException.class)
+                    .hasMessage("The integration with pid " + pid + " stopped 
before it answered the action route-dump");
+            assertNoFilesLeft();
+        } finally {
+            integration.destroyForcibly();
+        }
+    }
+
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void answerOfAnIntegrationThatStopsRightAfterIsRead() throws Exception {
+        Process integration = new ProcessBuilder("sleep", "30").start();
+        try {
+            long pid = integration.pid();
+            executor.submit(() -> {
+                Path dir = CommandLineHelper.getCamelDir();
+                Path request = await().atMost(5, TimeUnit.SECONDS)
+                        .until(() -> requestFiles(dir, pid), files -> 
!files.isEmpty()).get(0);
+                String id = request.getFileName().toString().substring((pid + 
"-action-").length()).replace(".json", "");
+                Files.writeString(dir.resolve(pid + "-output-" + id + 
".json"), "{\"status\":\"success\",\"value\":42}");
+                integration.destroy();
+                integration.waitFor(5, TimeUnit.SECONDS);
+                Files.deleteIfExists(request);
+                return null;
+            });
+            JsonObject request = new JsonObject();
+            request.put("action", "jvm");
+
+            ActionResult result = ActionClient.execute(pid, request, 30000);
+
+            assertThat(result.status()).isEqualTo(Status.OK);
+            assertThat(result.reply().getInteger("value")).isEqualTo(42);
+        } finally {
+            integration.destroyForcibly();
+        }
+    }

Review Comment:
   Same as the other thread: fixed in c3a81388d647.
   
   _Claude Code on behalf of davsclaus_



-- 
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]

Reply via email to