Class TestHelper

java.lang.Object
io.debezium.connector.sqlserver.util.TestHelper

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

  • Constructor Details

    • TestHelper

      public TestHelper()
  • Method Details

    • defaultJdbcConfig

      public static JdbcConfiguration defaultJdbcConfig()
    • jdbcConfig

      public static JdbcConfiguration jdbcConfig(String user, String password)
    • defaultConnectorConfig

      public static Configuration.Builder defaultConnectorConfig()
    • 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.
    • defaultConfig

      public static Configuration.Builder defaultConfig(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

      public 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
    • enableSchemaTableCdc

      public static void enableSchemaTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, TableId tableId) throws SQLException
      Enables CDC for given schema and table if not already enabled and generates the wrapper functions for that table.
      Parameters:
      connection - sql connection
      tableId - TableId of the table, schema and table name 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 in default schema 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
    • adjustCdcPollingInterval

      public static void adjustCdcPollingInterval(JdbcConnection connection, int interval) throws SQLException
      Sets new polling interval in which SQL server should poll changes. SQL server polls new changes and copies them into CDC in predefined interval. By default, this interval is 5 seconds. For the tests it may be too long and test may need shorter interval.
      Parameters:
      interval - new CDC polling interval, in seconds
      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)
    • 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
    • getObjectName

      private static ObjectName getObjectName(String context, String serverName)
    • getObjectName

      private static ObjectName getObjectName(String context, String serverName, String databaseName)
    • getObjectName

      private static ObjectName getObjectName(Map<String,String> tags)
    • waitTimeForRecords

      public static int waitTimeForRecords()
    • waitTimeForLogEntries

      public static int waitTimeForLogEntries()
    • 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
    • waitForEnabledCdc

      public static void waitForEnabledCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String table) throws SQLException, InterruptedException
      Throws:
      SQLException
      InterruptedException
    • waitForDisabledCdc

      public static void waitForDisabledCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String table) throws SQLException, InterruptedException
      Throws:
      SQLException
      InterruptedException
    • waitForCdcRecord

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

      public static void waitForCdcTransactionPropagation(io.debezium.connector.sqlserver.SqlServerConnection connection, String dbName, int expectedTransactions) throws SQLException
      Throws:
      SQLException
    • topicName

      public static String topicName(String databaseName, String tableName)