This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new a0a4bf4ca8 Enable Mongo tests to run with container image versions <
7.x
a0a4bf4ca8 is described below
commit a0a4bf4ca8d599eac0eb34cd9b3dbb49d68a5b10
Author: James Netherton <[email protected]>
AuthorDate: Mon Nov 18 08:49:31 2024 +0000
Enable Mongo tests to run with container image versions < 7.x
---
.../test/support/mongodb/MongoDbTestResource.java | 4 +-
.../support/mongodb/MongoDbTestSupportUtils.java | 46 ++++++++++++++++++++++
integration-tests/debezium/pom.xml | 2 +-
.../it/mongodb/DebeziumMongodbTestResource.java | 5 ++-
4 files changed, 54 insertions(+), 3 deletions(-)
diff --git
a/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestResource.java
b/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestResource.java
index 5a2313ca6d..86e326a3cc 100644
---
a/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestResource.java
+++
b/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestResource.java
@@ -36,6 +36,8 @@ import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.TestcontainersConfiguration;
+import static
org.apache.camel.quarkus.test.support.mongodb.MongoDbTestSupportUtils.getMongoScriptExecutable;
+
public class MongoDbTestResource implements
QuarkusTestResourceLifecycleManager {
private static final Logger LOGGER =
LoggerFactory.getLogger(MongoDbTestResource.class);
@@ -104,7 +106,7 @@ public class MongoDbTestResource implements
QuarkusTestResourceLifecycleManager
String[] cmds = cmd.split("\\n\\n");
for (int i = 0; i < cmds.length; i++) {
- Container.ExecResult er = container.execInContainer(new String[] {
"mongosh", "--eval", cmds[i] });
+ Container.ExecResult er =
container.execInContainer(getMongoScriptExecutable(MONGO_IMAGE), "--eval",
cmds[i]);
if (er.getExitCode() != 0) {
throw new IllegalStateException("Exec exit code " +
er.getExitCode() + ". " + er.getStderr());
}
diff --git
a/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestSupportUtils.java
b/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestSupportUtils.java
new file mode 100644
index 0000000000..357633852a
--- /dev/null
+++
b/integration-tests-support/mongodb/src/main/java/org/apache/camel/quarkus/test/support/mongodb/MongoDbTestSupportUtils.java
@@ -0,0 +1,46 @@
+/*
+ * 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.quarkus.test.support.mongodb;
+
+public class MongoDbTestSupportUtils {
+ private MongoDbTestSupportUtils() {
+ // Utility class
+ }
+
+ public static String getMongoScriptExecutable(String imageName) {
+ int major = getMongoMajorVersion(imageName);
+ if (major < 6) {
+ return "mongo";
+ }
+ return "mongosh";
+ }
+
+ static int getMongoMajorVersion(String imageName) {
+ String[] imageNameParts = imageName.split(":");
+ if (imageNameParts.length == 1) {
+ // Assume it's an image name without a tag. E.g 'latest'.
+ return 999;
+ }
+
+ String[] versionParts = imageNameParts[1].split("\\.");
+ if (versionParts.length == 0) {
+ throw new IllegalArgumentException("Invalid image version: " +
imageName);
+ }
+
+ return Integer.parseInt(versionParts[0]);
+ }
+}
diff --git a/integration-tests/debezium/pom.xml
b/integration-tests/debezium/pom.xml
index 2d17ddf120..279751669e 100644
--- a/integration-tests/debezium/pom.xml
+++ b/integration-tests/debezium/pom.xml
@@ -121,7 +121,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-integration-test-support</artifactId>
+
<artifactId>camel-quarkus-integration-tests-support-mongodb</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git
a/integration-tests/debezium/src/test/java/org/apache/camel/quarkus/component/debezium/common/it/mongodb/DebeziumMongodbTestResource.java
b/integration-tests/debezium/src/test/java/org/apache/camel/quarkus/component/debezium/common/it/mongodb/DebeziumMongodbTestResource.java
index 713c4b482f..9741957356 100644
---
a/integration-tests/debezium/src/test/java/org/apache/camel/quarkus/component/debezium/common/it/mongodb/DebeziumMongodbTestResource.java
+++
b/integration-tests/debezium/src/test/java/org/apache/camel/quarkus/component/debezium/common/it/mongodb/DebeziumMongodbTestResource.java
@@ -33,6 +33,8 @@ import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
+import static
org.apache.camel.quarkus.test.support.mongodb.MongoDbTestSupportUtils.getMongoScriptExecutable;
+
public class DebeziumMongodbTestResource extends
AbstractDebeziumTestResource<GenericContainer<?>> {
private static final Logger LOG =
Logger.getLogger(AbstractDebeziumTestResource.class);
private static final String PRIVATE_HOST = "mongodb_private";
@@ -79,7 +81,8 @@ public class DebeziumMongodbTestResource extends
AbstractDebeziumTestResource<Ge
String script = IOUtils.toString(resource, StandardCharsets.UTF_8);
script = script.replace("%container-host%", getHostPort());
for (String cmd : script.split("\\n\\n")) {
- Container.ExecResult er = container.execInContainer("mongosh",
"--port", String.valueOf(DB_PORT), "--eval", cmd);
+ Container.ExecResult er =
container.execInContainer(getMongoScriptExecutable(MONGO_IMAGE_NAME), "--port",
+ String.valueOf(DB_PORT), "--eval", cmd);
if (er.getExitCode() != 0) {
LOG.errorf("Error executing MongoDB command: %s", cmd);
LOG.error(er.getStdout());