Search in sources :

Example 1 with JdbcDatabaseDelegate

use of org.testcontainers.jdbc.JdbcDatabaseDelegate in project drill by apache.

the class TestJdbcWriterWithMySQL method initMysql.

@BeforeClass
public static void initMysql() throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher));
    dirTestWatcher.copyResourceToRoot(Paths.get(""));
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    String osName = System.getProperty("os.name").toLowerCase();
    String mysqlDBName = "drill_mysql_test";
    DockerImageName imageName;
    if (osName.startsWith("linux") && "aarch64".equals(System.getProperty("os.arch"))) {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MARIADB).asCompatibleSubstituteFor("mysql");
    } else {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MYSQL);
    }
    jdbcContainer = new MySQLContainer<>(imageName).withExposedPorts(3306).withConfigurationOverride("mysql_config_override").withUsername("mysqlUser").withPassword("mysqlPass").withDatabaseName(mysqlDBName).withUrlParam("serverTimezone", "UTC").withUrlParam("useJDBCCompliantTimezoneShift", "true").withInitScript("mysql-test-data.sql");
    jdbcContainer.start();
    if (osName.startsWith("linux")) {
        JdbcDatabaseDelegate databaseDelegate = new JdbcDatabaseDelegate(jdbcContainer, "");
        ScriptUtils.runInitScript(databaseDelegate, "mysql-test-data-linux.sql");
    }
    String jdbcUrl = jdbcContainer.getJdbcUrl();
    logger.debug("JDBC URL: {}", jdbcUrl);
    JdbcStorageConfig jdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), false, true, null, null, 10000);
    jdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("mysql", jdbcStorageConfig);
    JdbcStorageConfig jdbcStorageConfigNoWrite = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), false, false, null, null, 10000);
    jdbcStorageConfigNoWrite.setEnabled(true);
    cluster.defineStoragePlugin("mysql_no_write", jdbcStorageConfigNoWrite);
    if (osName.startsWith("linux")) {
        // adds storage plugin with case insensitive table names
        JdbcStorageConfig jdbcCaseSensitiveStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), true, true, null, null, 10000);
        jdbcCaseSensitiveStorageConfig.setEnabled(true);
        cluster.defineStoragePlugin("mysqlCaseInsensitive", jdbcCaseSensitiveStorageConfig);
    }
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) JdbcDatabaseDelegate(org.testcontainers.jdbc.JdbcDatabaseDelegate) BeforeClass(org.junit.BeforeClass)

Example 2 with JdbcDatabaseDelegate

use of org.testcontainers.jdbc.JdbcDatabaseDelegate in project drill by apache.

the class TestJdbcPluginWithMySQLIT method initMysql.

@BeforeClass
public static void initMysql() throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher));
    String osName = System.getProperty("os.name").toLowerCase();
    String mysqlDBName = "drill_mysql_test";
    DockerImageName imageName;
    if (osName.startsWith("linux") && "aarch64".equals(System.getProperty("os.arch"))) {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MARIADB).asCompatibleSubstituteFor("mysql");
    } else {
        imageName = DockerImageName.parse(DOCKER_IMAGE_MYSQL);
    }
    jdbcContainer = new MySQLContainer<>(imageName).withExposedPorts(3306).withConfigurationOverride("mysql_config_override").withUsername("mysqlUser").withPassword("mysqlPass").withDatabaseName(mysqlDBName).withUrlParam("serverTimezone", "UTC").withUrlParam("useJDBCCompliantTimezoneShift", "true").withInitScript("mysql-test-data.sql");
    jdbcContainer.start();
    if (osName.startsWith("linux")) {
        JdbcDatabaseDelegate databaseDelegate = new JdbcDatabaseDelegate(jdbcContainer, "");
        ScriptUtils.runInitScript(databaseDelegate, "mysql-test-data-linux.sql");
    }
    String jdbcUrl = jdbcContainer.getJdbcUrl();
    JdbcStorageConfig jdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), false, false, null, null, 10000);
    jdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("mysql", jdbcStorageConfig);
    if (osName.startsWith("linux")) {
        // adds storage plugin with case insensitive table names
        JdbcStorageConfig jdbcCaseSensitiveStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", jdbcUrl, jdbcContainer.getUsername(), jdbcContainer.getPassword(), true, false, null, null, 10000);
        jdbcCaseSensitiveStorageConfig.setEnabled(true);
        cluster.defineStoragePlugin("mysqlCaseInsensitive", jdbcCaseSensitiveStorageConfig);
    }
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) JdbcDatabaseDelegate(org.testcontainers.jdbc.JdbcDatabaseDelegate) BeforeClass(org.junit.BeforeClass)

Aggregations

BeforeClass (org.junit.BeforeClass)2 JdbcDatabaseDelegate (org.testcontainers.jdbc.JdbcDatabaseDelegate)2 DockerImageName (org.testcontainers.utility.DockerImageName)2