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 connector configuration suitable for most test cases. Can be amended/overridden in individual tests as needed.
      • defaultMultiPartitionConfig

        public static Configuration.Builder defaultMultiPartitionConfig​(String... databaseNames)
        Returns a default configuration for connectors in multi-partition mode.
      • createTestDatabase

        public static void createTestDatabase()
      • createTestDatabases

        public static void createTestDatabases​(String... databaseNames)
      • createTestDatabase

        public static void createTestDatabase​(String databaseName)
      • dropTestDatabase

        public static void dropTestDatabase()
      • dropTestDatabase

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

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

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

        public static io.debezium.connector.sqlserver.SqlServerConnection multiPartitionTestConnection()
        Returns a database connection that isn't explicitly connected to any database.
      • testConnection

        public static io.debezium.connector.sqlserver.SqlServerConnection testConnection​(String databaseName)
      • testConnection

        private static io.debezium.connector.sqlserver.SqlServerConnection testConnection​(JdbcConfiguration config)
      • testConnectionWithOptionRecompile

        public static io.debezium.connector.sqlserver.SqlServerConnection testConnectionWithOptionRecompile()
      • 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​(JdbcConnection 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​(JdbcConnection 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()
      • waitForDatabaseSnapshotToBeCompleted

        public static void waitForDatabaseSnapshotToBeCompleted​(String databaseName)
      • waitForDatabaseSnapshotsToBeCompleted

        public static void waitForDatabaseSnapshotsToBeCompleted​(String... databaseNames)
      • waitForSnapshotToBeCompleted

        private static void waitForSnapshotToBeCompleted​(ObjectName objectName)
      • waitForTaskStreamingStarted

        public static void waitForTaskStreamingStarted​(String taskId)
      • waitForTaskStreamingStarted

        public static void waitForTaskStreamingStarted()
      • waitForStreamingStarted

        public static void waitForStreamingStarted()
      • waitForStreamingStarted

        public static void waitForStreamingStarted​(ObjectName objectName)
      • waitForMaxLsnAvailable

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

        public static void waitForMaxLsnAvailable​(io.debezium.connector.sqlserver.SqlServerConnection connection,
                                                  String databaseName)
                                           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)