Destroy docker container properly.
Since JdbcContaieners are AutoClosables Spring will call `close()` on shut down. Original pull request #2379
This commit is contained in:
committed by
Jens Schauder
parent
f0e8a289d0
commit
d49f0ca29d
@@ -63,6 +63,7 @@ import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
*
|
||||
* @author Gabriel Basilio
|
||||
* @author Greg Turnquist
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@Transactional
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@@ -190,26 +191,21 @@ public class MySqlStoredProcedureIntegrationTests {
|
||||
@EnableTransactionManagement
|
||||
static class Config {
|
||||
|
||||
private MySQLContainer<?> MYSQL_CONTAINER;
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
|
||||
if (MYSQL_CONTAINER == null) {
|
||||
|
||||
MYSQL_CONTAINER = new MySQLContainer<>("mysql:8.0.24") //
|
||||
@SuppressWarnings("resource")
|
||||
@Bean(initMethod = "start")
|
||||
public MySQLContainer<?> container() {
|
||||
return new MySQLContainer<>("mysql:8.0.24") //
|
||||
.withUsername("test") //
|
||||
.withPassword("test") //
|
||||
.withConfigurationOverride("");
|
||||
MYSQL_CONTAINER.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource(MySQLContainer<?> container) {
|
||||
MysqlDataSource dataSource = new MysqlDataSource();
|
||||
dataSource.setUrl(MYSQL_CONTAINER.getJdbcUrl());
|
||||
dataSource.setUser("root");
|
||||
dataSource.setPassword(MYSQL_CONTAINER.getPassword());
|
||||
dataSource.setDatabaseName(MYSQL_CONTAINER.getDatabaseName());
|
||||
|
||||
dataSource.setUrl(container.getJdbcUrl());
|
||||
dataSource.setUser(container.getUsername());
|
||||
dataSource.setPassword(container.getPassword());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ import org.testcontainers.containers.PostgreSQLContainer;
|
||||
*
|
||||
* @author Gabriel Basilio
|
||||
* @author Greg Turnquist
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@Transactional
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@@ -193,23 +194,19 @@ public class PostgresStoredProcedureIntegrationTests {
|
||||
@EnableTransactionManagement
|
||||
static class Config {
|
||||
|
||||
private PostgreSQLContainer<?> POSTGRESQL_CONTAINER;
|
||||
@SuppressWarnings("resource")
|
||||
@Bean(initMethod = "start")
|
||||
public PostgreSQLContainer<?> container() {
|
||||
return new PostgreSQLContainer<>("postgres:9.6.12") //
|
||||
.withUsername("postgres");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
|
||||
if (POSTGRESQL_CONTAINER == null) {
|
||||
|
||||
POSTGRESQL_CONTAINER = new PostgreSQLContainer<>("postgres:9.6.12") //
|
||||
.withUsername("postgres");
|
||||
POSTGRESQL_CONTAINER.start();
|
||||
}
|
||||
|
||||
public DataSource dataSource(PostgreSQLContainer<?> container) {
|
||||
PGSimpleDataSource dataSource = new PGSimpleDataSource();
|
||||
dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl());
|
||||
dataSource.setUser(POSTGRESQL_CONTAINER.getUsername());
|
||||
dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword());
|
||||
|
||||
dataSource.setUrl(container.getJdbcUrl());
|
||||
dataSource.setUser(container.getUsername());
|
||||
dataSource.setPassword(container.getPassword());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user