Skip to content

Commit 718a8bc

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #950 from modelix/chore/remove-implemenation-of-LightModelServer-from-model-server-code
chore(model-server): remove implementation of `LightModelServer` from model-server code
2 parents abf5b4e + 8da0c1f commit 718a8bc

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

light-model-client/build.gradle.kts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ kotlin {
4040
implementation(libs.kotlin.logging)
4141
implementation(libs.kotlin.coroutines.core)
4242
implementation(libs.kotlin.serialization.json)
43-
44-
// implementation("io.ktor:ktor-client-core:$ktorVersion")
45-
// implementation("io.ktor:ktor-client-cio:$ktorVersion")
46-
// implementation("io.ktor:ktor-client-auth:$ktorVersion")
47-
// implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
48-
// implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
4943
}
5044
}
5145
val commonTest by getting {
@@ -63,7 +57,7 @@ kotlin {
6357
dependencies {
6458

6559
implementation(project(":authorization"))
66-
// implementation(project(":model-client"))
60+
implementation(project(":model-client", configuration = "jvmRuntimeElements"))
6761
implementation(project(":model-server"))
6862
implementation(project(":model-server-lib"))
6963
implementation(libs.modelix.incremental)

model-server/src/main/kotlin/org/modelix/model/server/handlers/LightModelServer.kt renamed to light-model-client/src/jvmTest/kotlin/org/modelix/client/light/FakeLightModelServer.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
* Copyright (c) 2024.
3+
*
24
* Licensed under the Apache License, Version 2.0 (the "License");
35
* you may not use this file except in compliance with the License.
46
* You may obtain a copy of the License at
@@ -11,7 +13,8 @@
1113
* See the License for the specific language governing permissions and
1214
* limitations under the License.
1315
*/
14-
package org.modelix.model.server.handlers
16+
17+
package org.modelix.client.light
1518

1619
import io.ktor.server.application.Application
1720
import io.ktor.server.request.host
@@ -22,8 +25,6 @@ import io.ktor.server.websocket.webSocket
2225
import io.ktor.websocket.Frame
2326
import io.ktor.websocket.readText
2427
import io.ktor.websocket.send
25-
import kotlinx.coroutines.ExperimentalCoroutinesApi
26-
import kotlinx.coroutines.channels.Channel
2728
import kotlinx.coroutines.launch
2829
import kotlinx.coroutines.sync.Mutex
2930
import kotlinx.coroutines.sync.withLock
@@ -55,14 +56,17 @@ import org.modelix.model.server.api.OperationData
5556
import org.modelix.model.server.api.SetPropertyOpData
5657
import org.modelix.model.server.api.SetReferenceOpData
5758
import org.modelix.model.server.api.VersionData
59+
import org.modelix.model.server.handlers.RepositoriesManager
5860
import org.modelix.model.server.store.ContextScopedStoreClient
5961
import org.modelix.model.server.store.LocalModelClient
6062
import java.util.Date
61-
import kotlin.collections.set
6263

6364
private val LOG = KotlinLogging.logger {}
6465

65-
class LightModelServer(val client: LocalModelClient, val repositoriesManager: RepositoriesManager) {
66+
/**
67+
* Simplified fake implementation of [org.modelix.model.server.light.LightModelServer].
68+
*/
69+
class FakeLightModelServer(val client: LocalModelClient, val repositoriesManager: RepositoriesManager) {
6670

6771
fun init(application: Application) {
6872
application.routing {
@@ -193,7 +197,16 @@ class LightModelServer(val client: LocalModelClient, val repositoriesManager: Re
193197
}
194198
}
195199
} catch (ex: Exception) {
196-
send(MessageFromServer(exception = ExceptionData(RuntimeException("Failed to process message: $text", ex))).toJson())
200+
send(
201+
MessageFromServer(
202+
exception = ExceptionData(
203+
RuntimeException(
204+
"Failed to process message: $text",
205+
ex,
206+
),
207+
),
208+
).toJson(),
209+
)
197210
}
198211
}
199212
else -> {}
@@ -365,10 +378,3 @@ class LightModelServer(val client: LocalModelClient, val repositoriesManager: Re
365378
}
366379
}
367380
}
368-
369-
@OptIn(ExperimentalCoroutinesApi::class)
370-
private suspend fun <T> Channel<T>.receiveLast(): T {
371-
var latest = receive()
372-
while (!isEmpty) latest = receive()
373-
return latest
374-
}

light-model-client/src/jvmTest/kotlin/org/modelix/client/light/LightModelClientTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.modelix.incremental.incrementalFunction
2727
import org.modelix.model.api.IProperty
2828
import org.modelix.model.api.addNewChild
2929
import org.modelix.model.api.getDescendants
30-
import org.modelix.model.server.handlers.LightModelServer
3130
import org.modelix.model.server.handlers.RepositoriesManager
3231
import org.modelix.model.server.store.InMemoryStoreClient
3332
import org.modelix.model.server.store.LocalModelClient
@@ -41,8 +40,6 @@ import kotlin.time.Duration.Companion.minutes
4140
import kotlin.time.Duration.Companion.seconds
4241

4342
class LightModelClientTest {
44-
var localModelClient: LocalModelClient? = null
45-
4643
private fun runTest(block: suspend (HttpClient) -> Unit) = testApplication {
4744
val modelClient = LocalModelClient(InMemoryStoreClient())
4845
val repositoryManager = RepositoriesManager(modelClient)
@@ -52,8 +49,11 @@ class LightModelClientTest {
5249
installAuthentication(unitTestMode = true)
5350
install(io.ktor.server.websocket.WebSockets)
5451
install(io.ktor.server.resources.Resources)
55-
localModelClient = modelClient
56-
LightModelServer(modelClient, repositoryManager).init(this)
52+
// TODO MODELIX-994 Should use `org.modelix.model.server.light.LightModelServer`
53+
// to test against the actual implementation.
54+
// But just using it does not work.
55+
// Might be caused by the setup here or actual bugs in the server or client.
56+
FakeLightModelServer(modelClient, repositoryManager).init(this)
5757
}
5858
val client = createClient {
5959
install(WebSockets)

0 commit comments

Comments
 (0)