Java Code Examples for org.testcontainers.containers.MySQLContainer#stop()
The following examples show how to use
org.testcontainers.containers.MySQLContainer#stop() .
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(); } }