Skip to content

Commit

Permalink
fix(rest-api-model-server): fix Ktor compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
odzhychko committed Nov 9, 2023
1 parent 613e082 commit c822139
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ modelixCore = "3.11.0"
mpsModelServerSyncPlugin = "2021.2.157"

# backend 1 / SPA
ktor = "2.3.5"
ktor = "2.3.6"

# backend 2
# When increasing the version of quarkus,
Expand Down Expand Up @@ -67,6 +67,9 @@ ktor-server-cors = { group = "io.ktor", name = "ktor-server-cors", version.ref =
ktor-server-websockets = { group = "io.ktor", name = "ktor-server-websockets", version.ref = "ktor" }
ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" }
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-auth = { group = "io.ktor", name = "ktor-client-auth", version.ref = "ktor" }
ktor-serialization-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }

# other
ant-junit = { group = "org.apache.ant", name = "ant-junit", version.ref = "antJunit" }
Expand Down
20 changes: 19 additions & 1 deletion rest-api-model-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,26 @@ dependencies {
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")

implementation(libs.ktor.client.core)
implementation(libs.modelix.model.client)
implementation(libs.ktor.client.core)
constraints {
// The Ktor version 2.3.5 from the modelix release 23.2,
// has a bug that makes it break for Quarkus.
//
// The bug stems from an upgraded Kotlin version,
// which broke backward compatibility.
// See https://youtrack.jetbrains.com/issue/KTOR-6354
//
// The Ktor version 2.3.6 provides a fix,
// but that Ktor version is not used in modelix release 23.2.
//
// Because of that, we are explicitly constraining the Ktor version
// of Ktor libraries to 2.3.6 or later (specified in libs.version.toml)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.auth)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.json)
}

implementation(project(":mps:metamodel-api-kts"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.acme.getting.started.testing

import io.quarkus.test.junit.QuarkusTest
import io.quarkus.test.junit.QuarkusTestProfile
import io.quarkus.test.junit.TestProfile
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test
import org.modelix.model.client.ReplicatedRepository
import javax.inject.Inject

class UnreachableUrlProfile : QuarkusTestProfile {
override fun getConfigOverrides(): Map<String, String> {
// Override the server uri to be an unreachable URL.
return mapOf("modelix.client.server-uri" to "http://non_existing_host:93939")
}
}

@QuarkusTest
@TestProfile(value = UnreachableUrlProfile::class)
class ReplicatedRepositoryInstantiationTest {
@Inject
lateinit var replicatedRepository: ReplicatedRepository

@Test
fun testInjection() {
// This tests, whether `replicatedRepository` can be correctly injected and instantiated by Quarkus.
// The actual instantiation is happening when we call something on `replicatedRepository`.
// Therefore, we call `.branch`.
// The asserted exception message indicates that the `replicatedRepository` was injected correctly.
// The exception message "java.lang.NoClassDefFoundError: kotlin/enums/EnumEntriesKt", for example,
// would indicate that something is set up wrong and the instantiation is failing.
// In the past, we had such issues with the wrong version of Kotlin and Ktor.
val exception = assertThrows(RuntimeException::class.java) { replicatedRepository.branch }
assertEquals(
"Unable to connect to 'http://non_existing_host:93939/get/branch_courses_master' to get key branch_courses_master",
exception.message
)
}
}

0 comments on commit c822139

Please sign in to comment.