Class TestHelper


  • public class TestHelper
    extends Object
    Author:
    Horia Chiorean (hchiorea@redhat.com)
    • Constructor Detail

      • TestHelper

        public TestHelper()
    • Method Detail

      • defaultConfig

        public static Configuration.Builder defaultConfig()
        Returns a default configuration suitable for most test cases. Can be amended/overridden in individual tests as needed.
      • createTestDatabase

        public static void createTestDatabase()
      • dropTestDatabase

        public static void dropTestDatabase()
      • dropTestDatabase

        private static void dropTestDatabase​(io.debezium.connector.sqlserver.SqlServerConnection connection)
                                      throws SQLException
        Throws:
        SQLException
      • adminConnection

        public static io.debezium.connector.sqlserver.SqlServerConnection adminConnection()
      • testConnection

        public static io.debezium.connector.sqlserver.SqlServerConnection testConnection()
      • enableDbCdc

        public static void enableDbCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                       String name)
                                throws SQLException
        Enables CDC for a given database, if not already enabled.
        Parameters:
        name - the name of the DB, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • disableDbCdc

        protected static void disableDbCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                           String name)
                                    throws SQLException
        Disables CDC for a given database, if not already disabled.
        Parameters:
        name - the name of the DB, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • enableTableCdc

        public static void enableTableCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                          String name)
                                   throws SQLException
        Enables CDC for a table if not already enabled and generates the wrapper functions for that table.
        Parameters:
        connection - sql connection
        name - the name of the table, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • isCdcEnabled

        public static boolean isCdcEnabled​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                           String name)
                                    throws SQLException
        Parameters:
        name - the name of the table, may not be null
        Returns:
        true if CDC is enabled for the table
        Throws:
        SQLException - if anything unexpected fails
      • enableTableCdc

        public static void enableTableCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                          String tableName,
                                          String captureName)
                                   throws SQLException
        Enables CDC for a table with a custom capture name functions for that table.
        Parameters:
        connection - sql connection
        tableName - the name of the table, may not be null
        captureName - the name of the capture instance, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • enableTableCdc

        public static void enableTableCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                          String tableName,
                                          String captureName,
                                          List<String> captureColumnList)
                                   throws SQLException
        Enables CDC for a table with a custom capture name functions for that table.
        Parameters:
        connection - sql connection
        tableName - the name of the table, may not be null
        captureName - the name of the capture instance, may not be null
        captureColumnList - the source table columns that are to be included in the change table, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • disableTableCdc

        public static void disableTableCdc​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                           String name)
                                    throws SQLException
        Disables CDC for a table for which it was enabled before.
        Parameters:
        name - the name of the table, may not be null
        Throws:
        SQLException - if anything unexpected fails
      • waitForSnapshotToBeCompleted

        public static void waitForSnapshotToBeCompleted()
      • waitForStreamingStarted

        public static void waitForStreamingStarted()
      • waitForMaxLsnAvailable

        public static void waitForMaxLsnAvailable​(io.debezium.connector.sqlserver.SqlServerConnection connection)
                                           throws Exception
        Throws:
        Exception
      • waitTimeForRecords

        public static int waitTimeForRecords()
      • waitForCdcRecord

        public static void waitForCdcRecord​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                            String tableName,
                                            TestHelper.CdcRecordHandler handler)
        Utility method that will poll the CDC change tables and provide the record handler with the changes detected. The record handler can then make a determination as to whether to return true if the expected outcome exists or false to indicate it did not find what it expected. This method will block until either the handler returns true or if the polling fails to complete within the allocated poll window.
        Parameters:
        connection - the SQL Server connection to be used
        tableName - the main table name to be checked
        handler - the handler method to be called if changes are found in the capture table instance
      • waitForCdcRecord

        public static void waitForCdcRecord​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                            String tableName,
                                            String captureInstanceName,
                                            TestHelper.CdcRecordHandler handler)