Package io.debezium.connector.mysql
Class UniqueDatabase
- java.lang.Object
-
- io.debezium.connector.mysql.UniqueDatabase
-
public class UniqueDatabase extends Object
Create and populate a unique instance of a MySQL database for each run of JUnit test. A user of class needs to provide a logical name for Debezium and database name. It is expected that there is a init file insrc/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
-
-
Field Summary
Fields Modifier and Type Field Description private Stringcharsetprivate static PatternCOMMENT_PATTERNprivate static String[]CREATE_DATABASE_DDLprivate static String[]CREATE_DATABASE_WITH_CHARSET_DDLprivate StringdatabaseNameprivate PathdbHistoryPathprivate static StringDEFAULT_DATABASEprivate Stringidentifierprivate StringserverNameprivate StringtemplateNamestatic ZoneIdTIMEZONE
-
Constructor Summary
Constructors Constructor Description UniqueDatabase(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private StringconvertSQL(String sql)voidcreateAndInitialize()Creates the database and populates it with initialization SQL script.voidcreateAndInitialize(Map<String,Object> urlProperties)Creates the database and populates it with initialization SQL script.Configuration.BuilderdefaultConfig()Configuration.BuilderdefaultConfigWithoutDatabaseFilter()Configuration.BuilderdefaultJdbcConfigBuilder()StringgetDatabaseName()StringgetIdentifier()StringgetServerName()StringqualifiedTableName(String tableName)ZoneIdtimezone()StringtopicForTable(String tableName)UniqueDatabasewithDbHistoryPath(Path dbHistoryPath)
-
-
-
Field Detail
-
TIMEZONE
public static final ZoneId TIMEZONE
-
DEFAULT_DATABASE
private static final String DEFAULT_DATABASE
- See Also:
- Constant Field Values
-
CREATE_DATABASE_DDL
private static final String[] CREATE_DATABASE_DDL
-
CREATE_DATABASE_WITH_CHARSET_DDL
private static final String[] CREATE_DATABASE_WITH_CHARSET_DDL
-
COMMENT_PATTERN
private static final Pattern COMMENT_PATTERN
-
databaseName
private final String databaseName
-
charset
private final String charset
-
templateName
private final String templateName
-
serverName
private final String serverName
-
dbHistoryPath
private Path dbHistoryPath
-
identifier
private final String identifier
-
-
Constructor Detail
-
UniqueDatabase
public UniqueDatabase(String serverName, String databaseName, String identifier, String charset)
-
UniqueDatabase
public UniqueDatabase(String serverName, String databaseName)
Creates an instance with given Debezium logical name and database name- Parameters:
serverName- - logical Debezium server namedatabaseName- - the name of the database (prix)
-
UniqueDatabase
public UniqueDatabase(String serverName, String databaseName, String charset)
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
public UniqueDatabase(String serverName, String databaseName, UniqueDatabase sibling)
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 Detail
-
getDatabaseName
public String getDatabaseName()
-
topicForTable
public String topicForTable(String tableName)
- Parameters:
tableName-- Returns:
- Fully qualified Kafka topic name for a given table
<serverName>.<databaseName>.<tableName>
-
qualifiedTableName
public String qualifiedTableName(String tableName)
- Parameters:
tableName-- Returns:
- Fully qualified table name
<databaseName>.<tableName>
-
getServerName
public String getServerName()
-
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
public void createAndInitialize(Map<String,Object> urlProperties)
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
-
withDbHistoryPath
public UniqueDatabase withDbHistoryPath(Path dbHistoryPath)
- Parameters:
dbHistoryPath- - directory where to store database schema history- See Also:
FileDatabaseHistory
-
defaultJdbcConfigBuilder
public Configuration.Builder defaultJdbcConfigBuilder()
- Returns:
- Configuration builder initialized with JDBC connection parameters.
-
defaultConfig
public Configuration.Builder defaultConfig()
- Returns:
- Configuration builder initialized with JDBC connection parameters and most frequently used parameters
-
defaultConfigWithoutDatabaseFilter
public Configuration.Builder defaultConfigWithoutDatabaseFilter()
- Returns:
- Configuration builder initialized with JDBC connection parameters and most frequently used parameters, database not filtered by default
-
getIdentifier
public String getIdentifier()
- Returns:
- The unique database suffix
-
timezone
public ZoneId timezone()
- Returns:
- timezone in which the database is located
-
-