diff --git a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorIT.java b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorIT.java index 65e697c107b..22d859a3c2f 100644 --- a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorIT.java +++ b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorIT.java @@ -77,7 +77,7 @@ private Configuration.Builder mongodbSinkConfig() { } default void startSink(Function custConfig) { - TestInfrastructureHelper.setupDebeziumContainer(Module.version(), null); + TestInfrastructureHelper.setupDebeziumContainer(Module.version(), null, TestInfrastructureHelper.parseDebeziumVersion(Module.version())); TestInfrastructureHelper.startContainers(DATABASE.DEBEZIUM_ONLY); final Configuration config = custConfig.apply(mongodbSinkConfig()).build(); TestInfrastructureHelper.getDebeziumContainer().registerConnector(SINK_CONNECTOR_NAME, ConnectorConfiguration.from(config.asMap())); diff --git a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorReplicaSetIT.java b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorReplicaSetIT.java index d3741b33ab0..a5d5726b9cb 100644 --- a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorReplicaSetIT.java +++ b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorReplicaSetIT.java @@ -15,10 +15,12 @@ import io.debezium.connector.mongodb.AbstractMongoConnectorIT; import io.debezium.connector.mongodb.sink.junit.NetworkIsolatedMongoDbDatabaseProvider; +import io.debezium.junit.RequiresAssemblyProfile; import io.debezium.testing.testcontainers.MongoDbDeployment; import io.debezium.testing.testcontainers.testhelper.TestInfrastructureHelper; import io.debezium.testing.testcontainers.util.DockerUtils; +@RequiresAssemblyProfile public class SinkConnectorReplicaSetIT extends AbstractMongoConnectorIT implements SinkConnectorIT { protected static MongoDbDeployment mongo; diff --git a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorShardedClusterIT.java b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorShardedClusterIT.java index 8eed6c424cf..8775b6c9c91 100644 --- a/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorShardedClusterIT.java +++ b/debezium-connector-mongodb/src/test/java/io/debezium/connector/mongodb/sink/SinkConnectorShardedClusterIT.java @@ -15,11 +15,13 @@ import io.debezium.connector.mongodb.AbstractShardedMongoConnectorIT; import io.debezium.connector.mongodb.sink.junit.NetworkIsolatedMongoDbDatabaseProvider; +import io.debezium.junit.RequiresAssemblyProfile; import io.debezium.testing.testcontainers.MongoDbDeployment; import io.debezium.testing.testcontainers.MongoDbShardedCluster; import io.debezium.testing.testcontainers.testhelper.TestInfrastructureHelper; import io.debezium.testing.testcontainers.util.DockerUtils; +@RequiresAssemblyProfile public class SinkConnectorShardedClusterIT extends AbstractShardedMongoConnectorIT implements SinkConnectorIT { protected static MongoDbDeployment mongo; diff --git a/debezium-core/src/test/java/io/debezium/junit/AnnotationBasedTestRule.java b/debezium-core/src/test/java/io/debezium/junit/AnnotationBasedTestRule.java index e45154f57f9..d3a147a76b0 100644 --- a/debezium-core/src/test/java/io/debezium/junit/AnnotationBasedTestRule.java +++ b/debezium-core/src/test/java/io/debezium/junit/AnnotationBasedTestRule.java @@ -24,12 +24,12 @@ protected static Statement emptyStatement(final String reason, final Description @Override public void evaluate() throws Throwable { StringBuilder messageBuilder = new StringBuilder(description.testCount()); - messageBuilder.append("Skipped ").append(description.toString()); + messageBuilder.append("Skipped ").append(description); if (reason != null && !reason.trim().isEmpty()) { messageBuilder.append(" because: ").append(reason); } - System.out.println(messageBuilder.toString()); + System.out.println(messageBuilder); } }; } diff --git a/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfile.java b/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfile.java new file mode 100644 index 00000000000..172fb2452b2 --- /dev/null +++ b/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfile.java @@ -0,0 +1,29 @@ +/* + * Copyright Debezium Authors. + * + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package io.debezium.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker annotation used to group tests that require the assembly profile, using the {@code isAssemblyProfileActive} system property. + * + * @author René Kerner + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface RequiresAssemblyProfile { + + String REQUIRES_ASSEMBLY_PROFILE_PROPERTY = "isAssemblyProfileActive"; + + /** + * The optional reason why the test is skipped. + * @return the reason why the test is skipped + */ + String value() default "Maven 'assembly' profile required (use '-Passembly' to enable assembly profile)"; +} diff --git a/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfileTestRule.java b/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfileTestRule.java new file mode 100644 index 00000000000..39c97d2a0cf --- /dev/null +++ b/debezium-core/src/test/java/io/debezium/junit/RequiresAssemblyProfileTestRule.java @@ -0,0 +1,32 @@ +/* + * Copyright Debezium Authors. + * + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package io.debezium.junit; + +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * JUnit rule that inspects the presence of the {@link RequiresAssemblyProfile} annotation either on a test method or on a test suite. If + * it finds the annotation, it will only run the test method/suite if the system property {@code isAssemblyProfileActive} has the + * value {@code true} + * + * @author René Kerner + */ +public class RequiresAssemblyProfileTestRule extends AnnotationBasedTestRule { + + @Override + public Statement apply(Statement base, Description description) { + RequiresAssemblyProfile requiresAssemblyProfileAnnotation = hasAnnotation(description, RequiresAssemblyProfile.class); + if (requiresAssemblyProfileAnnotation != null) { + String requiresAssemblyProfile = System.getProperty(RequiresAssemblyProfile.REQUIRES_ASSEMBLY_PROFILE_PROPERTY, "false"); + if (!Boolean.parseBoolean(requiresAssemblyProfile)) { + return emptyStatement(requiresAssemblyProfileAnnotation.value(), description); + } + } + return base; + } + +} diff --git a/debezium-embedded/src/test/java/io/debezium/embedded/AbstractConnectorTest.java b/debezium-embedded/src/test/java/io/debezium/embedded/AbstractConnectorTest.java index 981b4357de0..b252f751a9e 100644 --- a/debezium-embedded/src/test/java/io/debezium/embedded/AbstractConnectorTest.java +++ b/debezium-embedded/src/test/java/io/debezium/embedded/AbstractConnectorTest.java @@ -62,6 +62,7 @@ import org.awaitility.core.ConditionTimeoutException; import org.junit.After; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.rules.TestRule; import org.slf4j.Logger; @@ -72,6 +73,7 @@ import io.debezium.data.VerifyRecord; import io.debezium.engine.DebeziumEngine; import io.debezium.function.BooleanConsumer; +import io.debezium.junit.RequiresAssemblyProfileTestRule; import io.debezium.junit.SkipTestRule; import io.debezium.junit.TestLogger; import io.debezium.pipeline.txmetadata.TransactionStatus; @@ -93,9 +95,15 @@ */ public abstract class AbstractConnectorTest implements Testing { + @ClassRule + public static TestRule requiresAssemblyProfileClassRule = new RequiresAssemblyProfileTestRule(); + @Rule public TestRule skipTestRule = new SkipTestRule(); + @Rule + public TestRule requiresAssemblyProfileRule = new RequiresAssemblyProfileTestRule(); + protected static final Path OFFSET_STORE_PATH = Testing.Files.createTestingPath("file-connector-offsets.txt").toAbsolutePath(); private static final String TEST_PROPERTY_PREFIX = "debezium.test."; diff --git a/debezium-testing/debezium-testing-testcontainers/src/main/java/io/debezium/testing/testcontainers/testhelper/TestInfrastructureHelper.java b/debezium-testing/debezium-testing-testcontainers/src/main/java/io/debezium/testing/testcontainers/testhelper/TestInfrastructureHelper.java index 510eb136368..97a6f14ac08 100644 --- a/debezium-testing/debezium-testing-testcontainers/src/main/java/io/debezium/testing/testcontainers/testhelper/TestInfrastructureHelper.java +++ b/debezium-testing/debezium-testing-testcontainers/src/main/java/io/debezium/testing/testcontainers/testhelper/TestInfrastructureHelper.java @@ -160,6 +160,16 @@ private static Supplier> getContainers(DATABASE database) { } } + public static String parseDebeziumVersion(String connectorVersion) { + var matcher = VERSION_PATTERN.matcher(connectorVersion); + if (matcher.find()) { + return matcher.toMatchResult().group(); + } + else { + throw new RuntimeException("Cannot parse version: " + connectorVersion); + } + } + public static void stopContainers() { Stream containers = Stream.of(DEBEZIUM_CONTAINER, ORACLE_CONTAINER, SQL_SERVER_CONTAINER, MONGODB_REPLICA, MYSQL_CONTAINER, POSTGRES_CONTAINER, MARIADB_CONTAINER, @@ -224,13 +234,7 @@ public static void defaultDebeziumContainer(String debeziumContainerImageVersion debeziumContainerImageVersion = DEBEZIUM_CONTAINER_IMAGE_VERSION_LATEST; } else { - var matcher = VERSION_PATTERN.matcher(debeziumContainerImageVersion); - if (matcher.find()) { - debeziumContainerImageVersion = matcher.toMatchResult().group(); - } - else { - throw new RuntimeException("Cannot parse version: " + debeziumContainerImageVersion); - } + debeziumContainerImageVersion = parseDebeziumVersion(debeziumContainerImageVersion); } final String registry = debeziumContainerImageVersion.startsWith("1.2") ? "" : "quay.io/"; String imageName = registry + "debezium/connect:" + debeziumContainerImageVersion;