This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 6fcb3e00abfc [backport camel-4.18.x] CAMEL-27868: camel-dataset: fix
minRate makes assertIsSatisfied loop forever, dataset-test timeout fails with a
duration value (#31176)
6fcb3e00abfc is described below
commit 6fcb3e00abfcaa3193621204fa43f7d1be05ea42
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Dec 1 19:07:07 2026 +0100
[backport camel-4.18.x] CAMEL-27868: camel-dataset: fix minRate makes
assertIsSatisfied loop forever, dataset-test timeout fails with a duration
value (#31176)
* [backport camel-4.18.x] CAMEL-27868: camel-dataset: fix minRate makes
assertIsSatisfied loop forever, dataset-test timeout fails with a duration value
* CAMEL-27868: camel-dataset: lower minRate from 10 to 1 in
DataSetMinRateTest
minRate=1 is sufficient to trigger the original bug (the alternating delta
between x and 200-x stays >= 1, so the unfixed loop spins indefinitely),
while avoiding CI flakiness caused by GC pauses dropping a 1-second window
below the old minRate=10 threshold and letting the loop exit early.
* CAMEL-27868: camel-dataset: add missing trailing newline in
DataSetMinRateTest
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---------
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: Claus Ibsen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel/component/dataset/DataSetEndpoint.java | 9 +-
.../component/dataset/DataSetTestComponent.java | 4 -
.../component/dataset/DataSetMinRateTest.java | 78 +++++++++++
.../dataset/DataSetTestTimeoutDurationTest.java | 149 +++++++++++++++++++++
4 files changed, 233 insertions(+), 7 deletions(-)
diff --git
a/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
b/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
index f05140e174d2..b64d9caee659 100644
---
a/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
+++
b/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
@@ -139,12 +139,15 @@ public class DataSetEndpoint extends MockEndpoint
implements Service {
super.waitForCompleteLatch(timeout);
if (minRate > 0) {
- int count = getReceivedCounter();
+ int prev = getReceivedCounter();
+ int delta;
do {
// wait as long as we get a decent message rate
super.waitForCompleteLatch(1000L);
- count = getReceivedCounter() - count;
- } while (count >= minRate);
+ int curr = getReceivedCounter();
+ delta = curr - prev;
+ prev = curr;
+ } while (delta >= minRate);
}
}
diff --git
a/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetTestComponent.java
b/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetTestComponent.java
index 44064483b2a0..4bf595d1ee67 100644
---
a/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetTestComponent.java
+++
b/components/camel-dataset/src/main/java/org/apache/camel/component/dataset/DataSetTestComponent.java
@@ -38,11 +38,7 @@ public class DataSetTestComponent extends MockComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
- Long timeout = getAndRemoveParameter(parameters, "timeout",
Long.class);
DataSetTestEndpoint answer = new DataSetTestEndpoint(uri, this);
- if (timeout != null) {
- answer.setTimeout(timeout);
- }
answer.setLog(isLog());
setProperties(answer, parameters);
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetMinRateTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetMinRateTest.java
new file mode 100644
index 000000000000..d50a85f66f40
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetMinRateTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dataset;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+/**
+ * Regression test for CAMEL-27868: DataSetEndpoint.waitForCompleteLatch()
with minRate > 0 used to overwrite the
+ * message-count snapshot with the delta on each iteration, causing an
infinite busy-spin once all messages had been
+ * delivered and the latch reached zero.
+ * <p>
+ * The dataset is large enough and the produce delay slow enough that the
initial resultWaitTime elapses before all
+ * messages arrive, forcing the minRate loop to execute. With the old code
that loop would spin forever; with the fix it
+ * exits once the per-second delta drops below minRate.
+ */
+@Timeout(30)
+class DataSetMinRateTest extends ContextTestSupport {
+
+ // 200 messages at 10 ms each take ~2 s to deliver; resultWaitTime=100 ms
ensures
+ // the initial latch wait expires before all messages have arrived, so the
minRate
+ // loop is actually exercised.
+ private final SimpleDataSet dataSet = new SimpleDataSet(200);
+
+ @Override
+ protected Registry createCamelRegistry() throws Exception {
+ Registry registry = super.createCamelRegistry();
+ registry.bind("foo", dataSet);
+ return registry;
+ }
+
+ /**
+ * Verifies that assertIsSatisfied() terminates once all messages have
been received, even when minRate is set.
+ * Before the fix the snapshot variable {@code count} was overwritten with
the delta on every iteration, so after
+ * messages stopped arriving the loop never exited. The {@code
@Timeout(30)} annotation causes the test to fail
+ * (instead of hanging the fork) if the bug is re-introduced.
+ */
+ @Test
+ void testMinRateTerminatesWhenAllMessagesReceived() throws Exception {
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ // produceDelay=10 ms per message; resultWaitTime=100 ms
expires before all
+ // 200 messages arrive, so the minRate loop runs at least once.
+ // minRate=1: sufficient to trigger the original bug (the
alternating delta between
+ // x and 200-x stays >= 1, so the unfixed loop spins
indefinitely), while
+ // avoiding CI flakiness caused by GC pauses dropping a
1-second window below
+ // the old minRate=10 threshold and letting the loop exit
early.
+
from("dataset:foo?initialDelay=0&produceDelay=10&resultWaitTime=100&minRate=1")
+ .to("direct:foo");
+ from("direct:foo")
+
.to("dataset:foo?initialDelay=0&produceDelay=10&resultWaitTime=100&minRate=1");
+ }
+ };
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTestTimeoutDurationTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTestTimeoutDurationTest.java
new file mode 100644
index 000000000000..da75806e7559
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTestTimeoutDurationTest.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dataset;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Regression test for CAMEL-27868: DataSetTestComponent used to extract the
{@code timeout} URI parameter as
+ * {@code Long.class} via {@code getAndRemoveParameter()}, which rejected
duration strings like {@code "2s"} accepted by
+ * the catalog (declared as {@code javaType = "java.time.Duration"}). The fix
lets {@code setProperties()} resolve the
+ * parameter through Camel's type converter, which handles both plain
millisecond values and Camel time-pattern strings
+ * (e.g. {@code "2s"}, {@code "1m"}).
+ */
+class DataSetTestTimeoutDurationTest extends ContextTestSupport {
+
+ private final String expectedBody = "Hello World";
+
+ /**
+ * Verifies that a duration string (e.g. {@code "2s"}) is accepted for the
{@code timeout} parameter of the
+ * {@code dataset-test} component. Before the fix this caused a {@code
NumberFormatException} at endpoint creation
+ * time because the raw string was coerced directly to {@code Long}.
+ */
+ @Test
+ void testTimeoutAcceptsDurationString() throws Exception {
+ // dataset-test:my:foo?timeout=2s — "2s" must be accepted (2000 ms)
+ DataSetTestEndpoint endpoint
+ = context.getEndpoint("dataset-test:my:foo?timeout=2s",
DataSetTestEndpoint.class);
+ assertEquals(2000L, endpoint.getTimeout(), "timeout=2s should resolve
to 2000 ms");
+ }
+
+ /**
+ * Verifies that a plain millisecond value still works after the fix.
+ */
+ @Test
+ void testTimeoutAcceptsMilliseconds() throws Exception {
+ DataSetTestEndpoint endpoint
+ = context.getEndpoint("dataset-test:my:foo?timeout=1500",
DataSetTestEndpoint.class);
+ assertEquals(1500L, endpoint.getTimeout(), "timeout=1500 should
resolve to 1500 ms");
+ }
+
+ /**
+ * End-to-end test using a duration string on the URI — the route must
start and complete normally.
+ */
+ @Test
+ void testMocksAreValidWithDurationTimeout() throws Exception {
+ template.sendBody("seda:bar", expectedBody);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ MyEndpoint my = new MyEndpoint("my:foo", context);
+ context.addEndpoint("my:foo", my);
+
+ // timeout expressed as a duration string — must not throw at
startup
+ from("seda:bar").to("dataset-test:my:foo?timeout=1s");
+ }
+ };
+ }
+
+ private final class MyEndpoint extends DefaultEndpoint {
+
+ private MyEndpoint(String endpointUri, CamelContext camelContext) {
+ super(endpointUri, null);
+ setCamelContext(camelContext);
+ }
+
+ @Override
+ public Producer createProducer() {
+ return null;
+ }
+
+ @Override
+ public Consumer createConsumer(final Processor processor) {
+ return new Consumer() {
+ @Override
+ public Endpoint getEndpoint() {
+ return MyEndpoint.this;
+ }
+
+ @Override
+ public Processor getProcessor() {
+ return null;
+ }
+
+ @Override
+ public Exchange createExchange(boolean autoRelease) {
+ return DefaultExchange.newFromEndpoint(getEndpoint());
+ }
+
+ @Override
+ public void releaseExchange(Exchange exchange, boolean
autoRelease) {
+ // noop
+ }
+
+ @Override
+ public void start() {
+ Exchange exchange = createExchange(false);
+ exchange.getIn().setBody(expectedBody);
+ try {
+ processor.process(exchange);
+ } catch (Exception e) {
+ throw
RuntimeCamelException.wrapRuntimeCamelException(e);
+ }
+ }
+
+ @Override
+ public void stop() {
+ // noop
+ }
+ };
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+ }
+}