27
27
import org .testcontainers .oracle .OracleContainer ;
28
28
import org .testcontainers .utility .DockerImageName ;
29
29
30
+ import com .zaxxer .hikari .HikariConfig ;
31
+ import com .zaxxer .hikari .HikariDataSource ;
32
+
30
33
/**
31
34
* {@link DataSource} setup for Oracle Database 23ai FREE. Starts a docker container with an Oracle database.
32
35
*
33
- * @see <a href=
34
- * "https://github.com/gvenzl/oci-oracle-free">Oracle
35
- * Docker Image</a>
36
+ * @see <a href= "https://github.com/gvenzl/oci-oracle-free">Oracle Docker Image</a>
36
37
* @see <a href="https://www.testcontainers.org/modules/databases/oraclexe/">Testcontainers Oracle</a>
37
38
* @author Thomas Lang
38
39
* @author Jens Schauder
@@ -44,16 +45,16 @@ public class OracleDataSourceConfiguration extends DataSourceConfiguration {
44
45
45
46
private static final Log LOG = LogFactory .getLog (OracleDataSourceConfiguration .class );
46
47
47
- private static OracleContainer ORACLE_CONTAINER ;
48
+ private static DataSource DATA_SOURCE ;
48
49
49
50
public OracleDataSourceConfiguration (TestClass testClass , Environment environment ) {
50
51
super (testClass , environment );
51
52
}
52
53
53
54
@ Override
54
- protected DataSource createDataSource () {
55
+ protected synchronized DataSource createDataSource () {
55
56
56
- if (ORACLE_CONTAINER == null ) {
57
+ if (DATA_SOURCE == null ) {
57
58
58
59
LOG .info ("Oracle starting..." );
59
60
DockerImageName dockerImageName = DockerImageName .parse ("gvenzl/oracle-free:23-slim" );
@@ -63,21 +64,33 @@ protected DataSource createDataSource() {
63
64
container .start ();
64
65
LOG .info ("Oracle started" );
65
66
66
- ORACLE_CONTAINER = container ;
67
+ initDb (container .getJdbcUrl (),container .getUsername (), container .getPassword ());
68
+
69
+ DATA_SOURCE = poolDataSource (new DriverManagerDataSource (container .getJdbcUrl (),
70
+ container .getUsername (), container .getPassword ()));
67
71
}
72
+ return DATA_SOURCE ;
73
+ }
74
+
75
+ private DataSource poolDataSource (DataSource dataSource ) {
76
+
77
+ HikariConfig config = new HikariConfig ();
78
+ config .setDataSource (dataSource );
68
79
69
- initDb ();
80
+ config .setMaximumPoolSize (10 );
81
+ config .setIdleTimeout (30000 );
82
+ config .setMaxLifetime (600000 );
83
+ config .setConnectionTimeout (30000 );
70
84
71
- return new DriverManagerDataSource (ORACLE_CONTAINER .getJdbcUrl (), ORACLE_CONTAINER .getUsername (),
72
- ORACLE_CONTAINER .getPassword ());
85
+ return new HikariDataSource (config );
73
86
}
74
87
75
- private void initDb () {
88
+ private void initDb (String jdbcUrl , String username , String password ) {
76
89
77
- final DriverManagerDataSource dataSource = new DriverManagerDataSource (ORACLE_CONTAINER . getJdbcUrl () , "system" ,
78
- ORACLE_CONTAINER . getPassword () );
90
+ final DriverManagerDataSource dataSource = new DriverManagerDataSource (jdbcUrl , "system" ,
91
+ password );
79
92
final JdbcTemplate jdbc = new JdbcTemplate (dataSource );
80
- jdbc .execute ("GRANT ALL PRIVILEGES TO " + ORACLE_CONTAINER . getUsername () );
93
+ jdbc .execute ("GRANT ALL PRIVILEGES TO " + username );
81
94
}
82
95
83
96
@ Override
0 commit comments