Class TestHelper
- java.lang.Object
-
- io.debezium.connector.sqlserver.util.TestHelper
-
public class TestHelper extends Object
- Author:
- Horia Chiorean (hchiorea@redhat.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classTestHelper.CdcRecordFoundBlockingMultiResultSetConsumerA multiple result-set consumer used internally bywaitForCdcRecord(SqlServerConnection, String, CdcRecordHandler)that allows returning whether the providedTestHelper.CdcRecordHandlerdetected the expected condition or not.static interfaceTestHelper.CdcRecordHandler
-
Field Summary
Fields Modifier and Type Field Description private static StringCDC_WRAPPERS_DMLstatic PathDB_HISTORY_PATHprivate static StringDISABLE_DB_CDCprivate static StringDISABLE_TABLE_CDCprivate static StringENABLE_DB_CDCprivate static StringENABLE_TABLE_CDCprivate static StringENABLE_TABLE_CDC_WITH_CUSTOM_CAPTUREprivate static StringIS_CDC_ENABLEDprivate static StringIS_CDC_TABLE_ENABLEDprivate static org.slf4j.LoggerLOGGERprivate static StringSTATEMENTS_PLACEHOLDERstatic StringTEST_DATABASEstatic StringTEST_DATABASE_1static StringTEST_DATABASE_2private static StringTEST_PROPERTY_PREFIXstatic StringTEST_SERVER_NAMEprivate static StringTEST_TASK_IDstatic StringTYPE_LENGTH_PARAMETER_KEYKey for schema parameter used to store a source column's type length.static StringTYPE_NAME_PARAMETER_KEYKey for schema parameter used to store a source column's type name.static StringTYPE_SCALE_PARAMETER_KEYKey for schema parameter used to store a source column's type scale.
-
Constructor Summary
Constructors Constructor Description TestHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.debezium.connector.sqlserver.SqlServerConnectionadminConnection()static voidcreateTestDatabase()static voidcreateTestDatabase(String databaseName)static voidcreateTestDatabases(String... databaseNames)static Configuration.BuilderdefaultConfig()Returns a default connector configuration suitable for most test cases.static Configuration.BuilderdefaultConnectorConfig()static JdbcConfigurationdefaultJdbcConfig()static Configuration.BuilderdefaultMultiPartitionConfig()static Configuration.BuilderdefaultMultiPartitionConfig(String... databaseNames)Returns a default configuration for connectors in multi-partition mode.protected static voiddisableDbCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name)Disables CDC for a given database, if not already disabled.static voiddisableTableCdc(JdbcConnection connection, String name)Disables CDC for a table for which it was enabled before.static voiddropTestDatabase()private static voiddropTestDatabase(io.debezium.connector.sqlserver.SqlServerConnection connection, String databaseName)static voidenableDbCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name)Enables CDC for a given database, if not already enabled.static voidenableTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name)Enables CDC for a table if not already enabled and generates the wrapper functions for that table.static voidenableTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String tableName, String captureName)Enables CDC for a table with a custom capture name functions for that table.static voidenableTableCdc(JdbcConnection connection, String tableName, String captureName, List<String> captureColumnList)Enables CDC for a table with a custom capture name functions for that table.private static ObjectNamegetObjectName(String context, String serverName)private static ObjectNamegetObjectName(String context, String serverName, String databaseName)private static ObjectNamegetObjectName(Map<String,String> tags)static booleanisCdcEnabled(io.debezium.connector.sqlserver.SqlServerConnection connection, String name)static io.debezium.connector.sqlserver.SqlServerConnectionmultiPartitionTestConnection()Returns a database connection that isn't explicitly connected to any database.static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection()private static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection(JdbcConfiguration config)static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection(String databaseName)static io.debezium.connector.sqlserver.SqlServerConnectiontestConnectionWithOptionRecompile()static StringtopicName(String databaseName, String tableName)static voidwaitForCdcRecord(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.static voidwaitForCdcRecord(io.debezium.connector.sqlserver.SqlServerConnection connection, String tableName, String captureInstanceName, TestHelper.CdcRecordHandler handler)static voidwaitForDatabaseSnapshotsToBeCompleted(String... databaseNames)static voidwaitForDatabaseSnapshotToBeCompleted(String databaseName)static voidwaitForDisabledCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String table)static voidwaitForEnabledCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String table)static voidwaitForMaxLsnAvailable(io.debezium.connector.sqlserver.SqlServerConnection connection)static voidwaitForMaxLsnAvailable(io.debezium.connector.sqlserver.SqlServerConnection connection, String databaseName)static voidwaitForSnapshotToBeCompleted()private static voidwaitForSnapshotToBeCompleted(ObjectName objectName)static voidwaitForStreamingStarted()static voidwaitForStreamingStarted(ObjectName objectName)static voidwaitForTaskStreamingStarted()static voidwaitForTaskStreamingStarted(String taskId)static intwaitTimeForRecords()
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DB_HISTORY_PATH
public static final Path DB_HISTORY_PATH
-
TEST_DATABASE
public static final String TEST_DATABASE
- See Also:
- Constant Field Values
-
TEST_DATABASE_1
public static final String TEST_DATABASE_1
- See Also:
- Constant Field Values
-
TEST_DATABASE_2
public static final String TEST_DATABASE_2
- See Also:
- Constant Field Values
-
TEST_SERVER_NAME
public static final String TEST_SERVER_NAME
- See Also:
- Constant Field Values
-
TEST_PROPERTY_PREFIX
private static final String TEST_PROPERTY_PREFIX
- See Also:
- Constant Field Values
-
TEST_TASK_ID
private static final String TEST_TASK_ID
- See Also:
- Constant Field Values
-
STATEMENTS_PLACEHOLDER
private static final String STATEMENTS_PLACEHOLDER
- See Also:
- Constant Field Values
-
ENABLE_DB_CDC
private static final String ENABLE_DB_CDC
- See Also:
- Constant Field Values
-
DISABLE_DB_CDC
private static final String DISABLE_DB_CDC
- See Also:
- Constant Field Values
-
ENABLE_TABLE_CDC
private static final String ENABLE_TABLE_CDC
- See Also:
- Constant Field Values
-
IS_CDC_ENABLED
private static final String IS_CDC_ENABLED
- See Also:
- Constant Field Values
-
IS_CDC_TABLE_ENABLED
private static final String IS_CDC_TABLE_ENABLED
- See Also:
- Constant Field Values
-
ENABLE_TABLE_CDC_WITH_CUSTOM_CAPTURE
private static final String ENABLE_TABLE_CDC_WITH_CUSTOM_CAPTURE
- See Also:
- Constant Field Values
-
DISABLE_TABLE_CDC
private static final String DISABLE_TABLE_CDC
- See Also:
- Constant Field Values
-
CDC_WRAPPERS_DML
private static final String CDC_WRAPPERS_DML
-
TYPE_NAME_PARAMETER_KEY
public static final String TYPE_NAME_PARAMETER_KEY
Key for schema parameter used to store a source column's type name.- See Also:
- Constant Field Values
-
TYPE_LENGTH_PARAMETER_KEY
public static final String TYPE_LENGTH_PARAMETER_KEY
Key for schema parameter used to store a source column's type length.- See Also:
- Constant Field Values
-
TYPE_SCALE_PARAMETER_KEY
public static final String TYPE_SCALE_PARAMETER_KEY
Key for schema parameter used to store a source column's type scale.- See Also:
- Constant Field Values
-
-
Method Detail
-
defaultJdbcConfig
public static JdbcConfiguration defaultJdbcConfig()
-
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.
-
defaultMultiPartitionConfig
public static Configuration.Builder defaultMultiPartitionConfig(String... databaseNames)
Returns a default configuration for connectors in multi-partition mode.
-
defaultMultiPartitionConfig
public static Configuration.Builder defaultMultiPartitionConfig()
-
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 SQLExceptionEnables CDC for a given database, if not already enabled.- Parameters:
name- the name of the DB, may not benull- Throws:
SQLException- if anything unexpected fails
-
disableDbCdc
protected static void disableDbCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name) throws SQLExceptionDisables CDC for a given database, if not already disabled.- Parameters:
name- the name of the DB, may not benull- Throws:
SQLException- if anything unexpected fails
-
enableTableCdc
public static void enableTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name) throws SQLExceptionEnables CDC for a table if not already enabled and generates the wrapper functions for that table.- Parameters:
connection- sql connectionname- the name of the table, may not benull- 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 benull- 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 SQLExceptionEnables CDC for a table with a custom capture name functions for that table.- Parameters:
connection- sql connectiontableName- the name of the table, may not benullcaptureName- the name of the capture instance, may not benull- 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 connectiontableName- the name of the table, may not benullcaptureName- the name of the capture instance, may not benullcaptureColumnList- the source table columns that are to be included in the change table, may not benull- 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 benull- 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
-
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()
-
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 returntrueif the expected outcome exists orfalseto indicate it did not find what it expected. This method will block until either the handler returnstrueor if the polling fails to complete within the allocated poll window.- Parameters:
connection- the SQL Server connection to be usedtableName- the main table name to be checkedhandler- 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:
SQLExceptionInterruptedException
-
waitForDisabledCdc
public static void waitForDisabledCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String table) throws SQLException, InterruptedException- Throws:
SQLExceptionInterruptedException
-
waitForCdcRecord
public static void waitForCdcRecord(io.debezium.connector.sqlserver.SqlServerConnection connection, String tableName, String captureInstanceName, TestHelper.CdcRecordHandler handler)
-
-