Skip to content

Commit

Permalink
DBZ-4272 Skip connector test using annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jpechane authored and gunnarmorling committed Nov 30, 2021
1 parent 358eb03 commit 5e40e1c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
18 changes: 18 additions & 0 deletions debezium-core/src/test/java/io/debezium/junit/SkipTestRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ public Statement apply(Statement base,
}
}

final SkipWhenConnectorUnderTest connectorUnderTestAnnotation = hasAnnotation(description, SkipWhenConnectorUnderTest.class);
if (connectorUnderTestAnnotation != null) {
boolean isConnectorUnderTest;

switch (connectorUnderTestAnnotation.check()) {
case EQUAL:
isConnectorUnderTest = connectorUnderTestAnnotation.value().isEqualTo(description.getClassName());
break;
default:
isConnectorUnderTest = false;
break;
}

if (isConnectorUnderTest) {
return emptyStatement("Connector under test " + connectorUnderTestAnnotation.value(), description);
}
}

// First check if multiple database version skips are specified.
SkipWhenDatabaseVersions skipWhenDatabaseVersions = hasAnnotation(description, SkipWhenDatabaseVersions.class);
if (skipWhenDatabaseVersions != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 together with the {@link SkipTestRule} JUnit rule, that allows tests to be skipped
* based on the current connector under test
*
* @author Jiri Pechanec
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface SkipWhenConnectorUnderTest {

Connector value();

EqualityCheck check();

String description() default "";

public enum Connector {
SQL_SERVER {

@Override
boolean isEqualTo(String packageName) {
return packageName != null && packageName.startsWith("io.debezium.connector.sqlserver");
}
};

abstract boolean isEqualTo(String packageName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import io.debezium.embedded.AbstractConnectorTest;
import io.debezium.engine.DebeziumEngine;
import io.debezium.jdbc.JdbcConnection;
import io.debezium.junit.EqualityCheck;
import io.debezium.junit.SkipWhenConnectorUnderTest;
import io.debezium.junit.SkipWhenConnectorUnderTest.Connector;
import io.debezium.util.Testing;

public abstract class AbstractIncrementalSnapshotTest<T extends SourceConnector> extends AbstractConnectorTest {
Expand Down Expand Up @@ -415,11 +418,9 @@ public void snapshotOnlyWithRestart() throws Exception {

@Test
@FixFor("DBZ-4272")
public void snapshotProceededBySchemaChange() throws Exception {
// Disabled due to DBZ-4350
if (this.getClass().getName().contains("sqlserver")) {
return;
}
// Disabled due to DBZ-4350
@SkipWhenConnectorUnderTest(check = EqualityCheck.EQUAL, value = Connector.SQL_SERVER)
public void snapshotPreceededBySchemaChange() throws Exception {
Testing.Print.enable();

populateTable();
Expand Down

0 comments on commit 5e40e1c

Please sign in to comment.