Java Code Examples for org.testcontainers.containers.MySQLContainer#start()
The following examples show how to use
org.testcontainers.containers.MySQLContainer#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleMySQLTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void testWithAdditionalUrlParamTimeZone() throws SQLException { MySQLContainer mysql = (MySQLContainer) new MySQLContainer() .withUrlParam("serverTimezone", "Europe/Zurich") .withEnv("TZ", "Europe/Zurich") .withLogConsumer(new Slf4jLogConsumer(logger)); mysql.start(); try(Connection connection = mysql.createConnection("")) { Statement statement = connection.createStatement(); statement.execute("SELECT NOW();"); try (ResultSet resultSet = statement.getResultSet()) { resultSet.next(); // checking that the time_zone MySQL is Europe/Zurich LocalDateTime localDateTime = resultSet.getObject(1, LocalDateTime.class); ZonedDateTime actualDateTime = localDateTime.atZone(ZoneId.of("Europe/Zurich")) .truncatedTo(ChronoUnit.MINUTES); ZonedDateTime expectedDateTime = ZonedDateTime.now(ZoneId.of("Europe/Zurich")) .truncatedTo(ChronoUnit.MINUTES); String message = String.format("MySQL time zone is not Europe/Zurich. MySQL date:%s, current date:%s", actualDateTime, expectedDateTime); assertTrue(message, actualDateTime.equals(expectedDateTime)); } } finally { mysql.stop(); } }
Example 2
Source File: SimpleMySQLTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void testWithAdditionalUrlParamMultiQueries() throws SQLException { MySQLContainer mysql = (MySQLContainer) new MySQLContainer() .withUrlParam("allowMultiQueries", "true") .withLogConsumer(new Slf4jLogConsumer(logger)); mysql.start(); try(Connection connection = mysql.createConnection("")) { Statement statement = connection.createStatement(); String multiQuery = "DROP TABLE IF EXISTS bar; " + "CREATE TABLE bar (foo VARCHAR(20)); " + "INSERT INTO bar (foo) VALUES ('hello world');"; statement.execute(multiQuery); statement.execute("SELECT foo FROM bar;"); try(ResultSet resultSet = statement.getResultSet()) { resultSet.next(); String firstColumnValue = resultSet.getString(1); assertEquals("Value from bar should equal real value", "hello world", firstColumnValue); } } finally { mysql.stop(); } }
Example 3
Source File: SimpleMySQLTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void testWithAdditionalUrlParamInJdbcUrl() { MySQLContainer mysql = (MySQLContainer) new MySQLContainer() .withUrlParam("allowMultiQueries", "true") .withUrlParam("rewriteBatchedStatements", "true") .withLogConsumer(new Slf4jLogConsumer(logger)); try { mysql.start(); String jdbcUrl = mysql.getJdbcUrl(); assertThat(jdbcUrl, containsString("?")); assertThat(jdbcUrl, containsString("&")); assertThat(jdbcUrl, containsString("rewriteBatchedStatements=true")); assertThat(jdbcUrl, containsString("allowMultiQueries=true")); } finally { mysql.stop(); } }
Example 4
Source File: SqlTestUtil.java From kork with Apache License 2.0 | 6 votes |
@Deprecated public static TestDatabase initPreviousTcMysqlDatabase() { MySQLContainer container = new MySQLContainer("mysql:5.7.22") .withDatabaseName("previous") .withUsername("test") .withPassword("test"); container.start(); String jdbcUrl = String.format( "%s?user=%s&password=%s", container.getJdbcUrl(), container.getUsername(), container.getPassword()); return initDatabase(jdbcUrl, SQLDialect.MYSQL, "previous"); }
Example 5
Source File: ApolloMySQL.java From apollo with Apache License 2.0 | 5 votes |
public ApolloMySQL() throws SQLException, IOException, ScriptException { // Create mysql instance logger.info("Starting MySQL container"); mysql = new MySQLContainer("mysql:5.7.22"); mysql.start(); }
Example 6
Source File: SqlTestUtil.java From kork with Apache License 2.0 | 5 votes |
public static TestDatabase initDualTcMysqlDatabases() { MySQLContainer container = new MySQLContainer("mysql:5.7.22") .withDatabaseName("current") .withUsername("test") .withPassword("test"); container.start(); String rootJdbcUrl = String.format( "%s?user=%s&password=%s", container.getJdbcUrl(), "root", container.getPassword()); try { Connection rootCon = DriverManager.getConnection(rootJdbcUrl); rootCon.createStatement().executeUpdate("create database previous"); rootCon.createStatement().executeUpdate("grant all privileges on previous.* to 'test'@'%'"); rootCon.close(); } catch (SQLException e) { throw new RuntimeException("Error setting up testcontainer database", e); } String currentJdbcUrl = String.format( "%s?user=%s&password=%s", container.getJdbcUrl(), container.getUsername(), container.getPassword()); String previousJdbcUrl = currentJdbcUrl.replace("/current", "/previous"); TestDatabase currentTDB = initDatabase(currentJdbcUrl, SQLDialect.MYSQL, "current"); TestDatabase previousTDB = initDatabase(previousJdbcUrl, SQLDialect.MYSQL, "previous"); return new TestDatabase( currentTDB.dataSource, currentTDB.context, currentTDB.liquibase, previousTDB.dataSource, previousTDB.context, previousTDB.liquibase); }