Skip to content

Commit

Permalink
DBZ-8138 Re-add check if assembly profile is active as JUnit annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
rk3rn3r authored and jpechane committed Aug 15, 2024
1 parent 4189af9 commit 42fbde8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private Configuration.Builder mongodbSinkConfig() {
}

default void startSink(Function<Configuration.Builder, Configuration.Builder> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)";
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ private static Supplier<Stream<Startable>> 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<Startable> containers = Stream.of(DEBEZIUM_CONTAINER, ORACLE_CONTAINER, SQL_SERVER_CONTAINER, MONGODB_REPLICA, MYSQL_CONTAINER, POSTGRES_CONTAINER,
MARIADB_CONTAINER,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 42fbde8

Please sign in to comment.