Skip to content

Commit

Permalink
Prevent db containers to restart in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Aug 24, 2023
1 parent 4654ff8 commit 641a6a9
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 82 deletions.
48 changes: 48 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.exposed.gradle.Versions
import org.jetbrains.exposed.gradle.configureDetekt
import org.jetbrains.exposed.gradle.configurePublishing
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
Expand All @@ -8,6 +10,8 @@ plugins {
kotlin("jvm") apply true
id("io.gitlab.arturbosch.detekt")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"

id("com.avast.gradle.docker-compose")
}

repositories {
Expand Down Expand Up @@ -52,3 +56,47 @@ subprojects {
}
}
}

class DB(val name: String, val port: Int, val dependency: String)

val dbs = listOf(
DB("mysql", 3306, "mysql:mysql-connector-java:${Versions.mysql51}"),
DB("mariadb", 3306, "org.mariadb.jdbc:mariadb-java-client:${Versions.mariaDB_v2}")
)

dockerCompose {
dbs.forEach {
nested(it.name).apply {
useComposeFiles.set(listOf("buildScripts/docker/docker-compose-${it.name}.yml"))
stopContainers.set(false)
}
}
}

subprojects {
if (name == "exposed-bom") return@subprojects

apply(plugin = "org.jetbrains.kotlin.jvm")

val testTasks = dbs.map {
tasks.register<Test>("test${it.name.capitalized()}") {

dependsOn(rootProject.tasks.getByName("${it.name}ComposeUp"))
finalizedBy(rootProject.tasks.getByName("${it.name}ComposeDown"))
systemProperties["exposed.test.dialects"] = it.name
systemProperties["exposed.test.db.port"] = it.port.toString()

description = "Runs tests using $it database"
group = "verification"
}
}

dependencies {
dbs.forEach {
testRuntimeOnly(it.dependency)
}
}

val test by tasks
test.dependsOn(testTasks)
}
4 changes: 2 additions & 2 deletions buildScripts/docker/docker-compose-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
image: mariadb
restart: always
ports:
- "3306"
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'testdb'
4 changes: 2 additions & 2 deletions buildScripts/docker/docker-compose-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
image: mysql:5.7
restart: always
ports:
- "3306"
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'testdb'
2 changes: 1 addition & 1 deletion buildScripts/docker/docker-compose-oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ services:
WEB_CONSOLE: "true"
DBCA_TOTAL_MEMORY: 1024
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
USE_UTF8_IF_CHARSET_EMPTY: "true"
USE_UTF8_IF_CHARSET_EMPTY: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ object Versions {
/** Spring **/
const val springFramework = "5.3.29"
const val springBoot = "2.7.14"

/** Test Dependencies **/
const val testContainers = "1.18.3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open class DBTestWithDockerCompose(dialect: String, @get:Input val port: Int, @g
)
captureContainersOutput.set(true)
removeVolumes.set(true)
stopContainers.set(false)

waitForHealthyStateTimeout.set(Duration.ofMinutes(60))
}
Expand Down
23 changes: 23 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ This project and the corresponding community is governed by
the [JetBrains Open Source and Community Code of Conduct](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct).
Independently of how you'd like to contribute, please make sure you read and comply with it.

## Setup

### Testing on Apple Silicon
To run Oracle XE tests, you need to install [Colima](https://github.com/abiosoft/colima) container runtime. It will work in pair with your docker installation.
```shell
brew install
```

After installing, you need to start the colima daemon in arch x86_64 mode:
```shel
colima start --arch x86_64 --memory 4 --network-address
```

Make sure that colima is used as default docker context:
```shell
docker context list
```

If not, set it as default:
```shell
docker context use colima
```

### Code

#### Pull Requests
Expand Down
1 change: 0 additions & 1 deletion exposed-java-time/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
kotlin("jvm") apply true
kotlin("plugin.serialization") apply true
id("testWithDBs")
}

repositories {
Expand Down
1 change: 0 additions & 1 deletion exposed-jodatime/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
kotlin("jvm") apply true
kotlin("plugin.serialization") apply true
id("testWithDBs")
}

repositories {
Expand Down
1 change: 0 additions & 1 deletion exposed-json/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import org.jetbrains.exposed.gradle.Versions
plugins {
kotlin("jvm") apply true
kotlin("plugin.serialization") apply true
id("testWithDBs")
}

repositories {
Expand Down
1 change: 0 additions & 1 deletion exposed-kotlin-datetime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
kotlin("jvm") apply true
kotlin("plugin.serialization") apply true
id("testWithDBs")
}

repositories {
Expand Down
1 change: 0 additions & 1 deletion exposed-money/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
kotlin("jvm") apply true
id("testWithDBs")
}

repositories {
Expand Down
16 changes: 8 additions & 8 deletions exposed-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.jetbrains.exposed.gradle.Versions

plugins {
kotlin("jvm") apply true
id("testWithDBs")
}

repositories {
Expand All @@ -13,22 +12,23 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", Versions.kotlinCoroutines)
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-debug", Versions.kotlinCoroutines)

implementation(kotlin("test-junit"))
implementation("junit", "junit", "4.12")
implementation("org.hamcrest", "hamcrest-library", "1.3")

implementation(project(":exposed-core"))
implementation(project(":exposed-jdbc"))
implementation(project(":exposed-dao"))
implementation(project(":exposed-crypt"))
implementation(kotlin("test-junit"))

implementation("org.slf4j", "slf4j-api", Versions.slf4j)
implementation("org.apache.logging.log4j", "log4j-slf4j-impl", Versions.log4j2)
implementation("org.apache.logging.log4j", "log4j-api", Versions.log4j2)
implementation("org.apache.logging.log4j", "log4j-core", Versions.log4j2)
implementation("junit", "junit", "4.12")
implementation("org.hamcrest", "hamcrest-library", "1.3")
implementation("com.zaxxer", "HikariCP", "5.0.1")
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-debug", Versions.kotlinCoroutines)

implementation("org.testcontainers", "mysql", Versions.testContainers)
implementation("org.testcontainers", "postgresql", Versions.testContainers)
implementation("com.zaxxer", "HikariCP", "5.0.1")
testCompileOnly("org.postgresql", "postgresql", Versions.postgre)
testCompileOnly("com.impossibl.pgjdbc-ng", "pgjdbc-ng", Versions.postgreNG)
compileOnly("com.h2database", "h2", Versions.h2)
Expand Down
Loading

0 comments on commit 641a6a9

Please sign in to comment.