Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public class RpcParameter(public val name: String, public val type: RpcType)
@ExperimentalRpcApi
public class RpcType(public val kType: KType) {
override fun toString(): String {
return return kType.toString()
return kType.toString()
}
}
4 changes: 2 additions & 2 deletions gradle-conventions/common/src/main/kotlin/util/JsTarget.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util
Expand Down Expand Up @@ -40,7 +40,7 @@ fun KotlinJsTargetDsl.configureJsAndWasmJsTasks() {
nodejs {
testTask {
useMocha {
timeout = "10000"
timeout = "100s"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util
Expand Down Expand Up @@ -38,6 +38,7 @@ class ProjectKotlinConfig(
jvm: Boolean = true,
js: Boolean = true,
wasmJs: Boolean = true,
wasmJsD8: Boolean = true,
wasmWasi: Boolean = true,
val native: Boolean = true,
) : Project by project {
Expand All @@ -48,18 +49,18 @@ class ProjectKotlinConfig(

private fun isIncluded(
targetName: String,
kotlinVersion: KotlinVersion,
lookupTable: Map<String, String>,
lookupTable: Map<String, String> = targetsLookup,
): Boolean {
return lookupTable[targetName]?.let { sinceKotlin ->
sinceKotlin == FULLY_SUPPORTED_TARGET || sinceKotlin.kotlinVersionParsed() <= kotlinVersion
} ?: false
}

val jvm: Boolean by lazy { jvm && isIncluded("jvm", kotlinVersion, targetsLookup) }
val js: Boolean by lazy { js && isIncluded("js", kotlinVersion, targetsLookup) }
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs", kotlinVersion, targetsLookup) }
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi", kotlinVersion, targetsLookup) }
val jvm: Boolean by lazy { jvm && isIncluded("jvm") }
val js: Boolean by lazy { js && isIncluded("js") }
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs") }
val wasmJsD8: Boolean by lazy { wasmJsD8 && wasmJs }
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi") }

private val nativeLookup by lazy {
targetsLookup.filterKeys { key ->
Expand All @@ -71,7 +72,6 @@ class ProjectKotlinConfig(
.filter { targetFunction ->
targetFunction.parameters.size == 1 && isIncluded(
targetName = targetFunction.name,
kotlinVersion = kotlinVersion,
lookupTable = nativeLookup,
)
}.map { function ->
Expand All @@ -84,6 +84,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
val excludeJvm: Boolean by optionalProperty()
val excludeJs: Boolean by optionalProperty()
val excludeWasmJs: Boolean by optionalProperty()
val excludeWasmJsD8: Boolean by optionalProperty()
val excludeWasmWasi: Boolean by optionalProperty()
val excludeNative: Boolean by optionalProperty()

Expand All @@ -93,6 +94,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
jvm = !excludeJvm,
js = !excludeJs,
wasmJs = !excludeWasmJs,
wasmJsD8 = !excludeWasmJsD8,
wasmWasi = !excludeWasmWasi,
native = !excludeNative,
).configure()
Expand Down
6 changes: 4 additions & 2 deletions gradle-conventions/src/main/kotlin/util/wasm.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util
Expand All @@ -23,7 +23,9 @@ fun ProjectKotlinConfig.configureWasm() {

browser()
nodejs()
d8()
if (wasmJsD8) {
d8()
}

binaries.library()
}.configurePublication()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kotlinx.rpc.krpc.client
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.rpc.RpcCall
Expand Down Expand Up @@ -258,9 +257,7 @@ public abstract class KrpcClient(

val id = callCounter.incrementAndGet()

val dataTypeString = callable.dataType.toString()

val callId = "$connectionId:$dataTypeString:$id"
val callId = "$connectionId:${callable.name}:$id"

logger.trace { "start a call[$callId] ${callable.name}" }

Expand Down Expand Up @@ -325,9 +322,7 @@ public abstract class KrpcClient(
val callable = call.descriptor.getCallable(call.callableName)
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")

val dataTypeString = callable.dataType.toString()

val callId = "$connectionId:$dataTypeString:$id"
val callId = "$connectionId:${callable.name}:$id"

val channel = Channel<T>()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.internal
Expand Down Expand Up @@ -154,9 +154,25 @@ public class KrpcConnector<SubscriptionKey>(
if (waitForSubscribers) {
waiting.getOrPut(message.getKey()) { mutableListOf() }.add(message)

logger.warn {
val reason = when (result) {
is HandlerResult.Failure -> {
"Unhandled exception while processing ${result.cause?.message}"
}

is HandlerResult.NoSubscription -> {
"No service with key '${message.getKey()}' and '${message.serviceType}' type was registered." +
"Available: keys: [${subscriptions.keys.joinToString()}]"
}

else -> {
"Unknown"
}
}

logger.warn((result as? HandlerResult.Failure)?.cause) {
"No registered service of ${message.serviceType} service type " +
"was able to process message at the moment. Waiting for new services."
"was able to process message at the moment. Waiting for new services." +
"Reason: $reason"
}

return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("ExtractKtorModule")
Expand Down Expand Up @@ -31,6 +31,7 @@ class NewServiceImpl(
override val coroutineContext: CoroutineContext,
private val call: ApplicationCall,
) : NewService {
@Suppress("UastIncorrectHttpHeaderInspection")
override suspend fun echo(value: String): String {
assertEquals("test-header", call.request.headers["TestHeader"])
return value
Expand Down
4 changes: 2 additions & 2 deletions krpc/krpc-ktor/krpc-ktor-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
Expand All @@ -9,7 +9,7 @@ plugins {

kotlin {
sourceSets {
jvmMain {
commonMain {
dependencies {
api(projects.krpc.krpcServer)
api(projects.krpc.krpcKtor.krpcKtorCore)
Expand Down
6 changes: 0 additions & 6 deletions krpc/krpc-ktor/krpc-ktor-server/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.ktor.server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.ktor.server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.ktor.server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.ktor.server
Expand Down
36 changes: 26 additions & 10 deletions krpc/krpc-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import com.osacky.doctor.internal.sysProperty
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
import util.applyAtomicfuPlugin
import java.nio.file.Files
Expand All @@ -22,11 +24,7 @@ kotlin {
// Workaround for
// KLIB resolver: Could not find "org.jetbrains.kotlinx:atomicfu"
api(libs.atomicfu)
}
}

jvmMain {
dependencies {
api(projects.krpc.krpcCore)
api(projects.krpc.krpcServer)
api(projects.krpc.krpcClient)
Expand All @@ -35,24 +33,34 @@ kotlin {

implementation(libs.serialization.core)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
}
}

jvmMain {
dependencies {
implementation(libs.kotlin.test.junit)
}
}

jvmTest {
commonTest {
dependencies {
implementation(projects.krpc.krpcTest)
implementation(projects.krpc.krpcSerialization.krpcSerializationJson)
implementation(projects.krpc.krpcSerialization.krpcSerializationCbor)
implementation(projects.krpc.krpcSerialization.krpcSerializationProtobuf)
implementation(projects.krpc.krpcLogging)

implementation(libs.coroutines.test)
implementation(libs.kotlin.reflect)
}
}

jvmTest {
dependencies {
implementation(libs.slf4j.api)
implementation(libs.logback.classic)

implementation(libs.coroutines.test)
implementation(libs.coroutines.debug)
implementation(libs.kotlin.reflect)
}
}
}
Expand All @@ -72,7 +80,15 @@ tasks.named<Delete>("clean") {
delete(resourcesPath.walk().filter { it.isFile && it.extension == tmpExt }.toList())
}

tasks.create("moveToGold") {
tasks.withType<KotlinJsTest> {
onlyIf {
// for some reason browser tests don't wait for the test to complete and end immediately
// KRPC-166
!targetName.orEmpty().endsWith("browser")
}
}

tasks.register("moveToGold") {
doLast {
resourcesPath.walk().forEach {
if (it.isFile && it.extension == tmpExt) {
Expand Down
6 changes: 6 additions & 0 deletions krpc/krpc-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
#

# tests fail with some obscure reason
kotlinx.rpc.excludeWasmJsD8=true
8 changes: 0 additions & 8 deletions krpc/krpc-test/src/commonMain/kotlin/Stub.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,37 @@ import kotlinx.rpc.RemoteService
import kotlinx.rpc.annotations.Rpc
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import java.time.LocalDate
import java.time.LocalDateTime

data class LocalDate(
val year: Int,
val month: Int,
val day: Int,
) {
override fun toString(): String {
return "$year-$month-$day"
}

companion object {
fun parse(str: String): LocalDate = str.split('-').let {
LocalDate(it[0].toInt(), it[1].toInt(), it[2].toInt())
}
}
}

data class LocalDateTime(
val date: LocalDate,
val time: String,
) {
override fun toString(): String {
return "$date $time"
}

companion object {
fun parse(str: String): LocalDateTime = str.split(' ').let {
LocalDateTime(LocalDate.parse(it[0]), it[1])
}
}
}

@Suppress("detekt.TooManyFunctions")
@Rpc
Expand Down
Loading