Skip to content

Commit

Permalink
Test rework to cover more database/driver versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Mar 10, 2018
1 parent 40af152 commit 36c2880
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
31 changes: 29 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.avast.gradle:gradle-docker-compose-plugin:0.5.2"
classpath "com.avast.gradle:gradle-docker-compose-plugin:0.7.1"
}
}

Expand Down Expand Up @@ -51,14 +51,37 @@ exposedDialectTestWithDocker.doFirst {

dockerCompose.isRequiredBy(exposedDialectTestWithDocker)

task mysql56Test(type: Test) {
apply from: 'src/test-conf/mysql56.gradle'
// composeUp.execute()
// exposedDialectTestWithDocker.execute()
println "MYSQL"
// environment 'DB_VERSION' "5.6"
}

dockerCompose {
useComposeFiles = ['docker-compose-' + dialect + '.yml']
// def dialectProp = System.getProperty("dialect", "")
// println dialectProp
// println ext.dialect
mysql {
environment.put 'DB_VERSION', '5.6'

useComposeFiles = ['src/test-conf/compose/docker-compose-mysql.yml']
isRequiredBy(project.tasks.mysql56Test)
}
// }
captureContainersOutput = true
removeVolumes = true
environment.put 'COMPOSE_CONVERT_WINDOWS_PATHS', 'true'
waitForHealthyStateTimeout = Duration.ofMinutes(60)
}

//gradle.taskGraph.whenReady {taskGraph ->
// if (taskGraph.hasTask(mysql56Test)) {
//// System.setProperty("dialect", "oracle")
// }
//}

artifacts {
archives sourcesJar
}
Expand Down Expand Up @@ -88,6 +111,10 @@ dependencies {
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.2.1.jre7'
}



//mysql56Test.dependsOn(mysql)

test {
jvmArgs "-XX:MaxPermSize=256m"
testLogging {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ group=org.jetbrains.exposed
version=0.10.2-SNAPSHOT
kotlin_version=1.2.30
spring_version=4.3.7.RELEASE
dialect=
dialect=custom
6 changes: 4 additions & 2 deletions src/main/kotlin/org/jetbrains/exposed/sql/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Database private constructor(val connector: () -> Connection) {

val url: String by lazy { metadata.url }

internal val dialect by lazy {
var dialect : DatabaseDialect = run {
val name = url.removePrefix("jdbc:").substringBefore(':')
dialects[name.toLowerCase()]?.invoke() ?: error("No dialect registered for $name. URL=$url")
}
Expand Down Expand Up @@ -61,7 +61,7 @@ class Database private constructor(val connector: () -> Connection) {
private fun Char.isIdentifierStart(): Boolean = this in 'a'..'z' || this in 'A'..'Z' || this == '_' || this in extraNameCharacters

companion object {
private val dialects = ConcurrentHashMap<String, () ->DatabaseDialect>()
private val dialects = ConcurrentHashMap<String, ()->DatabaseDialect>()

init {
registerDialect(H2Dialect.dialectName) { H2Dialect() }
Expand All @@ -76,6 +76,8 @@ class Database private constructor(val connector: () -> Connection) {
dialects[prefix] = dialect
}

fun getDialect(dialectName: String) = dialects[dialectName]

private fun doConnect(getNewConnection: () -> Connection, setupConnection: (Connection) -> Unit = {},
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it, DEFAULT_ISOLATION_LEVEL) }
): Database {
Expand Down
8 changes: 8 additions & 0 deletions src/test-conf/compose/docker-compose-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.5'

services:
mysql:
image: "mysql:${DB_VERSION:-latest}"
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/test-conf/mysql56.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
"mysql:mysql-connector-java:5.1.44"
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,21 @@ enum class TestDB(val connection: String, val driver: String, val user: String =
}),
SQLSERVER("jdbc:sqlserver://${System.getProperty("exposed.test.sqlserver.host", "192.168.99.100")}" +
":${System.getProperty("exposed.test.sqlserver.port", "32781")}",
"com.microsoft.sqlserver.jdbc.SQLServerDriver", "SA", "yourStrong(!)Password");
"com.microsoft.sqlserver.jdbc.SQLServerDriver", "SA", "yourStrong(!)Password"),

fun connect() = Database.connect(connection, user = user, password = pass, driver = driver)
CUSTOM(System.getProperty("exposed.test.custom.url", ""),
System.getProperty("exposed.test.custom.driver", ""),
System.getProperty("exposed.test.custom.user", ""),
System.getProperty("exposed.test.custom.pass", "")
);

fun connect() = Database.connect(connection, user = user, password = pass, driver = driver).also { db ->
if (this == CUSTOM) {
System.getProperty("exposed.test.custom.dialect")?.let { dialect ->
db.dialect = Database.getDialect(dialect)!!()
}
}
}

companion object {
fun enabledInTests(): List<TestDB> {
Expand Down

0 comments on commit 36c2880

Please sign in to comment.