Skip to content

Commit

Permalink
fixup! Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Sep 8, 2023
1 parent 916d53d commit 7d4d4f5
Show file tree
Hide file tree
Showing 28 changed files with 323 additions and 148 deletions.
16 changes: 5 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ subprojects {
}
}

testDb("mariadb") {
port = 3000
testDb("mariadb_v2") {
dialects("mariadb")
container = "mariadb"
port = 3000
dependencies {
dependency("org.mariadb.jdbc:mariadb-java-client:${Versions.mariaDB_v2}")
}
Expand All @@ -119,17 +120,9 @@ subprojects {
}
}

testDb("mariadb_v2") {
dialects("mariadb")
container = "mariadb"
port = 3000
dependencies {
dependency("org.mariadb.jdbc:mariadb-java-client:${Versions.mariaDB_v2}")
}
}

testDb("oracle") {
port = 3003
colima = true
dialects("oracle")
dependencies {
dependency("com.oracle.database.jdbc:ojdbc8:${Versions.oracle12}")
Expand All @@ -156,6 +149,7 @@ subprojects {

testDb("sqlserver") {
port = 3005
dialects("sqlserver")
dependencies {
dependency("com.microsoft.sqlserver:mssql-jdbc:${Versions.sqlserver}")
}
Expand Down
4 changes: 0 additions & 4 deletions buildScripts/docker/docker-compose-oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ services:
ports:
- "3003:1521"
environment:
# 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"
ORACLE_PASSWORD: "Oracle18"
45 changes: 40 additions & 5 deletions buildSrc/src/main/kotlin/org/jetbrains/exposed/gradle/TestDbDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package org.jetbrains.exposed.gradle

import com.avast.gradle.dockercompose.ComposeExtension
import org.gradle.api.Project
import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.AbstractTestTask
import org.gradle.api.tasks.testing.Test
import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import java.time.Duration

Expand All @@ -17,6 +19,7 @@ class TestDb(val name: String) {
var port: Int? = null
var container: String = name
var withContainer: Boolean = true
var colima: Boolean = false

internal val dependencies = mutableListOf<String>()

Expand Down Expand Up @@ -61,17 +64,26 @@ fun Project.testDb(name: String, block: TestDb.() -> Unit) {
}
}

val test by tasks
test.dependsOn(testTask)
tasks.named<Test>("test") {
delegatedTo(testTask)
}
}

private fun Project.configureCompose(db: TestDb) {
if (rootProject.tasks.findByPath("${db.container}ComposeUp") != null) return

rootProject.extensions.configure<ComposeExtension>("dockerCompose") {
nested(db.name).apply {
nested(db.container).apply {
environment.put("SERVICES_HOST", "127.0.0.1")
environment.put("COMPOSE_CONVERT_WINDOWS_PATHS", true)

val isArm = System.getProperty("os.arch") == "aarch64"
if (isArm && db.colima) {
val home = System.getProperty("user.home")
val dockerHost = "unix://$home/.colima/default/docker.sock"
environment.put("DOCKER_HOST", dockerHost)
}

useComposeFiles.set(listOf("buildScripts/docker/docker-compose-${db.container}.yml"))
removeVolumes.set(true)
stopContainers.set(false)
Expand All @@ -89,3 +101,26 @@ private fun Project.configureCompose(db: TestDb) {
startCompose.dependsOn(startDb)
stopCompose.dependsOn(stopDb)
}

/**
* Delegates the execution of tests to other tasks.
*
* @param tasks The tasks to delegate the test execution to.
* @return The modified Test object.
*/
fun Test.delegatedTo(vararg tasks: TaskProvider<out AbstractTestTask>): Test {
// don't run tests directly, delegate to other tasks
filter {
setExcludePatterns("*")
isFailOnNoMatchingTests = false
}
finalizedBy(tasks)
// Pass --tests CLI option value into delegates
doFirst {
val testsFilter = (filter as DefaultTestFilter).commandLineIncludePatterns.toList()
tasks.forEach {
it.configure { setTestNameIncludePatterns(testsFilter) }
}
}
return this
}
11 changes: 6 additions & 5 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ Independently of how you'd like to contribute, please make sure you read and com
### 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
brew install colima
```

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:
The test task can automatically use colima context when needed, and it's better to use default context for other tasks.
To switch the context to default, run:
```shell
docker context list
docker context use default
```

If not, set it as default:
Make sure that default is used as default docker context:
```shell
docker context use colima
docker context list
```

### Code
Expand Down
2 changes: 2 additions & 0 deletions exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,7 @@ public final class org/jetbrains/exposed/sql/SchemaUtils {
public final fun dropSequence ([Lorg/jetbrains/exposed/sql/Sequence;Z)V
public static synthetic fun dropSequence$default (Lorg/jetbrains/exposed/sql/SchemaUtils;[Lorg/jetbrains/exposed/sql/Sequence;ZILjava/lang/Object;)V
public final fun listDatabases ()Ljava/util/List;
public final fun listTables ()Ljava/util/List;
public final fun setSchema (Lorg/jetbrains/exposed/sql/Schema;Z)V
public static synthetic fun setSchema$default (Lorg/jetbrains/exposed/sql/SchemaUtils;Lorg/jetbrains/exposed/sql/Schema;ZILjava/lang/Object;)V
public final fun sortTablesByReferences (Ljava/lang/Iterable;)Ljava/util/List;
Expand Down Expand Up @@ -3606,6 +3607,7 @@ public class org/jetbrains/exposed/sql/vendors/SQLServerDialect : org/jetbrains/
public fun getSupportsOnlyIdentifiersInGeneratedKeys ()Z
public fun getSupportsSequenceAsGeneratedKeys ()Z
public fun isAllowedAsColumnDefault (Lorg/jetbrains/exposed/sql/Expression;)Z
public fun listDatabases ()Ljava/lang/String;
public fun modifyColumn (Lorg/jetbrains/exposed/sql/Column;Lorg/jetbrains/exposed/sql/ColumnDiff;)Ljava/util/List;
public fun setSchema (Lorg/jetbrains/exposed/sql/Schema;)Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class Database private constructor(
fun connect(
url: String,
driver: String = getDriver(url),
user: String = "root",
password: String = "Exposed_password_1!",
user: String = "",
password: String = "",
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object SchemaUtils {
return createStatement()
}

fun createIndex(index: Index) = index.createStatement()
fun createIndex(index: Index): List<String> = index.createStatement()

@Suppress("NestedBlockDepth", "ComplexMethod")
private fun DataTypeProvider.dbDefaultToString(column: Column<*>, exp: Expression<*>): String {
Expand Down Expand Up @@ -624,6 +624,13 @@ object SchemaUtils {
}
}

/**
* Retrieves a list of all table names in the current database.
*
* @return A list of table names as strings.
*/
fun listTables(): List<String> = currentDialect.allTablesNames()

fun drop(vararg tables: Table, inBatch: Boolean = false) {
if (tables.isEmpty()) return
with(TransactionManager.current()) {
Expand Down
Loading

0 comments on commit 7d4d4f5

Please sign in to comment.