Class UniqueDatabase
java.lang.Object
io.debezium.connector.binlog.util.UniqueDatabase
Create and populate a unique instance of a binlog-based connector database for each run of a Junit test.
A user of class needs to provide a logical name for Debezium and the database. It is expected that there
is an init file in
src/test/resources/ddl/<database_name>.sql.
The database name is enriched with a unique suffix that guarantees complete isolation between runs:
<database_name>_<suffix>- Author:
- jpechane, Chris Cranford
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUniqueDatabase(String serverName, String databaseName) Creates an instance with given Debezium logical name and database nameUniqueDatabase(String serverName, String databaseName, UniqueDatabase sibling) Creates an instance with given Debezium logical name and database name and id suffix same as another database.UniqueDatabase(String serverName, String databaseName, String charset) Creates an instance with given Debezium logical name and database name and a set default charsetUniqueDatabase(String serverName, String databaseName, String identifier, String charset) -
Method Summary
Modifier and TypeMethodDescriptionprotected Configuration.Builderprivate StringconvertSQL(String sql) voidCreates the database and populates it with initialization SQL script.voidcreateAndInitialize(Map<String, Object> urlProperties) Creates the database and populates it with initialization SQL script.protected abstract JdbcConnectionforTestDatabase(String databaseName, Map<String, Object> urlProperties) qualifiedTableName(String tableName) Supports reading the contents of the SQL file, regardless if its bundled in a jar or not.timezone()topicForTable(String tableName) withDbHistoryPath(Path dbHistoryPath)
-
Field Details
-
TIMEZONE
-
DEFAULT_DATABASE
- See Also:
-
CREATE_DATABASE_DDL
-
CREATE_DATABASE_WITH_CHARSET_DDL
-
COMMENT_PATTERN
-
databaseName
-
charset
-
templateName
-
serverName
-
dbHistoryPath
-
identifier
-
-
Constructor Details
-
UniqueDatabase
-
UniqueDatabase
Creates an instance with given Debezium logical name and database name- Parameters:
serverName- - logical Debezium server namedatabaseName- - the name of the database (prix)
-
UniqueDatabase
Creates an instance with given Debezium logical name and database name and a set default charset- Parameters:
serverName- - logical Debezium server namedatabaseName- - the name of the database (prix)
-
UniqueDatabase
Creates an instance with given Debezium logical name and database name and id suffix same as another database. This is handy for tests that need multpli databases and can use regex based whitelisting.- Parameters:
serverName- - logical Debezium server namedatabaseName- - the name of the database (prix)sibling- - a database whose unique suffix will be used
-
-
Method Details
-
convertSQL
-
getDatabaseName
-
topicForTable
- Parameters:
tableName-- Returns:
- Fully qualified Kafka topic name for a given table
<serverName>.<databaseName>.<tableName>
-
qualifiedTableName
- Parameters:
tableName-- Returns:
- Fully qualified table name
<databaseName>.<tableName>
-
getServerName
-
getTopicPrefix
-
createAndInitialize
public void createAndInitialize()Creates the database and populates it with initialization SQL script. To use multiline statements for stored procedures definition use delimiter $$ to delimit statements in the procedure. See fnDbz162 procedure in reqression_test.sql for example of usage. -
createAndInitialize
Creates the database and populates it with initialization SQL script. To use multiline statements for stored procedures definition use delimiter $$ to delimit statements in the procedure. See fnDbz162 procedure in reqression_test.sql for example of usage.- Parameters:
urlProperties- jdbc url properties
-
readFileContents
private List<String> readFileContents(URI uri, Function<Stream<String>, List<String>> handler) throws IOExceptionSupports reading the contents of the SQL file, regardless if its bundled in a jar or not.- Parameters:
uri- the file URIhandler- the handler to receive the file contents- Returns:
- the contents
- Throws:
IOException- if there was an error reading the file contents
-
withDbHistoryPath
- Parameters:
dbHistoryPath- - directory where to store database schema history- See Also:
-
FileSchemaHistory
-
defaultJdbcConfigBuilder
- Returns:
- Configuration builder initialized with JDBC connection parameters.
-
defaultConfig
- Returns:
- Configuration builder initialized with JDBC connection parameters and most frequently used parameters
-
defaultConfigWithoutDatabaseFilter
- Returns:
- Configuration builder initialized with JDBC connection parameters and most frequently used parameters, database not filtered by default
-
getIdentifier
- Returns:
- The unique database suffix
-
timezone
- Returns:
- timezone in which the database is located
-
applyConnectorDefaultJdbcConfiguration
protected Configuration.Builder applyConnectorDefaultJdbcConfiguration(Configuration.Builder builder) -
forTestDatabase
protected abstract JdbcConnection forTestDatabase(String databaseName, Map<String, Object> urlProperties)
-