9
9
import org .junit .runner .RunWith ;
10
10
import org .junit .runners .Parameterized ;
11
11
import org .junit .runners .Parameterized .Parameter ;
12
+ import org .testcontainers .containers .JdbcDatabaseContainer ;
12
13
13
14
import java .sql .Connection ;
14
15
import java .sql .ResultSet ;
18
19
import static java .util .Arrays .asList ;
19
20
import static org .junit .Assume .assumeFalse ;
20
21
import static org .rnorth .visibleassertions .VisibleAssertions .assertEquals ;
22
+ import static org .rnorth .visibleassertions .VisibleAssertions .assertNotNull ;
23
+ import static org .rnorth .visibleassertions .VisibleAssertions .assertNull ;
21
24
import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
22
25
23
26
@ RunWith (Parameterized .class )
@@ -32,6 +35,7 @@ public class JDBCDriverTest {
32
35
@ Parameter (3 )
33
36
public boolean performTestForCustomIniFile ;
34
37
38
+
35
39
@ Parameterized .Parameters (name = "{index} - {0}" )
36
40
public static Iterable <Object []> data () {
37
41
return asList (
@@ -48,7 +52,7 @@ public static Iterable<Object[]> data() {
48
52
{"jdbc:tc:mariadb://hostname/databasename?TC_INITSCRIPT=somepath/init_mariadb.sql" , true , false , false },
49
53
{"jdbc:tc:mariadb://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction" , true , false , false },
50
54
{"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override" , false , false , true },
51
- {"jdbc:tc:mariadb:10.1.16://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override" , false , false , true }
55
+ {"jdbc:tc:mariadb:10.1.16://hostname/databasename?TC_MY_CNF=somepath/mariadb_conf_override" , false , false , true },
52
56
});
53
57
}
54
58
@@ -84,6 +88,27 @@ public void test() throws SQLException {
84
88
}
85
89
}
86
90
91
+ @ Test
92
+ public void shouldStopContainerWhenAllConnectionsClosed () throws SQLException {
93
+ final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename" ;
94
+
95
+ performSimpleTest (jdbcUrl );
96
+
97
+ JdbcDatabaseContainer <?> container = ContainerDatabaseDriver .getContainer (jdbcUrl );
98
+ assertNull ("Database container instance is null as expected" , container );
99
+ }
100
+
101
+ @ Test
102
+ public void shouldNotStopDaemonContainerWhenAllConnectionsClosed () throws SQLException {
103
+ final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename?TC_DAEMON=true" ;
104
+
105
+ performSimpleTest (jdbcUrl );
106
+
107
+ JdbcDatabaseContainer <?> container = ContainerDatabaseDriver .getContainer (jdbcUrl );
108
+ assertNotNull ("Database container instance is not null as expected" , container );
109
+ assertTrue ("Database container is running as expected" , container .isRunning ());
110
+ }
111
+
87
112
private void performSimpleTest (String jdbcUrl ) throws SQLException {
88
113
try (HikariDataSource dataSource = getDataSource (jdbcUrl , 1 )) {
89
114
boolean result = new QueryRunner (dataSource ).query ("SELECT 1" , rs -> {
0 commit comments