Skip to content

Migrate to ktor 2.0.0 eap and new native memory model #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Feb 26, 2022
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
13 changes: 0 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,4 @@ subprojects {
if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") }
if (name.startsWith("link", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipLink") }
}

//workaround for https://youtrack.jetbrains.com/issue/KT-44884
configurations.matching { !it.name.startsWith("kotlinCompilerPluginClasspath") }.all {
resolutionStrategy.eachDependency {
val version = requested.version
if (requested.group == "org.jetbrains.kotlinx" &&
requested.name.startsWith("kotlinx-coroutines") &&
version != null && !version.contains("native-mt")
) {
useVersion("$version-native-mt")
}
}
}
}
2 changes: 2 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
}

versionCatalogs {
Expand Down
3 changes: 0 additions & 3 deletions buildSrc/src/main/kotlin/TestOptIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ fun LanguageSettingsBuilder.optInForTest() {
optIn("kotlinx.coroutines.FlowPreview")
optIn("kotlinx.coroutines.DelicateCoroutinesApi")

optIn("io.ktor.util.InternalAPI")
optIn("io.ktor.utils.io.core.internal.DangerousInternalIoApi")

optIn("io.rsocket.kotlin.TransportApi")
optIn("io.rsocket.kotlin.ExperimentalMetadataApi")
optIn("io.rsocket.kotlin.ExperimentalStreamsApi")
Expand Down
5 changes: 0 additions & 5 deletions buildSrc/src/main/kotlin/rsocket.multiplatform.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ kotlin {

optIn("kotlin.RequiresOptIn")

//TODO: kludge, this is needed now,
// as ktor isn't fully supports kotlin 1.5.3x opt-in changes
// will be not needed after ktor 2.0.0
optIn("io.ktor.utils.io.core.ExperimentalIoApi")

if (name.contains("test", ignoreCase = true)) optInForTest()
}
}
Expand Down
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ version=0.15.0-SNAPSHOT
#Kotlin
kotlin.js.compiler=both
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.native.ignoreIncorrectDependencies=true
#TODO native debug tests fail for ktor
kotlin.native.cacheKind.linuxX64=none
kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled
#Gradle
org.gradle.parallel=true
org.gradle.caching=true
Expand Down
47 changes: 47 additions & 0 deletions gradle/js/yarn/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ abab@^2.0.5:
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a"
integrity sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q==

abort-controller@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
dependencies:
event-target-shim "^5.0.0"

accepts@~1.3.4:
version "1.3.7"
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
Expand Down Expand Up @@ -274,6 +281,11 @@ argparse@^2.0.1:
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

async-limiter@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -552,6 +564,14 @@ dom-serialize@^2.2.1:
extend "^3.0.0"
void-elements "^2.0.0"

dukat@0.5.8-rc.4:
version "0.5.8-rc.4"
resolved "https://registry.yarnpkg.com/dukat/-/dukat-0.5.8-rc.4.tgz#90384dcb50b14c26f0e99dae92b2dea44f5fce21"
integrity sha512-ZnMt6DGBjlVgK2uQamXfd7uP/AxH7RqI0BL9GLrrJb2gKdDxvJChWy+M9AQEaL+7/6TmxzJxFOsRiInY9oGWTA==
dependencies:
google-protobuf "3.12.2"
typescript "3.9.5"

ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
Expand Down Expand Up @@ -655,6 +675,11 @@ estraverse@^5.2.0:
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==

event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==

eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
Expand Down Expand Up @@ -826,6 +851,11 @@ glob@^7.1.3, glob@^7.1.7:
once "^1.3.0"
path-is-absolute "^1.0.0"

google-protobuf@3.12.2:
version "3.12.2"
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.12.2.tgz#50ce9f9b6281235724eb243d6a83e969a2176e53"
integrity sha512-4CZhpuRr1d6HjlyrxoXoocoGFnRYgKULgMtikMddA9ztRyYR59Aondv2FioyxWVamRo0rF2XpYawkTCBEQOSkA==

graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, graceful-fs@^4.2.6:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
Expand Down Expand Up @@ -1235,6 +1265,11 @@ neo-async@^2.6.2:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

node-fetch@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

node-releases@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.1.tgz#3d1d395f204f1f2f29a54358b9fb678765ad2fc5"
Expand Down Expand Up @@ -1676,6 +1711,11 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"

typescript@3.9.5:
version "3.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.5.tgz#586f0dba300cde8be52dd1ac4f7e1009c1b13f36"
integrity sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==

ua-parser-js@^0.7.28:
version "0.7.31"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.31.tgz#649a656b191dffab4f21d5e053e27ca17cbff5c6"
Expand Down Expand Up @@ -1833,6 +1873,13 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

ws@6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==
dependencies:
async-limiter "~1.0.0"

ws@~7.4.2:
version "7.4.6"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"
Expand Down
17 changes: 9 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[versions]
kotlin = "1.6.10"
kotlin = "1.6.20-M1-106"

kotlinx-atomicfu = "0.17.0"
kotlinx-coroutines = "1.5.2-native-mt"
kotlinx-benchmark = "0.4.0"
kotlinx-coroutines = "1.6.0"
kotlinx-benchmark = "0.4.2"

ktor = "1.6.7"
ktor = "2.0.0-eap-317"

turbine = "0.7.0"

versionUpdates = "0.39.0"
versionUpdates = "0.41.0"

rsocket-java = "1.1.1"

jmh = "1.33"
jmh = "1.34"

[libraries]
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
Expand All @@ -25,12 +25,13 @@ kotlinx-benchmark = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime"
ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" }
ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor" }
ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" }
ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor" }
ktor-websockets = { module = "io.ktor:ktor-websockets", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-server-core = { module = "io.ktor:ktor-server", version.ref = "ktor" }
ktor-server-websockets = { module = "io.ktor:ktor-websockets", version.ref = "ktor" }
ktor-server-websockets = { module = "io.ktor:ktor-server-websockets", version.ref = "ktor" }
ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" }
ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import io.ktor.utils.io.core.internal.*
import io.ktor.utils.io.pool.*

internal inline fun buildPacket(pool: ObjectPool<ChunkBuffer>, block: BytePacketBuilder.() -> Unit): ByteReadPacket {
val builder = BytePacketBuilder(0, pool)
val builder = BytePacketBuilder(pool)
try {
block(builder)
return builder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ internal suspend inline fun FlowCollector<Payload>.emitAllWithRequestN(
internal abstract class RequestFlow : Flow<Payload> {
private val consumed = atomic(false)

@InternalCoroutinesApi
override suspend fun collect(collector: FlowCollector<Payload>) {
check(!consumed.getAndSet(true)) { "RequestFlow can be collected just once" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import io.rsocket.kotlin.payload.*
import kotlinx.coroutines.*

internal abstract class FrameHandler(pool: ObjectPool<ChunkBuffer>) : Closeable {
private val data = BytePacketBuilder(0, pool)
private val metadata = BytePacketBuilder(0, pool)
private val data = BytePacketBuilder(pool)
private val metadata = BytePacketBuilder(pool)
protected abstract var hasMetadata: Boolean

fun handleRequest(frame: RequestFrame) {
Expand Down
5 changes: 3 additions & 2 deletions rsocket-test/rsocket-test-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ kotlin {
main {
dependencies {
implementation(projects.rsocketTest)
implementation(projects.rsocketTransportKtorServer)
implementation(projects.rsocketTransportKtor.rsocketTransportKtorTcp)
implementation(projects.rsocketTransportKtor.rsocketTransportKtorWebsocketServer)

implementation(libs.ktor.server.cio)
}
Expand Down Expand Up @@ -73,7 +74,7 @@ val testTasks = setOf(
)

rootProject.allprojects {
if (name == "rsocket-transport-ktor") {
if (name == "rsocket-transport-ktor-websocket") {
tasks.matching { it.name in testTasks }.all {
dependsOn(startTestServer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package io.rsocket.kotlin.test.server

import io.ktor.application.*
import io.ktor.routing.*
import io.ktor.server.application.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.websocket.*
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import io.rsocket.kotlin.core.*
import io.rsocket.kotlin.test.*
import io.rsocket.kotlin.transport.ktor.*
import io.rsocket.kotlin.transport.ktor.server.*
import io.rsocket.kotlin.transport.ktor.tcp.*
import io.rsocket.kotlin.transport.ktor.websocket.server.*
import kotlinx.coroutines.*
import java.io.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.ktor.utils.io.core.internal.*
import io.ktor.utils.io.pool.*
import kotlin.test.*

@Suppress("DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNCHECKED_CAST")
object InUseTrackingPool : ObjectPool<ChunkBuffer> {
override val capacity: Int get() = BufferPool.capacity
private val inUse = TrackingSet()
Expand All @@ -35,7 +34,7 @@ object InUseTrackingPool : ObjectPool<ChunkBuffer> {

override fun recycle(instance: ChunkBuffer) {
inUse.remove(instance)
BufferPool.recycle(instance as IoBuffer)
BufferPool.recycle(instance)
}

override fun dispose() {
Expand Down Expand Up @@ -80,21 +79,21 @@ object InUseTrackingPool : ObjectPool<ChunkBuffer> {
// that there are no leaked buffers
// used only on tests, so it's more or less safe
// copy of io.ktor.utils.io.core.DefaultBufferPool with changed parent pool!!!
private object BufferPool : DefaultPool<IoBuffer>(1000) {
override fun produceInstance(): IoBuffer {
return IoBuffer(DefaultAllocator.alloc(DEFAULT_BUFFER_SIZE), null, InUseTrackingPool as ObjectPool<IoBuffer>)
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
private object BufferPool : DefaultPool<ChunkBuffer>(1000) {
override fun produceInstance(): ChunkBuffer {
return ChunkBuffer(DefaultAllocator.alloc(DEFAULT_BUFFER_SIZE), null, InUseTrackingPool)
}

override fun disposeInstance(instance: IoBuffer) {
override fun disposeInstance(instance: ChunkBuffer) {
DefaultAllocator.free(instance.memory)
super.disposeInstance(instance)
instance.unlink()
}

override fun validateInstance(instance: IoBuffer) {
override fun validateInstance(instance: ChunkBuffer) {
super.validateInstance(instance)

check(instance !== IoBuffer.Empty) { "Empty instance couldn't be recycled" }
check(instance !== Buffer.Empty) { "Empty instance couldn't be recycled" }
check(instance !== ChunkBuffer.Empty) { "Empty instance couldn't be recycled" }

Expand All @@ -103,7 +102,7 @@ object InUseTrackingPool : ObjectPool<ChunkBuffer> {
check(instance.origin == null) { "Recycled instance shouldn't be a view or another buffer." }
}

override fun clearInstance(instance: IoBuffer): IoBuffer {
override fun clearInstance(instance: ChunkBuffer): ChunkBuffer {
return super.clearInstance(instance).apply {
unpark()
reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun assertBytesEquals(expected: ByteArray?, actual: ByteArray?) {
}

private inline fun buildPacket(pool: ObjectPool<ChunkBuffer>, block: BytePacketBuilder.() -> Unit): ByteReadPacket {
val builder = BytePacketBuilder(0, pool)
val builder = BytePacketBuilder(pool)
try {
block(builder)
return builder.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.rsocket.kotlin.transport.ktor
package io.rsocket.kotlin.test

import kotlinx.atomicfu.*
import kotlin.random.*
Expand Down
27 changes: 2 additions & 25 deletions rsocket-transport-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,12 @@ kotlin {
main {
dependencies {
api(projects.rsocketCore)

api(libs.ktor.network)
api(libs.ktor.http.cio)
}
}
test {
dependencies {
implementation(projects.rsocketTransportKtorClient)
}
}
}
configureJvm {
test {
dependencies {
implementation(projects.rsocketTransportKtorServer)

implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.okhttp)

implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.jetty)
}
}
}
configureJvm()
configureJs()
configureNative(NativeTargets.Nix)
configureNative()
}

description = "Ktor RSocket transport implementations (TCP, Websocket)"

evaluationDependsOn(":rsocket-test-server")
Loading