Class TestHelper
java.lang.Object
io.debezium.connector.sqlserver.util.TestHelper
- Author:
- Horia Chiorean (hchiorea@redhat.com)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classA multiple result-set consumer used internally bywaitForCdcRecord(SqlServerConnection, String, CdcRecordHandler)that allows returning whether the providedTestHelper.CdcRecordHandlerdetected the expected condition or not.static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final org.slf4j.Loggerstatic final Pathprivate static final Stringprivate static final Stringstatic final Stringstatic final Stringprivate static final Stringstatic final Stringprivate static final Stringstatic final StringKey for schema parameter used to store a source column's type length.static final StringKey for schema parameter used to store a source column's type name.static final StringKey for schema parameter used to store a source column's type scale. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic io.debezium.connector.sqlserver.SqlServerConnectionstatic voidstatic voidcreateTestDatabase(String databaseName) static voidcreateTestDatabases(String... databaseNames) static Configuration.BuilderReturns a default connector configuration suitable for most test cases.static Configuration.BuilderdefaultConfig(String... databaseNames) Returns a default configuration for connectors in multi-partition mode.static Configuration.Builderstatic JdbcConfigurationprotected 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 voidprivate 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 voidenableSchemaTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, TableId tableId) Enables CDC for given schema and table if not already enabled and generates the wrapper functions for that table.static voidenableTableCdc(io.debezium.connector.sqlserver.SqlServerConnection connection, String name) Enables CDC for a table in default schema 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 JdbcConfigurationjdbcConfig(String user, String password) static io.debezium.connector.sqlserver.SqlServerConnectionReturns a database connection that isn't explicitly connected to any database.static io.debezium.connector.sqlserver.SqlServerConnectionstatic io.debezium.connector.sqlserver.SqlServerConnectiontestConnection(JdbcConfiguration config) static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection(String databaseName) static io.debezium.connector.sqlserver.SqlServerConnectionstatic Stringstatic 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 voidprivate static voidwaitForSnapshotToBeCompleted(ObjectName objectName) static voidstatic voidwaitForStreamingStarted(ObjectName objectName) static voidwaitForTaskStreamingStarted(String taskId) static intstatic int
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
SCHEMA_HISTORY_PATH
-
TEST_DATABASE_1
- See Also:
-
TEST_DATABASE_2
- See Also:
-
TEST_SERVER_NAME
- See Also:
-
TEST_PROPERTY_PREFIX
- See Also:
-
TEST_TASK_ID
- See Also:
-
STATEMENTS_PLACEHOLDER
- See Also:
-
SCHEMA_PLACEHOLDER
- See Also:
-
ENABLE_DB_CDC
- See Also:
-
DISABLE_DB_CDC
- See Also:
-
ENABLE_TABLE_CDC
- See Also:
-
IS_CDC_ENABLED
- See Also:
-
IS_CDC_TABLE_ENABLED
- See Also:
-
ENABLE_TABLE_CDC_WITH_CUSTOM_CAPTURE
- See Also:
-
DISABLE_TABLE_CDC
- See Also:
-
CDC_WRAPPERS_DML
-
TYPE_NAME_PARAMETER_KEY
Key for schema parameter used to store a source column's type name.- See Also:
-
TYPE_LENGTH_PARAMETER_KEY
Key for schema parameter used to store a source column's type length.- See Also:
-
TYPE_SCALE_PARAMETER_KEY
Key for schema parameter used to store a source column's type scale.- See Also:
-
-
Constructor Details
-
TestHelper
public TestHelper()
-
-
Method Details
-
defaultJdbcConfig
-
jdbcConfig
-
defaultConnectorConfig
-
defaultConfig
Returns a default connector configuration suitable for most test cases. Can be amended/overridden in individual tests as needed. -
defaultConfig
Returns a default configuration for connectors in multi-partition mode. -
createTestDatabase
public static void createTestDatabase() -
createTestDatabases
-
createTestDatabase
-
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 benull- 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 benull- 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 connectiontableId-TableIdof the table, schema and table name may not benull- 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 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 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 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
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
-
waitForDatabaseSnapshotsToBeCompleted
-
waitForSnapshotToBeCompleted
-
waitForTaskStreamingStarted
-
waitForStreamingStarted
public static void waitForStreamingStarted() -
waitForStreamingStarted
-
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
-
getObjectName
-
getObjectName
-
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 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) -
topicName
-