This is an automated email from the ASF dual-hosted git repository.
apupier 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 09145be223b6 CAMEL-26381: Fix flaky ConsulMasterIT by using a
dedicated namespace per cluster IT
09145be223b6 is described below
commit 09145be223b6e6e4720360280666bb94e6ed3b54
Author: Aurélien Pupier <[email protected]>
AuthorDate: Thu Nov 5 11:44:28 2026 +0100
CAMEL-26381: Fix flaky ConsulMasterIT by using a dedicated namespace per
cluster IT
ConsulMasterIT, ConsulClusteredRoutePolicyIT and
ConsulClusteredRoutePolicyFactoryIT all used the namespace "my-ns" while
sharing the same singleton Consul container. A lock (or its lock-delay)
left on that key by one test could keep the nodes of another one from
taking the leadership, so no node completed within the 1 minute wait and
the assertion failed with "expected: <3> but was: <0>".
- Use a specific namespace for each of the three tests
- Use a thread-safe list for the results, which are added from several
scheduler threads
- Stop the CamelContext of a node in a finally block: when the test gives
up waiting, the interrupted node skipped context.stop() and kept running
and holding the lock
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../cluster/ConsulClusteredRoutePolicyFactoryIT.java | 11 +++++++----
.../consul/cluster/ConsulClusteredRoutePolicyIT.java | 12 ++++++++----
.../camel/component/consul/cluster/ConsulMasterIT.java | 15 +++++++++++----
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryIT.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryIT.java
index 026a6fb0a34f..71b60cdaa597 100644
---
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryIT.java
+++
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryIT.java
@@ -16,8 +16,8 @@
*/
package org.apache.camel.component.consul.cluster;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -43,7 +43,7 @@ public class ConsulClusteredRoutePolicyFactoryIT {
private static final Logger LOGGER =
LoggerFactory.getLogger(ConsulClusteredRoutePolicyFactoryIT.class);
private static final List<String> CLIENTS = IntStream.range(0,
3).mapToObj(Integer::toString).toList();
- private static final List<String> RESULTS = new ArrayList<>();
+ private static final List<String> RESULTS = new CopyOnWriteArrayList<>();
private static final ScheduledExecutorService SCHEDULER =
Executors.newScheduledThreadPool(CLIENTS.size() * 2);
private static final CountDownLatch LATCH = new
CountDownLatch(CLIENTS.size());
@@ -69,6 +69,7 @@ public class ConsulClusteredRoutePolicyFactoryIT {
// ************************************
private static void run(String id) {
+ DefaultCamelContext context = new DefaultCamelContext();
try {
int events = ThreadLocalRandom.current().nextInt(2, 6);
CountDownLatch contextLatch = new CountDownLatch(events);
@@ -79,11 +80,10 @@ public class ConsulClusteredRoutePolicyFactoryIT {
LOGGER.info("Consul URL {}", consulClusterService.getUrl());
- DefaultCamelContext context = new DefaultCamelContext();
context.disableJMX();
context.getCamelContextExtension().setName("context-" + id);
context.addService(consulClusterService);
-
context.addRoutePolicyFactory(ClusteredRoutePolicyFactory.forNamespace("my-ns"));
+
context.addRoutePolicyFactory(ClusteredRoutePolicyFactory.forNamespace("consul-clustered-route-policy-factory-it"));
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
@@ -110,6 +110,9 @@ public class ConsulClusteredRoutePolicyFactoryIT {
LATCH.countDown();
} catch (Exception e) {
LOGGER.warn("{}", e.getMessage(), e);
+ } finally {
+ // also when the test gave up waiting, so that this node does not
keep running and holding the lock
+ context.stop();
}
}
}
diff --git
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyIT.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyIT.java
index cd9ce9e59ea4..5c413aa8a7a5 100644
---
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyIT.java
+++
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyIT.java
@@ -16,8 +16,8 @@
*/
package org.apache.camel.component.consul.cluster;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -43,7 +43,7 @@ public class ConsulClusteredRoutePolicyIT {
private static final Logger LOGGER =
LoggerFactory.getLogger(ConsulClusteredRoutePolicyIT.class);
private static final List<String> CLIENTS = IntStream.range(0,
3).mapToObj(Integer::toString).toList();
- private static final List<String> RESULTS = new ArrayList<>();
+ private static final List<String> RESULTS = new CopyOnWriteArrayList<>();
private static final ScheduledExecutorService SCHEDULER =
Executors.newScheduledThreadPool(CLIENTS.size() * 2);
private static final CountDownLatch LATCH = new
CountDownLatch(CLIENTS.size());
@@ -69,6 +69,7 @@ public class ConsulClusteredRoutePolicyIT {
// ************************************
private static void run(String id) {
+ DefaultCamelContext context = new DefaultCamelContext();
try {
int events = ThreadLocalRandom.current().nextInt(2, 6);
CountDownLatch contextLatch = new CountDownLatch(events);
@@ -79,7 +80,6 @@ public class ConsulClusteredRoutePolicyIT {
LOGGER.info("Consul URL {}", consulClusterService.getUrl());
- DefaultCamelContext context = new DefaultCamelContext();
context.disableJMX();
context.getCamelContextExtension().setName("context-" + id);
context.addService(consulClusterService);
@@ -87,7 +87,8 @@ public class ConsulClusteredRoutePolicyIT {
@Override
public void configure() throws Exception {
from("timer:consul?delay=1000&period=1000").routeId("route-" + id)
-
.routePolicy(ClusteredRoutePolicy.forNamespace("my-ns")).log("From ${routeId}")
+
.routePolicy(ClusteredRoutePolicy.forNamespace("consul-clustered-route-policy-it"))
+ .log("From ${routeId}")
.process(e -> contextLatch.countDown());
}
});
@@ -108,6 +109,9 @@ public class ConsulClusteredRoutePolicyIT {
LATCH.countDown();
} catch (Exception e) {
LOGGER.warn("{}", e.getMessage(), e);
+ } finally {
+ // also when the test gave up waiting, so that this node does not
keep running and holding the lock
+ context.stop();
}
}
}
diff --git
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulMasterIT.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulMasterIT.java
index 8ab5b02dab65..a886c0878516 100644
---
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulMasterIT.java
+++
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulMasterIT.java
@@ -16,8 +16,8 @@
*/
package org.apache.camel.component.consul.cluster;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -41,8 +41,11 @@ public class ConsulMasterIT {
public static ConsulService service =
ConsulServiceFactory.createSingletonService();
private static final Logger LOGGER =
LoggerFactory.getLogger(ConsulMasterIT.class);
+ // own namespace: the Consul service is shared with the other integration
tests of this module, a lock left by one
+ // of them on the same key would keep these nodes from taking the
leadership
+ private static final String NAMESPACE = "consul-master-it";
private static final List<String> CLIENTS = IntStream.range(0,
3).mapToObj(Integer::toString).toList();
- private static final List<String> RESULTS = new ArrayList<>();
+ private static final List<String> RESULTS = new CopyOnWriteArrayList<>();
private static final ScheduledExecutorService SCHEDULER =
Executors.newScheduledThreadPool(CLIENTS.size() * 2);
private static final CountDownLatch LATCH = new
CountDownLatch(CLIENTS.size());
@@ -68,6 +71,7 @@ public class ConsulMasterIT {
// ************************************
private static void run(String id) {
+ DefaultCamelContext context = new DefaultCamelContext();
try {
int events = ThreadLocalRandom.current().nextInt(2, 6);
CountDownLatch contextLatch = new CountDownLatch(events);
@@ -78,14 +82,14 @@ public class ConsulMasterIT {
LOGGER.info("Consul URL {}", consulClusterService.getUrl());
- DefaultCamelContext context = new DefaultCamelContext();
context.disableJMX();
context.getCamelContextExtension().setName("context-" + id);
context.addService(consulClusterService);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
-
from("master:my-ns:timer:consul?delay=1000&period=1000").routeId("route-" +
id).log("From ${routeId}")
+ from("master:" + NAMESPACE +
":timer:consul?delay=1000&period=1000").routeId("route-" + id)
+ .log("From ${routeId}")
.process(e -> contextLatch.countDown());
}
});
@@ -106,6 +110,9 @@ public class ConsulMasterIT {
LATCH.countDown();
} catch (Exception e) {
LOGGER.warn("{}", e.getMessage(), e);
+ } finally {
+ // also when the test gave up waiting, so that this node does not
keep running and holding the lock
+ context.stop();
}
}
}