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_DATABASEprivate static StringTEST_PROPERTY_PREFIXstatic 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 JdbcConfigurationadminJdbcConfig()static voidcreateTestDatabase()static voidcreateTestDatabase(String databaseName)static Configuration.BuilderdefaultConfig()Returns a default connector configuration suitable for most test cases.static Configuration.BuilderdefaultConnectorConfig()static JdbcConfigurationdefaultJdbcConfig()static Configuration.BuilderdefaultMultiPartitionConfig()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)static booleanisCdcEnabled(io.debezium.connector.sqlserver.SqlServerConnection connection, String name)static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection()static io.debezium.connector.sqlserver.SqlServerConnectiontestConnection(String databaseName)static io.debezium.connector.sqlserver.SqlServerConnectiontestConnectionWithOptionRecompile()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 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()static voidwaitForStreamingStarted()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_PROPERTY_PREFIX
private static final String TEST_PROPERTY_PREFIX
- 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
-
adminJdbcConfig
public static JdbcConfiguration adminJdbcConfig()
-
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()
Returns a default configuration for connectors in multi-partition mode.
-
createTestDatabase
public static void createTestDatabase()
-
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()
-
testConnection
public static io.debezium.connector.sqlserver.SqlServerConnection testConnection(String databaseName)
-
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()
-
waitForStreamingStarted
public static void 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
private static ObjectName getObjectName(String context, String serverName) throws MalformedObjectNameException
- Throws:
MalformedObjectNameException
-
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)
-
-