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 d488aa9496d7 CAMEL-26938: camel-jbang - an action is answered in about
25 millis instead of 110 (#29878)
d488aa9496d7 is described below
commit d488aa9496d7905bfd0e3b8e294c5fdb15f3e72a
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 08:51:13 2026 +0100
CAMEL-26938: camel-jbang - an action is answered in about 25 millis instead
of 110 (#29878)
A camel cmd action, a runtime tool of the MCP server, camel ask and the TUI
are answered in about 25 millis instead of 110.
- ActionClient looks for the answer after 5 millis, then waits a tenth of
the time waited so far, from 5 to 100 millis.
- The connector looks for action files every 20 millis (was 100), and
between two status updates lists ~/.camel only when its modification time
changed. A time is only remembered once it is 20 millis old, for file system
clocks with coarse ticks, and an action file that cannot be read yet makes the
next poll list again.
- ActionBaseCommand.getJsonObject looks before it sleeps.
- ActionClient.executeText takes an answer that is not JSON, of an older
integration, once it has not changed for 100 millis.
- The protocol is the same, so new and old clients and integrations work
together.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/catalog/docs/cli-connector.adoc | 8 ++--
.../src/main/docs/cli-connector.adoc | 8 ++--
.../camel/cli/connector/CliConnectorTransport.java | 2 +-
.../cli/connector/FileCliConnectorTransport.java | 55 +++++++++++++++++-----
.../connector/FileCliConnectorTransportTest.java | 52 ++++++++++++++++++--
.../core/commands/action/ActionBaseCommand.java | 11 +++--
.../camel/dsl/jbang/core/common/ActionClient.java | 25 ++++++++--
.../camel/dsl/jbang/core/common/RuntimeHelper.java | 1 -
.../dsl/jbang/core/common/ActionClientTest.java | 32 +++++++++++++
9 files changed, 160 insertions(+), 34 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cli-connector.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cli-connector.adoc
index 42daa0683cc0..53ed54173beb 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cli-connector.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cli-connector.adoc
@@ -62,9 +62,11 @@ route. When the action wrote a result before it failed, the
answer has it under
two routes that fail to stop, are joined with `;` in `error`. A result can
also report a failure of its own, such as a
message sent to a route that throws an exception: it is written as it is.
-The connector looks for action files about every 100 millis, and writes the
status to `~/.camel/<pid>-status.json`
-every second. It also writes the status as soon as Camel changes phase, such
as when it has started, and after it
-answers actions (at most every 200 millis), so the status shows what an action
did.
+The connector looks for action files about every 20 millis, and writes the
status to `~/.camel/<pid>-status.json`
+every second. In between, it only lists the directory when its modification
time has changed, which it does when a
+file is added to it, and with every status it lists it anyway. It also writes
the status as soon as Camel changes
+phase, such as when it has started, and after it answers actions (at most
every 200 millis), so the status shows what
+an action did.
Write the action file atomically (write a temporary file, then move it), so
the connector never reads half an action.
An action file that cannot be read yet is retried for two seconds. Deleting
the action file before the answer is
diff --git a/dsl/camel-cli-connector/src/main/docs/cli-connector.adoc
b/dsl/camel-cli-connector/src/main/docs/cli-connector.adoc
index 42daa0683cc0..53ed54173beb 100644
--- a/dsl/camel-cli-connector/src/main/docs/cli-connector.adoc
+++ b/dsl/camel-cli-connector/src/main/docs/cli-connector.adoc
@@ -62,9 +62,11 @@ route. When the action wrote a result before it failed, the
answer has it under
two routes that fail to stop, are joined with `;` in `error`. A result can
also report a failure of its own, such as a
message sent to a route that throws an exception: it is written as it is.
-The connector looks for action files about every 100 millis, and writes the
status to `~/.camel/<pid>-status.json`
-every second. It also writes the status as soon as Camel changes phase, such
as when it has started, and after it
-answers actions (at most every 200 millis), so the status shows what an action
did.
+The connector looks for action files about every 20 millis, and writes the
status to `~/.camel/<pid>-status.json`
+every second. In between, it only lists the directory when its modification
time has changed, which it does when a
+file is added to it, and with every status it lists it anyway. It also writes
the status as soon as Camel changes
+phase, such as when it has started, and after it answers actions (at most
every 200 millis), so the status shows what
+an action did.
Write the action file atomically (write a temporary file, then move it), so
the connector never reads half an action.
An action file that cannot be read yet is retried for two seconds. Deleting
the action file before the answer is
diff --git
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/CliConnectorTransport.java
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/CliConnectorTransport.java
index 084c0a3b804b..37584c7626be 100644
---
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/CliConnectorTransport.java
+++
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/CliConnectorTransport.java
@@ -41,7 +41,7 @@ public interface CliConnectorTransport extends Service {
CamelContext camelContext, CliActionDispatcher dispatcher,
CliSnapshotProducer snapshots, Runnable shutdown);
/**
- * Changes how often the transport updates its snapshots, in millis. The
file transport looks for actions every 100
+ * Changes how often the transport updates its snapshots, in millis. The
file transport looks for actions every 20
* millis also when this is longer.
*/
default void updateDelay(int delay) {
diff --git
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/FileCliConnectorTransport.java
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/FileCliConnectorTransport.java
index 919928d410b8..21ff9008d5d5 100644
---
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/FileCliConnectorTransport.java
+++
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/FileCliConnectorTransport.java
@@ -49,10 +49,12 @@ import org.slf4j.LoggerFactory;
* Deleting the <tt>{pid}</tt> lock file shuts down the integration.
* <p/>
* The snapshots are written every second (every 100 millis in debug mode),
and the action files are looked for about
- * every 100 millis in between, on the same thread, so an action does not wait
up to a second for its answer. The status
- * is also written as soon as Camel changes phase, such as when it has
started, and after actions are answered (at most
- * every 200 millis), so a <tt>camel run --background</tt> is told that Camel
has started without waiting for the next
- * status, and a <tt>camel get</tt> right after a <tt>camel cmd</tt> shows
what the action did.
+ * every 20 millis in between, on the same thread, so an action does not wait
up to a second for its answer. In between,
+ * the directory is only listed when its modification time has changed, which
it does when a file is added to it, as
+ * listing it costs far more than looking at that time. With every snapshot it
is listed anyway. The status is also
+ * written as soon as Camel changes phase, such as when it has started, and
after actions are answered (at most every
+ * 200 millis), so a <tt>camel run --background</tt> is told that Camel has
started without waiting for the next status,
+ * and a <tt>camel get</tt> right after a <tt>camel cmd</tt> shows what the
action did.
* <p/>
* An action with a request id (<tt>{pid}-action-{requestId}.json</tt>) always
gets a reply in
* <tt>{pid}-output-{requestId}.json</tt>:
<tt>{"status":"failed","error":"..."}</tt> when it is unknown, throws or
@@ -78,6 +80,8 @@ public class FileCliConnectorTransport extends ServiceSupport
implements CliConn
private int delay = 1000;
private long counter;
private final Map<File, PendingAction> pending = new HashMap<>();
+ // the modification time of the directory when it was last listed, or 0 to
list it at the next poll
+ private long listed;
// the phase of Camel when the status was last written, when it was
written, and whether an action was answered since
private int statusPhase = -1;
private long statusWritten;
@@ -88,7 +92,10 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
// how long a stop waits for the poll in flight before it removes the files
private static final long STOP_POLL_TIMEOUT_MS = 5000;
// how often the action files are looked for between two snapshots
- private static final int ACTION_POLL_MS = 100;
+ private static final int ACTION_POLL_MS = 20;
+ // a file added within the same tick of the clock of the file system as
the change before it leaves the
+ // modification time of the directory as it was; a tick is at most about
16 millis (Windows)
+ private static final long CLOCK_TICK_MS = 20;
// how often at most the status is written for the actions answered
between two snapshots, as collecting it costs
private static final long ANSWERED_STATUS_MS = 200;
@@ -200,7 +207,7 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
return;
}
- actionTask();
+ actionTask(true);
statusTask();
// only run this every 2nd time as gathering this data has more
overhead
// and are only needed when doing tracing/debugging/receive
@@ -210,13 +217,13 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
}
/**
- * Looks for actions between two snapshots, so an action is answered in
about 100 millis instead of up to a second.
+ * Looks for actions between two snapshots, so an action is answered in
about 20 millis instead of up to a second.
* Writes the status when Camel has changed phase since it was last
written, and when an action was answered (at
* most every 200 millis).
*/
protected void actionPollTask() {
if (polling()) {
- actionTask();
+ actionTask(false);
if (statusPhase !=
camelContext.getCamelContextExtension().getStatusPhase()
|| (answered &&
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - statusWritten) >=
ANSWERED_STATUS_MS)) {
statusTask();
@@ -237,7 +244,13 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
return statusFile.exists();
}
- protected synchronized void actionTask() {
+ /**
+ * Writes the answers of the actions that are done, and runs the new
actions.
+ *
+ * @param list whether to list the directory also when its modification
time has not changed since it was last
+ * listed
+ */
+ protected synchronized void actionTask(boolean list) {
pending.entrySet().removeIf(entry -> {
File request = entry.getKey();
PendingAction action = entry.getValue();
@@ -251,10 +264,19 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
}
return false;
});
- // scan for all action files: {pid}-action.json (legacy) and
{pid}-action-{requestId}.json (multi-client)
File dir = lockFile.getParentFile();
+ // the time before the directory is looked at, see CLOCK_TICK_MS
+ long now = System.currentTimeMillis();
+ long modified = dir.lastModified();
+ if (!list && modified != 0 && modified == listed) {
+ // no file added since the last listing
+ return;
+ }
+ // the time is only remembered once a file added to the directory
would change it
+ listed = now - modified >= CLOCK_TICK_MS ? modified : 0;
+ // scan for all action files: {pid}-action.json (legacy) and
{pid}-action-{requestId}.json (multi-client)
String prefix = lockFile.getName() + "-action";
- File[] actionFiles = dir.listFiles((d, name) ->
name.startsWith(prefix) && name.endsWith(".json"));
+ File[] actionFiles = listActionFiles(dir, prefix);
if (actionFiles == null || actionFiles.length == 0) {
return;
}
@@ -273,6 +295,13 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
}
}
+ /**
+ * Lists the action files whose names start with the given prefix.
+ */
+ protected File[] listActionFiles(File dir, String prefix) {
+ return dir.listFiles((d, name) -> name.startsWith(prefix) &&
name.endsWith(".json"));
+ }
+
private void processAction(File af, File of, boolean replyAlways) {
String text = readAction(af);
if (text == null) {
@@ -295,7 +324,9 @@ public class FileCliConnectorTransport extends
ServiceSupport implements CliConn
}
if (root == null) {
if (System.currentTimeMillis() - af.lastModified() <
UNREADABLE_GRACE_MS) {
- // try again at the next poll, the file may still be written
+ // try again at the next poll, the file may still be written:
in place, which leaves the modification
+ // time of the directory as it is
+ listed = 0;
return;
}
if (invalid != null && replyAlways) {
diff --git
a/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/FileCliConnectorTransportTest.java
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/FileCliConnectorTransportTest.java
index dcc7ec644722..24629fb7e478 100644
---
a/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/FileCliConnectorTransportTest.java
+++
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/FileCliConnectorTransportTest.java
@@ -58,6 +58,7 @@ class FileCliConnectorTransportTest {
private DefaultCamelContext context;
private FileCliConnectorTransport transport;
private final EmptySnapshots snapshots = new EmptySnapshots();
+ private final AtomicInteger listings = new AtomicInteger();
@BeforeEach
void start() {
@@ -66,7 +67,13 @@ class FileCliConnectorTransportTest {
dir = home.resolve(".camel").toFile();
context = new DefaultCamelContext();
- transport = new FileCliConnectorTransport();
+ transport = new FileCliConnectorTransport() {
+ @Override
+ protected File[] listActionFiles(File dir, String prefix) {
+ listings.incrementAndGet();
+ return super.listActionFiles(dir, prefix);
+ }
+ };
transport.configure(context, FileCliConnectorTransportTest::dispatch,
snapshots, () -> {
});
transport.start();
@@ -107,7 +114,7 @@ class FileCliConnectorTransportTest {
@Test
void actionsAreAnsweredBetweenTwoStatusUpdates() {
- // CAMEL-25447: the status every second, as by default, and the
actions looked for about every 100 millis
+ // CAMEL-25447: the status every second, as by default, and the
actions looked for about every 20 millis
transport.updateDelay(1000);
awaitJson(file(PID + "-status.json"));
int statuses = snapshots.statuses.get();
@@ -155,6 +162,35 @@ class FileCliConnectorTransportTest {
await().atMost(5, TimeUnit.SECONDS).until(() ->
snapshots.statuses.get() > statuses);
}
+ @Test
+ void directoryIsOnlyListedBetweenTwoStatusUpdatesWhenAFileIsAdded() {
+ // CAMEL-26938: the actions are looked for about 50 times a second,
and listing the directory costs far more
+ // than looking at its modification time
+ transport.updateDelay(1000);
+ awaitSharedActionFileRemoved();
+ int before = listings.get();
+
+ // listed with every status, and after the status is moved in place,
which changes the directory
+ await().during(1, TimeUnit.SECONDS).atMost(3,
TimeUnit.SECONDS).until(() -> listings.get() - before < 15);
+
+ writeAction(action("result"), "r1");
+ assertThat(awaitJson(file(PID +
"-output-r1.json"))).containsEntry("value", "42");
+ }
+
+ @Test
+ void halfWrittenActionIsLookedForAtEveryPoll() throws Exception {
+ transport.updateDelay(1000);
+ awaitSharedActionFileRemoved();
+ File action = writeText("{\"action\":\"res", "r1");
+ int before = listings.get();
+
+ // the rest of it is written in place, which leaves the modification
time of the directory as it is
+ await().atMost(1, TimeUnit.SECONDS).until(() -> listings.get() -
before >= 10);
+ Files.writeString(action.toPath(), action("result").toJson());
+
+ assertThat(awaitJson(file(PID +
"-output-r1.json"))).containsEntry("value", "42");
+ }
+
@Test
void resultIsTheReply() {
writeAction(action("result"), "r1");
@@ -356,14 +392,20 @@ class FileCliConnectorTransportTest {
}
private void writeAction(JsonObject action, String requestId) {
- String name = requestId != null ? PID + "-action-" + requestId +
".json" : PID + "-action.json";
if (requestId == null) {
- // the connector creates an empty shared action file on start, and
removes it a little later
- await().atMost(10, TimeUnit.SECONDS).untilAsserted(() ->
assertThat(file(name)).doesNotExist());
+ awaitSharedActionFileRemoved();
}
writeText(action.toJson(), requestId);
}
+ /**
+ * The connector creates an empty shared action file on start, and removes
it a little later. Until then it lists
+ * the directory at every poll, as a Camel CLI before 4.21 writes its
action in that file, in place.
+ */
+ private void awaitSharedActionFileRemoved() {
+ await().atMost(10, TimeUnit.SECONDS).untilAsserted(() ->
assertThat(file(PID + "-action.json")).doesNotExist());
+ }
+
/**
* Writes the action atomically, as the Camel CLI does since 4.21 for
actions with a request id.
*/
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/ActionBaseCommand.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/ActionBaseCommand.java
index fcabf8b6750f..356709fb8402 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/ActionBaseCommand.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/ActionBaseCommand.java
@@ -64,18 +64,19 @@ abstract class ActionBaseCommand extends CamelCommand {
while (watch.taken() < timeout) {
File f = outputFile.toFile();
try {
- // give time for response to be ready
- Thread.sleep(100);
-
if (Files.exists(outputFile) && f.length() > 0) {
String text = Files.readString(outputFile);
return (JsonObject) Jsoner.deserialize(text);
}
+ } catch (Exception e) {
+ // not all written yet
+ }
+ try {
+ // give time for response to be ready
+ Thread.sleep(ActionClient.pollDelay(watch.taken()));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
- } catch (Exception e) {
- // ignore
}
}
return null;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ActionClient.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ActionClient.java
index 07c54b62a28b..57b59ee4b3fc 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ActionClient.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ActionClient.java
@@ -48,7 +48,9 @@ public final class ActionClient {
*/
public static final long DEFAULT_TIMEOUT = 10_000;
- private static final long POLL_INTERVAL = 100;
+ // the connector looks for actions about every 20 millis since Camel 4.24,
and every second before
+ private static final long MIN_POLL_INTERVAL = 5;
+ private static final long MAX_POLL_INTERVAL = 100;
private static final Pattern VERSION = Pattern.compile("^(\\d+)\\.(\\d+)");
/**
@@ -221,14 +223,19 @@ public final class ActionClient {
*/
public static String executeText(long pid, JsonObject request, long
timeout) throws IOException {
// the answer once it is all there, as an integration of an earlier
Camel version writes it in place
- // (CAMEL-26911): JSON once it parses, other text once it reads the
same at two polls
+ // (CAMEL-26911): JSON once it parses, other text once it has not
changed for 100 millis
AtomicReference<String> previous = new AtomicReference<>();
+ StopWatch unchanged = new StopWatch();
Exchange<String> exchange = exchange(pid, versionOf(pid), request,
timeout, true, text -> {
if (isJson(text)) {
return text;
}
boolean json = text.stripLeading().startsWith("{") ||
text.stripLeading().startsWith("[");
- return !json && text.equals(previous.getAndSet(text)) ? text :
null;
+ if (json || !text.equals(previous.getAndSet(text))) {
+ unchanged.restart();
+ return null;
+ }
+ return unchanged.taken() >= MAX_POLL_INTERVAL ? text : null;
});
if (exchange.stopped()) {
throw new StoppedException(pid, request.getString("action"));
@@ -284,7 +291,7 @@ public final class ActionClient {
StopWatch watch = new StopWatch();
while (watch.taken() < timeout) {
try {
- Thread.sleep(Math.min(POLL_INTERVAL, Math.max(1, timeout -
watch.taken())));
+ Thread.sleep(Math.min(pollDelay(watch.taken()),
Math.max(1, timeout - watch.taken())));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
@@ -312,6 +319,16 @@ public final class ActionClient {
}
}
+ /**
+ * How long to wait before looking again for an answer that is not there
yet: a tenth of the time waited so far,
+ * from 5 to 100 millis. An answer that arrives is read at the latest
after that delay.
+ *
+ * @param waited how long the answer has been waited for, in millis
+ */
+ public static long pollDelay(long waited) {
+ return Math.clamp(waited / 10, MIN_POLL_INTERVAL, MAX_POLL_INTERVAL);
+ }
+
private static <T> T readReply(Path outputFile, Function<String, T>
reader) {
try {
if (Files.exists(outputFile)) {
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeHelper.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeHelper.java
index ca976164a133..6108c4a84fff 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeHelper.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeHelper.java
@@ -44,7 +44,6 @@ import org.apache.camel.util.json.Jsoner;
public final class RuntimeHelper {
private static final long ACTION_TIMEOUT_MS = 10_000;
- private static final long POLL_INTERVAL_MS = 100;
/**
* Information about a discovered running Camel process.
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java
index d08a7795f167..0d5b5029dcfe 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/ActionClientTest.java
@@ -281,6 +281,38 @@ class ActionClientTest {
assertThat(ActionClient.executeText(PID, request,
5000)).isEqualTo(answer);
}
+ @Test
+ void textThatIsNotJsonIsReadOnceItNoLongerChanges() throws Exception {
+ Files.writeString(CommandLineHelper.getCamelDir().resolve(PID +
"-status.json"),
+ "{\"context\":{\"version\":\"4.23.0\"}}");
+ executor.submit(() -> {
+ Path dir = CommandLineHelper.getCamelDir();
+ Path request = await().pollInterval(1,
TimeUnit.MILLISECONDS).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"),
"Route route1 started");
+ Files.delete(request);
+ return null;
+ });
+
+ JsonObject request = new JsonObject();
+ request.put("action", "route");
+ StopWatch watch = new StopWatch();
+ assertThat(ActionClient.executeText(PID, request,
5000)).isEqualTo("Route route1 started");
+ // an integration of an earlier Camel version writes it in place, and
the answer is looked for every 5 millis
+ assertThat(watch.taken()).isGreaterThanOrEqualTo(100);
+ }
+
+ @Test
+ void answerIsLookedForSoonAndThenLessOften() {
+ // the connector looks for the action about every 20 millis
+ assertThat(ActionClient.pollDelay(0)).isEqualTo(5);
+ assertThat(ActionClient.pollDelay(80)).isEqualTo(8);
+ // an action that takes longer, such as a message sent to a slow
route, is not looked for 200 times a second
+ assertThat(ActionClient.pollDelay(500)).isEqualTo(50);
+ assertThat(ActionClient.pollDelay(60_000)).isEqualTo(100);
+ }
+
@Test
void errorMessageComesFromTheAnswer() {
assertThat(ActionClient.result(json("{\"status\":\"error\",\"exception\":{\"message\":\"Forced\"}}")).error())