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 576717d0e383 CAMEL-25882: camel-cassandraql - Speed up tests by
sharing one Cassandra container
576717d0e383 is described below
commit 576717d0e383091c7d2fa4a70422ada63bf79be9
Author: Aurélien Pupier <[email protected]>
AuthorDate: Wed Dec 2 10:54:10 2026 +0100
CAMEL-25882: camel-cassandraql - Speed up tests by sharing one Cassandra
container
Every IT class of the module started its own Cassandra container
(14 starts, 4-8s each). Use a singleton service shared by all the test
classes of the JVM instead:
- CassandraServiceFactory: new createSingletonService(initScript), the
init script is applied once when the container starts
- BaseCassandra: use the shared service
- BasicDataSet.cql: truncate all the tables used by the tests before each
test, so the classes do not see the data of each other
Measured with `mvn verify -Pit -pl components/camel-cassandraql`, sampling
once per second the RSS of the forked failsafe JVM and the memory of the
containers (podman stats), 94 tests passing in both cases:
before after
wall time of the build 123 s 63 s
Cassandra container starts 14 1
time a Cassandra container is up 90 s 42 s
container memory, peak 1535 MB 1590 MB
container memory, average 1385 MB 1522 MB
test JVM RSS, peak / average 409/353 MB 360/311 MB
test JVM + containers, peak 1944 MB 1942 MB
The peak memory is unchanged: before, two containers overlapped while the
previous one was stopping. The memory is held for half as long.
Co-authored-by: IBM Bob <[email protected]>
---
.../cassandra/integration/BaseCassandra.java | 2 +-
.../src/test/resources/BasicDataSet.cql | 6 ++++++
.../cassandra/services/CassandraServiceFactory.java | 21 +++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git
a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/integration/BaseCassandra.java
b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/integration/BaseCassandra.java
index f5721e311b44..c9c41687d988 100644
---
a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/integration/BaseCassandra.java
+++
b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/integration/BaseCassandra.java
@@ -43,7 +43,7 @@ public abstract class BaseCassandra implements
ConfigurableRoute, CamelTestSuppo
@Order(1)
@RegisterExtension
- public static CassandraService service =
CassandraServiceFactory.createLocalService("initScript.cql");
+ public static CassandraService service =
CassandraServiceFactory.createSingletonService("initScript.cql");
@Order(2)
@RegisterExtension
diff --git a/components/camel-cassandraql/src/test/resources/BasicDataSet.cql
b/components/camel-cassandraql/src/test/resources/BasicDataSet.cql
index f77e9470f842..ed2f680cbd68 100644
--- a/components/camel-cassandraql/src/test/resources/BasicDataSet.cql
+++ b/components/camel-cassandraql/src/test/resources/BasicDataSet.cql
@@ -15,7 +15,13 @@
-- limitations under the License.
--
+-- the Cassandra container is shared by all the test classes: start each test
from empty tables
TRUNCATE camel_user;
+TRUNCATE NAMED_CAMEL_AGGREGATION;
+TRUNCATE NAMED_CAMEL_IDEMPOTENT;
+TRUNCATE CAMEL_IDEMPOTENT;
+TRUNCATE CAMEL_AGGREGATION;
+TRUNCATE camel_keyvalue;
INSERT INTO camel_user(login, first_name, last_name)
VALUES('j_strachan','James','Strachan');
diff --git
a/test-infra/camel-test-infra-cassandra/src/main/java/org/apache/camel/test/infra/cassandra/services/CassandraServiceFactory.java
b/test-infra/camel-test-infra-cassandra/src/main/java/org/apache/camel/test/infra/cassandra/services/CassandraServiceFactory.java
index 9418a9bba8ee..94b855f71a02 100644
---
a/test-infra/camel-test-infra-cassandra/src/main/java/org/apache/camel/test/infra/cassandra/services/CassandraServiceFactory.java
+++
b/test-infra/camel-test-infra-cassandra/src/main/java/org/apache/camel/test/infra/cassandra/services/CassandraServiceFactory.java
@@ -16,6 +16,9 @@
*/
package org.apache.camel.test.infra.cassandra.services;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
import org.apache.camel.test.infra.common.services.SingletonService;
@@ -75,6 +78,24 @@ public final class CassandraServiceFactory {
return SingletonServiceHolder.INSTANCE;
}
+ /**
+ * Creates a Cassandra service shared by all the test classes of the JVM,
whose container executes the given init
+ * script when it starts. The same instance is returned for the same init
script.
+ *
+ * @param initScript the classpath resource of the CQL script to execute
when the container starts
+ */
+ public static CassandraService createSingletonService(String initScript) {
+ return SINGLETONS_WITH_INIT_SCRIPT.computeIfAbsent(initScript, script
-> {
+ SimpleTestServiceBuilder<CassandraService> instance = builder();
+ instance.addLocalMapping(() -> new SingletonCassandraService(
+ createLocalService(script), "cassandra-" + script))
+ .addRemoteMapping(RemoteCassandraService::new);
+ return instance.build();
+ });
+ }
+
+ private static final Map<String, CassandraService>
SINGLETONS_WITH_INIT_SCRIPT = new ConcurrentHashMap<>();
+
private static class SingletonServiceHolder {
static final CassandraService INSTANCE;
static {