Skip to content

Commit 6981e14

Browse files
try fix oracle connection issue
1 parent e1dd6f5 commit 6981e14

File tree

6 files changed

+478
-513
lines changed

6 files changed

+478
-513
lines changed
Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package org.ktorm.support.oracle
22

3+
import org.junit.ClassRule
34
import org.ktorm.BaseTest
45
import org.ktorm.database.Database
56
import org.testcontainers.containers.OracleContainer
6-
import java.sql.Connection
7-
import java.sql.DriverManager
8-
import kotlin.concurrent.thread
97

108
abstract class BaseOracleTest : BaseTest() {
119

1210
override fun init() {
13-
database = Database.connect(alwaysQuoteIdentifiers = true) {
14-
object : Connection by connection {
15-
override fun close() {
16-
// do nothing...
17-
}
18-
}
19-
}
11+
database = Database.connect(
12+
url = container.jdbcUrl,
13+
driver = container.driverClassName,
14+
user = container.username,
15+
password = container.password,
16+
alwaysQuoteIdentifiers = true
17+
)
2018

2119
execSqlScript("init-oracle-data.sql")
2220
}
@@ -25,28 +23,11 @@ abstract class BaseOracleTest : BaseTest() {
2523
execSqlScript("drop-oracle-data.sql")
2624
}
2725

28-
companion object : OracleContainer("zerda/oracle-database:11.2.0.2-xe") {
29-
lateinit var connection: Connection
30-
31-
init {
26+
companion object {
27+
@JvmField
28+
@ClassRule
29+
val container = OracleContainer("zerda/oracle-database:11.2.0.2-xe")
3230
// At least 1 GB memory is required by Oracle.
33-
withCreateContainerCmdModifier { cmd -> cmd.hostConfig?.withShmSize((1 * 1024 * 1024 * 1024).toLong()) }
34-
// Start the container when it's first used.
35-
start()
36-
// Stop the container when the process exits.
37-
Runtime.getRuntime().addShutdownHook(thread(start = false) { stop() })
38-
}
39-
40-
override fun start() {
41-
super.start()
42-
43-
Class.forName(driverClassName)
44-
connection = DriverManager.getConnection(jdbcUrl, username, password)
45-
}
46-
47-
override fun stop() {
48-
connection.close()
49-
super.stop()
50-
}
31+
.withCreateContainerCmdModifier { cmd -> cmd.hostConfig?.withShmSize((1 * 1024 * 1024 * 1024).toLong()) }
5132
}
5233
}

ktorm-support-oracle/src/test/kotlin/org/ktorm/support/oracle/CommonTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CommonTest : BaseOracleTest() {
106106

107107
@Test
108108
fun testSchema() {
109-
val t = object : Table<Department>("t_department", schema = username.uppercase()) {
109+
val t = object : Table<Department>("t_department", schema = container.username.uppercase()) {
110110
val id = int("id").primaryKey().bindTo { it.id }
111111
val name = varchar("name").bindTo { it.name }
112112
}

0 commit comments

Comments
 (0)