@Override public JdbcDatabaseContainer newInstance(String tag) { if (tag != null) { return new MySQLContainer(MySQLContainer.IMAGE + ":" + tag); } else { return newInstance(); } }
@Test public void testCommandOverride() throws SQLException { MySQLContainer mysqlCustomConfig = (MySQLContainer) new MySQLContainer().withCommand("mysqld --auto_increment_increment=42"); mysqlCustomConfig.start(); try { ResultSet resultSet = performQuery(mysqlCustomConfig, "show variables like 'auto_increment_increment'"); String result = resultSet.getString("Value"); assertEquals("Auto increment increment should be overriden by command line", "42", result); } finally { mysqlCustomConfig.stop(); } }
@Test public void testMySQL8() throws SQLException { assumeFalse(SystemUtils.IS_OS_WINDOWS); MySQLContainer container = new MySQLContainer<>("mysql:8.0.11") .withCommand("mysqld --default-authentication-plugin=mysql_native_password"); container.start(); try { ResultSet resultSet = performQuery(container, "SELECT VERSION()"); String resultSetString = resultSet.getString(1); assertTrue("The database version can be set using a container rule parameter", "8.0.11".equals(resultSetString)); } finally { container.stop(); } }
@Test public void testSpecificVersion() throws SQLException { MySQLContainer mysqlOldVersion = (MySQLContainer) new MySQLContainer("mysql:5.5") .withConfigurationOverride("somepath/mysql_conf_override") .withLogConsumer(new Slf4jLogConsumer(logger)); mysqlOldVersion.start(); try { ResultSet resultSet = performQuery(mysqlOldVersion, "SELECT VERSION()"); String resultSetString = resultSet.getString(1); assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5")); } finally { mysqlOldVersion.stop(); } }
@Test public void testExplicitInitScript() throws SQLException { try (MySQLContainer container = (MySQLContainer) new MySQLContainer() .withInitScript("somepath/init_mysql.sql") .withLogConsumer(new Slf4jLogConsumer(logger))) { container.start(); ResultSet resultSet = performQuery(container, "SELECT foo FROM bar"); String firstColumnValue = resultSet.getString(1); assertEquals("Value from init script should equal real value", "hello world", firstColumnValue); } }
@Test public void testMySQLWithCustomIniFile() throws SQLException { assumeFalse(SystemUtils.IS_OS_WINDOWS); MySQLContainer mysqlCustomConfig = new MySQLContainer("mysql:5.6") .withConfigurationOverride("somepath/mysql_conf_override"); mysqlCustomConfig.start(); try { ResultSet resultSet = performQuery(mysqlCustomConfig, "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 { mysqlCustomConfig.stop(); } }
@Test public void testSimple() throws SQLException { MySQLContainer mysql = (MySQLContainer) new MySQLContainer() .withConfigurationOverride("somepath/mysql_conf_override") .withLogConsumer(new Slf4jLogConsumer(logger)); mysql.start(); try { ResultSet resultSet = performQuery(mysql, "SELECT 1"); int resultSetInt = resultSet.getInt(1); assertEquals("A basic SELECT query succeeds", 1, resultSetInt); } finally { mysql.stop(); } }
@Test public void testEmptyPasswordWithNonRootUser() { MySQLContainer container = (MySQLContainer) new MySQLContainer("mysql:5.5").withDatabaseName("TEST") .withUsername("test").withPassword("").withEnv("MYSQL_ROOT_HOST", "%"); try { container.start(); fail("ContainerLaunchException expected to be thrown"); } catch (ContainerLaunchException e) { } finally { container.stop(); } }
@Override public JdbcDatabaseContainer newInstance(String tag) { if (tag != null) { return new MySQLContainer(MySQLContainer.IMAGE + ":" + tag); } else { return newInstance(); } }