From 8d8c12fec4ac93104bce4c344be5865a717dec42 Mon Sep 17 00:00:00 2001 From: Kevin Wittek Date: Fri, 9 Jun 2017 23:26:48 +0200 Subject: [PATCH] Extract MariaDB into a separate repository. See #337 --- .../testcontainers/jdbc/JDBCDriverTest.java | 6 -- .../junit/SimpleMariaDBTest.java | 87 ------------------- .../test/resources/somepath/init_mariadb.sql | 5 -- .../somepath/mariadb_conf_override/my.cnf | 53 ----------- modules/mariadb/pom.xml | 59 ------------- .../containers/MariaDBContainer.java | 73 ---------------- .../containers/MariaDBContainerProvider.java | 16 ---- ...s.containers.JdbcDatabaseContainerProvider | 1 - .../resources/mariadb-default-conf/my.cnf | 46 ---------- pom.xml | 2 +- 10 files changed, 1 insertion(+), 347 deletions(-) delete mode 100644 modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMariaDBTest.java delete mode 100644 modules/jdbc-test/src/test/resources/somepath/init_mariadb.sql delete mode 100644 modules/jdbc-test/src/test/resources/somepath/mariadb_conf_override/my.cnf delete mode 100644 modules/mariadb/pom.xml delete mode 100644 modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java delete mode 100644 modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainerProvider.java delete mode 100644 modules/mariadb/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider delete mode 100644 modules/mariadb/src/main/resources/mariadb-default-conf/my.cnf diff --git a/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java b/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java index f29a19c14f1..8e663df8a45 100644 --- a/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java +++ b/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java @@ -42,13 +42,7 @@ public static Iterable data() { {"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false}, {"jdbc:tc:mysql://hostname/databasename", false, false, false}, {"jdbc:tc:postgresql://hostname/databasename", false, false, false}, - {"jdbc:tc:mariadb:10.1.16://hostname/databasename", false, false, false}, - {"jdbc:tc:mariadb://hostname/databasename", false, false, false}, - {"jdbc:tc:mariadb://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false}, - {"jdbc:tc:mariadb://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql", true, false, false}, - {"jdbc:tc:mariadb://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false}, {"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true}, - {"jdbc:tc:mariadb:10.1.16://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override", false, false, true} }); } diff --git a/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMariaDBTest.java b/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMariaDBTest.java deleted file mode 100644 index 1ad65e65465..00000000000 --- a/modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMariaDBTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.testcontainers.junit; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import lombok.NonNull; - -import org.apache.commons.lang.SystemUtils; -import org.junit.Test; -import org.testcontainers.containers.MariaDBContainer; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; -import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue; -import static org.junit.Assume.assumeFalse; - - -/** - * @author Miguel Gonzalez Sanchez - */ -public class SimpleMariaDBTest { - - @Test - public void testSimple() throws SQLException { - MariaDBContainer mariadb = new MariaDBContainer(); - mariadb.start(); - - try { - ResultSet resultSet = performQuery(mariadb, "SELECT 1"); - int resultSetInt = resultSet.getInt(1); - - assertEquals("A basic SELECT query succeeds", 1, resultSetInt); - } finally { - mariadb.stop(); - } - } - - @Test - public void testSpecificVersion() throws SQLException { - MariaDBContainer mariadbOldVersion = new MariaDBContainer("mariadb:5.5.51"); - mariadbOldVersion.start(); - - try { - ResultSet resultSet = performQuery(mariadbOldVersion, "SELECT VERSION()"); - String resultSetString = resultSet.getString(1); - - assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5.51")); - } finally { - mariadbOldVersion.stop(); - } - } - - @Test - public void testMariaDBWithCustomIniFile() throws SQLException { - assumeFalse(SystemUtils.IS_OS_WINDOWS); - MariaDBContainer mariadbCustomConfig = new MariaDBContainer("mariadb:10.1.16") - .withConfigurationOverride("somepath/mariadb_conf_override"); - mariadbCustomConfig.start(); - - try { - ResultSet resultSet = performQuery(mariadbCustomConfig, "SELECT @@GLOBAL.innodb_file_format"); - String result = resultSet.getString(1); - - assertEquals("The InnoDB file format has been set by the ini file content", "Barracuda", result); - } finally { - mariadbCustomConfig.stop(); - } - } - - @NonNull - protected ResultSet performQuery(MariaDBContainer containerRule, String sql) throws SQLException { - HikariConfig hikariConfig = new HikariConfig(); - hikariConfig.setJdbcUrl(containerRule.getJdbcUrl()); - hikariConfig.setUsername(containerRule.getUsername()); - hikariConfig.setPassword(containerRule.getPassword()); - - HikariDataSource ds = new HikariDataSource(hikariConfig); - Statement statement = ds.getConnection().createStatement(); - statement.execute(sql); - ResultSet resultSet = statement.getResultSet(); - - resultSet.next(); - return resultSet; - } -} diff --git a/modules/jdbc-test/src/test/resources/somepath/init_mariadb.sql b/modules/jdbc-test/src/test/resources/somepath/init_mariadb.sql deleted file mode 100644 index 2b00ee968b0..00000000000 --- a/modules/jdbc-test/src/test/resources/somepath/init_mariadb.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE bar ( - foo VARCHAR(255) -); - -INSERT INTO bar (foo) VALUES ('hello world'); \ No newline at end of file diff --git a/modules/jdbc-test/src/test/resources/somepath/mariadb_conf_override/my.cnf b/modules/jdbc-test/src/test/resources/somepath/mariadb_conf_override/my.cnf deleted file mode 100644 index 220060976ab..00000000000 --- a/modules/jdbc-test/src/test/resources/somepath/mariadb_conf_override/my.cnf +++ /dev/null @@ -1,53 +0,0 @@ -[mysqld] -port = 3306 -#socket = /tmp/mysql.sock -skip-external-locking -key_buffer_size = 16K -max_allowed_packet = 1M -table_open_cache = 4 -sort_buffer_size = 64K -read_buffer_size = 256K -read_rnd_buffer_size = 256K -net_buffer_length = 2K -thread_stack = 128K - - -innodb_file_format=Barracuda - - - - - -# Don't listen on a TCP/IP port at all. This can be a security enhancement, -# if all processes that need to connect to mysqld run on the same host. -# All interaction with mysqld must be made via Unix sockets or named pipes. -# Note that using this option without enabling named pipes on Windows -# (using the "enable-named-pipe" option) will render mysqld useless! -# -#skip-networking -#server-id = 1 - -# Uncomment the following if you want to log updates -#log-bin=mysql-bin - -# binary logging format - mixed recommended -#binlog_format=mixed - -# Causes updates to non-transactional engines using statement format to be -# written directly to binary log. Before using this option make sure that -# there are no dependencies between transactional and non-transactional -# tables such as in the statement INSERT INTO t_myisam SELECT * FROM -# t_innodb; otherwise, slaves may diverge from the master. -#binlog_direct_non_transactional_updates=TRUE - -# Uncomment the following if you are using InnoDB tables -innodb_data_file_path = ibdata1:10M:autoextend -# You can set .._buffer_pool_size up to 50 - 80 % -# of RAM but beware of setting memory usage too high -innodb_buffer_pool_size = 16M -#innodb_additional_mem_pool_size = 2M -# Set .._log_file_size to 25 % of buffer pool size -innodb_log_file_size = 5M -innodb_log_buffer_size = 8M -innodb_flush_log_at_trx_commit = 1 -innodb_lock_wait_timeout = 50 \ No newline at end of file diff --git a/modules/mariadb/pom.xml b/modules/mariadb/pom.xml deleted file mode 100644 index efb117eb0c0..00000000000 --- a/modules/mariadb/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - 4.0.0 - - - org.testcontainers - testcontainers-parent - 1.2.2-SNAPSHOT - ../../pom.xml - - - mariadb - TestContainers :: JDBC :: MariaDB - - - - ${project.groupId} - testcontainers - ${project.version} - - - ${project.groupId} - jdbc - ${project.version} - - - - - org.mariadb.jdbc - mariadb-java-client - 1.4.6 - test - - - - - com.zaxxer - HikariCP-java6 - 2.3.8 - test - - - commons-dbutils - commons-dbutils - 1.6 - test - - - org.apache.tomcat - tomcat-jdbc - 8.5.4 - - - org.vibur - vibur-dbcp - 9.0 - - - diff --git a/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java b/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java deleted file mode 100644 index 2bea9b8ad7b..00000000000 --- a/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.testcontainers.containers; - -/** - * Container implementation for the MariaDB project. - * - * @author Miguel Gonzalez Sanchez - */ -public class MariaDBContainer> extends JdbcDatabaseContainer { - - public static final String NAME = "mariadb"; - public static final String IMAGE = "mariadb"; - private static final Integer MARIADB_PORT = 3306; - private static final String MARIADB_USER = "test"; - private static final String MARIADB_PASSWORD = "test"; - private static final String MARIADB_DATABASE = "test"; - private static final String MY_CNF_CONFIG_OVERRIDE_PARAM_NAME = "TC_MY_CNF"; - - public MariaDBContainer() { - super(IMAGE + ":latest"); - } - - public MariaDBContainer(String dockerImageName) { - super(dockerImageName); - } - - @Override - protected Integer getLivenessCheckPort() { - return getMappedPort(MARIADB_PORT); - } - - @Override - protected void configure() { - optionallyMapResourceParameterAsVolume(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, "/etc/mysql/conf.d", "mariadb-default-conf"); - - addExposedPort(MARIADB_PORT); - addEnv("MYSQL_DATABASE", MARIADB_DATABASE); - addEnv("MYSQL_USER", MARIADB_USER); - addEnv("MYSQL_PASSWORD", MARIADB_PASSWORD); - addEnv("MYSQL_ROOT_PASSWORD", MARIADB_PASSWORD); - setCommand("mysqld"); - setStartupAttempts(3); - } - - @Override - public String getDriverClassName() { - return "org.mariadb.jdbc.Driver"; - } - - @Override - public String getJdbcUrl() { - return "jdbc:mariadb://" + getContainerIpAddress() + ":" + getMappedPort(MARIADB_PORT) + "/test"; - } - - @Override - public String getUsername() { - return MARIADB_USER; - } - - @Override - public String getPassword() { - return MARIADB_PASSWORD; - } - - @Override - public String getTestQueryString() { - return "SELECT 1"; - } - - public SELF withConfigurationOverride(String s) { - parameters.put(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, s); - return self(); - } -} diff --git a/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainerProvider.java b/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainerProvider.java deleted file mode 100644 index b3171b02911..00000000000 --- a/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainerProvider.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.testcontainers.containers; - -/** - * Factory for MariaDB containers. - */ -public class MariaDBContainerProvider extends JdbcDatabaseContainerProvider { - @Override - public boolean supports(String databaseType) { - return databaseType.equals(MariaDBContainer.NAME); - } - - @Override - public JdbcDatabaseContainer newInstance(String tag) { - return new MariaDBContainer(MariaDBContainer.IMAGE + ":" + tag); - } -} diff --git a/modules/mariadb/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/mariadb/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider deleted file mode 100644 index f5b51466d19..00000000000 --- a/modules/mariadb/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider +++ /dev/null @@ -1 +0,0 @@ -org.testcontainers.containers.MariaDBContainerProvider \ No newline at end of file diff --git a/modules/mariadb/src/main/resources/mariadb-default-conf/my.cnf b/modules/mariadb/src/main/resources/mariadb-default-conf/my.cnf deleted file mode 100644 index 3f6c80633e2..00000000000 --- a/modules/mariadb/src/main/resources/mariadb-default-conf/my.cnf +++ /dev/null @@ -1,46 +0,0 @@ -[mysqld] -port = 3306 -#socket = /tmp/mysql.sock -skip-external-locking -key_buffer_size = 16K -max_allowed_packet = 1M -table_open_cache = 4 -sort_buffer_size = 64K -read_buffer_size = 256K -read_rnd_buffer_size = 256K -net_buffer_length = 2K -thread_stack = 128K - -# Don't listen on a TCP/IP port at all. This can be a security enhancement, -# if all processes that need to connect to mysqld run on the same host. -# All interaction with mysqld must be made via Unix sockets or named pipes. -# Note that using this option without enabling named pipes on Windows -# (using the "enable-named-pipe" option) will render mysqld useless! -# -#skip-networking -#server-id = 1 - -# Uncomment the following if you want to log updates -#log-bin=mysql-bin - -# binary logging format - mixed recommended -#binlog_format=mixed - -# Causes updates to non-transactional engines using statement format to be -# written directly to binary log. Before using this option make sure that -# there are no dependencies between transactional and non-transactional -# tables such as in the statement INSERT INTO t_myisam SELECT * FROM -# t_innodb; otherwise, slaves may diverge from the master. -#binlog_direct_non_transactional_updates=TRUE - -# Uncomment the following if you are using InnoDB tables -innodb_data_file_path = ibdata1:10M:autoextend -# You can set .._buffer_pool_size up to 50 - 80 % -# of RAM but beware of setting memory usage too high -innodb_buffer_pool_size = 16M -#innodb_additional_mem_pool_size = 2M -# Set .._log_file_size to 25 % of buffer pool size -innodb_log_file_size = 5M -innodb_log_buffer_size = 8M -innodb_flush_log_at_trx_commit = 1 -innodb_lock_wait_timeout = 50 \ No newline at end of file diff --git a/pom.xml b/pom.xml index b3fb3361c7c..105f2361123 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ modules/postgresql modules/selenium modules/nginx - modules/mariadb + modules/jdbc-test