Class 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 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
    • Field Detail

      • TIMEZONE

        public static final ZoneId TIMEZONE
      • 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

        private 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 name
        databaseName - - 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 name
        databaseName - - 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 name
        databaseName - - 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
      • getIdentifier

        public String getIdentifier()
        Returns:
        The unique database suffix
      • timezone

        public ZoneId timezone()
        Returns:
        timezone in which the database is located