如何重现 RSocket Kotlin 的错误
How to make a reproduction of a bug for RSocket Kotlin
如何使用 RSocket Kotlin 重现错误以提交错误或在 Whosebug 上提问。
在 Intellij 中制作一个 Kotlin 脚本,将其放在任何源文件夹之外,并确保它以 .main.kts
文件名结尾。
example.main.kts
#!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:Repository("https://jcenter.bintray.com/")
@file:DependsOn("io.rsocket.kotlin:rsocket-core:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-core-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client-jvm:0.12.0")
@file:DependsOn("io.ktor:ktor-client-okhttp:1.4.3")
@file:CompilerOptions("-jvm-target", "1.8", "-Xopt-in=kotlin.RequiresOptIn")
@file:OptIn(ExperimentalTime::class)
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.features.websocket.WebSockets
import io.rsocket.kotlin.RSocket
import io.rsocket.kotlin.core.RSocketConnector
import io.rsocket.kotlin.keepalive.KeepAlive
import io.rsocket.kotlin.payload.Payload
import io.rsocket.kotlin.payload.PayloadMimeType
import io.rsocket.kotlin.transport.ktor.client.RSocketSupport
import io.rsocket.kotlin.transport.ktor.client.rSocket
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
runBlocking {
val client = HttpClient(OkHttp) {
install(WebSockets)
install(RSocketSupport) {
connector = RSocketConnector {
connectionConfig {
// setupPayload(setupPayload)
keepAlive = KeepAlive(5.seconds)
payloadMimeType = PayloadMimeType("application/json", "application/json")
}
}
}
}
// connect to some url
val rSocket: RSocket = client.rSocket("wss://rsocket-demo.herokuapp.com/rsocket")
// request stream
val stream: Flow<Payload> = rSocket.requestStream(Payload.Empty)
// take 5 values and print response
stream.take(5).collect { payload: Payload ->
println(payload.data.readText())
}
}
#!行意味着它将 运行 像 shell 脚本一样
$ ./example.main.kts
0
1
2
3
4
Exception in thread "DefaultDispatcher-worker-3" java.lang.IllegalArgumentException: End gap 8 is too big: capacity is 7
at io.ktor.utils.io.core.BufferKt.endGapReservationFailedDueToCapacity(Buffer.kt:463)
at io.ktor.utils.io.core.Buffer.reserveEndGap(Buffer.kt:220)
at io.ktor.utils.io.core.AbstractOutput.appendNewChunk(AbstractOutput.kt:195)
at io.ktor.utils.io.core.AbstractOutput.prepareWriteHead(AbstractOutput.kt:497)
at io.ktor.utils.io.core.OutputPrimitivesKt.writeIntFallback(OutputPrimitives.kt:133)
at io.ktor.utils.io.core.OutputPrimitivesKt.writeInt(OutputPrimitives.kt:22)
...
运行 rsocket-cli 向 rsocket 服务器发送测试请求
$ brew install yschimke/tap/rsocket-cli
$ rsocket-cli wss://rsocket-demo-1.ew.r.appspot.com/rsocket --route timer --stream -i '{"a": "b"}' --requestn 5
0
1
2
如何使用 RSocket Kotlin 重现错误以提交错误或在 Whosebug 上提问。
在 Intellij 中制作一个 Kotlin 脚本,将其放在任何源文件夹之外,并确保它以 .main.kts
文件名结尾。
example.main.kts
#!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:Repository("https://jcenter.bintray.com/")
@file:DependsOn("io.rsocket.kotlin:rsocket-core:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-core-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-jvm:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client:0.12.0")
@file:DependsOn("io.rsocket.kotlin:rsocket-transport-ktor-client-jvm:0.12.0")
@file:DependsOn("io.ktor:ktor-client-okhttp:1.4.3")
@file:CompilerOptions("-jvm-target", "1.8", "-Xopt-in=kotlin.RequiresOptIn")
@file:OptIn(ExperimentalTime::class)
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.features.websocket.WebSockets
import io.rsocket.kotlin.RSocket
import io.rsocket.kotlin.core.RSocketConnector
import io.rsocket.kotlin.keepalive.KeepAlive
import io.rsocket.kotlin.payload.Payload
import io.rsocket.kotlin.payload.PayloadMimeType
import io.rsocket.kotlin.transport.ktor.client.RSocketSupport
import io.rsocket.kotlin.transport.ktor.client.rSocket
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
runBlocking {
val client = HttpClient(OkHttp) {
install(WebSockets)
install(RSocketSupport) {
connector = RSocketConnector {
connectionConfig {
// setupPayload(setupPayload)
keepAlive = KeepAlive(5.seconds)
payloadMimeType = PayloadMimeType("application/json", "application/json")
}
}
}
}
// connect to some url
val rSocket: RSocket = client.rSocket("wss://rsocket-demo.herokuapp.com/rsocket")
// request stream
val stream: Flow<Payload> = rSocket.requestStream(Payload.Empty)
// take 5 values and print response
stream.take(5).collect { payload: Payload ->
println(payload.data.readText())
}
}
#!行意味着它将 运行 像 shell 脚本一样
$ ./example.main.kts
0
1
2
3
4
Exception in thread "DefaultDispatcher-worker-3" java.lang.IllegalArgumentException: End gap 8 is too big: capacity is 7
at io.ktor.utils.io.core.BufferKt.endGapReservationFailedDueToCapacity(Buffer.kt:463)
at io.ktor.utils.io.core.Buffer.reserveEndGap(Buffer.kt:220)
at io.ktor.utils.io.core.AbstractOutput.appendNewChunk(AbstractOutput.kt:195)
at io.ktor.utils.io.core.AbstractOutput.prepareWriteHead(AbstractOutput.kt:497)
at io.ktor.utils.io.core.OutputPrimitivesKt.writeIntFallback(OutputPrimitives.kt:133)
at io.ktor.utils.io.core.OutputPrimitivesKt.writeInt(OutputPrimitives.kt:22)
...
运行 rsocket-cli 向 rsocket 服务器发送测试请求
$ brew install yschimke/tap/rsocket-cli
$ rsocket-cli wss://rsocket-demo-1.ew.r.appspot.com/rsocket --route timer --stream -i '{"a": "b"}' --requestn 5
0
1
2