DBZ-1185 Skip unsupported tests for legacy parser

This commit is contained in:
Jiri Pechanec 2019-03-21 12:51:28 +01:00 committed by Gunnar Morling
parent 601f2008ac
commit 958d207121
4 changed files with 69 additions and 0 deletions

View File

@ -18,9 +18,13 @@
import org.apache.kafka.connect.source.SourceRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import io.debezium.config.Configuration;
import io.debezium.connector.mysql.junit.SkipForLegacyParser;
import io.debezium.connector.mysql.junit.SkipTestForLegacyParser;
import io.debezium.data.Envelope;
import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest;
@ -29,6 +33,7 @@
/**
* @author Omar Al-Safi
*/
@SkipForLegacyParser
public class MySqlUnsignedIntegerIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-json.txt")
@ -39,6 +44,9 @@ public class MySqlUnsignedIntegerIT extends AbstractConnectorTest {
private final UniqueDatabase DATABASE = new UniqueDatabase("unsignednumericit", "unsigned_integer_test")
.withDbHistoryPath(DB_HISTORY_PATH);
@Rule
public final TestRule skip = new SkipTestForLegacyParser();
@Before
public void beforeEach() {
stopConnector();

View File

@ -15,9 +15,13 @@
import org.apache.kafka.connect.source.SourceRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import io.debezium.config.Configuration;
import io.debezium.connector.mysql.junit.SkipForLegacyParser;
import io.debezium.connector.mysql.junit.SkipTestForLegacyParser;
import io.debezium.data.VerifyRecord;
import io.debezium.doc.FixFor;
import io.debezium.embedded.AbstractConnectorTest;
@ -28,6 +32,7 @@
*
* @author Gunnar Morling
*/
@SkipForLegacyParser
public class TopicNameSanitizationIT extends AbstractConnectorTest {
private static final Path DB_HISTORY_PATH = Testing.Files.createTestingPath("file-db-history-topic-name-sanitization.txt")
@ -35,6 +40,9 @@ public class TopicNameSanitizationIT extends AbstractConnectorTest {
private final UniqueDatabase DATABASE = new UniqueDatabase("topic-name-sanitization-it", "topic_name_sanitization_test")
.withDbHistoryPath(DB_HISTORY_PATH);
@Rule
public final TestRule skip = new SkipTestForLegacyParser();
private Configuration config;
@Before

View File

@ -0,0 +1,20 @@
/*
* 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.connector.mysql.junit;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation used together with the {@link SkipTestForLegacyParser} JUnit rule, that allows
* tests to be skipped if the legacy parser is used.
*/
@Retention( RetentionPolicy.RUNTIME)
@Target( {ElementType.METHOD, ElementType.TYPE})
public @interface SkipForLegacyParser {
}

View File

@ -0,0 +1,33 @@
/*
* 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.connector.mysql.junit;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import io.debezium.connector.mysql.MySqlConnectorConfig;
import io.debezium.junit.AnnotationBasedTestRule;
import io.debezium.util.Strings;
/**
* JUnit rule that skips a test based on the {@link SkipForLegacyParser} annotation on either a test method or a test class.
*/
public class SkipTestForLegacyParser extends AnnotationBasedTestRule {
private static boolean isLegacyParserInUse() {
final String mode = System.getProperty("ddl.parser.mode");
return !Strings.isNullOrEmpty(mode) && mode.equalsIgnoreCase(MySqlConnectorConfig.DdlParsingMode.LEGACY.getValue());
}
@Override
public Statement apply(Statement base, Description description) {
final SkipForLegacyParser skipHasName = hasAnnotation(description, SkipForLegacyParser.class);
if (skipHasName != null && isLegacyParserInUse()) {
String reasonForSkipping = "Legacy parser is used";
return emptyStatement(reasonForSkipping, description);
}
return base;
}
}