diff --git a/src/test/java/io/debezium/connector/db2/Db2ConnectorIT.java b/src/test/java/io/debezium/connector/db2/Db2ConnectorIT.java index af5f0e4..802e441 100644 --- a/src/test/java/io/debezium/connector/db2/Db2ConnectorIT.java +++ b/src/test/java/io/debezium/connector/db2/Db2ConnectorIT.java @@ -58,6 +58,8 @@ public class Db2ConnectorIT extends AbstractConnectorTest { @Before public void before() throws SQLException { + TestHelper.dropAllTables(); + connection = TestHelper.testConnection(); connection.execute("DELETE FROM ASNCDC.IBMSNAP_REGISTER"); connection.execute( diff --git a/src/test/java/io/debezium/connector/db2/util/TestHelper.java b/src/test/java/io/debezium/connector/db2/util/TestHelper.java index a5b25c0..7c2e888 100644 --- a/src/test/java/io/debezium/connector/db2/util/TestHelper.java +++ b/src/test/java/io/debezium/connector/db2/util/TestHelper.java @@ -272,4 +272,19 @@ public static void waitForCDC() { } } + + public static void dropAllTables() throws SQLException { + try (Db2Connection connection = testConnection()) { + LOGGER.info("Attempting to drop all tables (if exists)"); + connection.query("SELECT TABNAME FROM syscat.tables WHERE TABSCHEMA = 'DB2INST1'", rs -> { + while (rs.next()) { + final String tableName = rs.getString(1); + LOGGER.info("Disabling CDC for table {}", tableName); + disableTableCdc(connection, "DB2INST1", tableName); + LOGGER.warn("Dropping table {}", tableName); + connection.execute("DROP TABLE IF EXISTS " + tableName); + } + }); + } + } }