Skip to content

Commit ad18e2f

Browse files
authored
chore: upgrade Ktor to 3.0.0 (#1167)
1 parent b5f5e91 commit ad18e2f

File tree

8 files changed

+22
-27
lines changed

8 files changed

+22
-27
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ kotlin-compile-testing-version = "1.6.0"
2727
kotlinx-benchmark-version = "0.4.12"
2828
kotlinx-serialization-version = "1.7.3"
2929
docker-java-version = "3.4.0"
30-
ktor-version = "2.3.12"
30+
ktor-version = "3.0.0"
3131
kaml-version = "0.55.0"
3232
jsoup-version = "1.18.1"
3333

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import aws.smithy.kotlin.runtime.httptest.TestWithLocalServer
1414
import aws.smithy.kotlin.runtime.net.Host
1515
import aws.smithy.kotlin.runtime.net.Scheme
1616
import aws.smithy.kotlin.runtime.testing.IgnoreWindows
17-
import io.ktor.server.application.*
1817
import io.ktor.server.cio.*
1918
import io.ktor.server.engine.*
2019
import io.ktor.server.response.*

runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,43 @@ package aws.smithy.kotlin.runtime.http.test.suite
88
import aws.smithy.kotlin.runtime.hashing.sha256
99
import aws.smithy.kotlin.runtime.text.encoding.encodeToHex
1010
import io.ktor.http.*
11-
import io.ktor.http.content.*
1211
import io.ktor.server.application.*
1312
import io.ktor.server.response.*
1413
import io.ktor.server.routing.*
1514
import io.ktor.utils.io.*
1615
import kotlinx.coroutines.delay
17-
import kotlinx.coroutines.launch
1816
import java.io.ByteArrayOutputStream
1917
import java.util.zip.GZIPOutputStream
2018
import kotlin.random.Random
2119

20+
internal const val DOWNLOAD_SIZE = 16L * 1024 * 1024 // 16MB
21+
2222
internal fun Application.downloadTests() {
2323
routing {
2424
route("/download") {
2525
get("/integrity") {
2626
// writer is setup to write random lengths and delay to cause the reader to enter a suspend loop
27-
val data = ByteArray(16 * 1024 * 1024) { it.toByte() }
27+
val data = ByteArray(DOWNLOAD_SIZE.toInt()) { it.toByte() }
2828
val writeSha = data.sha256().encodeToHex()
2929
call.response.header("expected-sha256", writeSha)
3030
val chunked = call.request.queryParameters["chunked-response"]?.toBoolean() ?: false
3131

32-
val ch = ByteChannel(autoFlush = true)
33-
val content = object : OutgoingContent.ReadChannelContent() {
34-
override val contentLength: Long? = if (chunked) null else data.size.toLong()
35-
override fun readFrom(): ByteReadChannel = ch
36-
override val contentType: ContentType = ContentType.Application.OctetStream
37-
}
38-
39-
launch {
32+
call.respondBytesWriter(contentLength = DOWNLOAD_SIZE.takeUnless { chunked }) {
4033
var wcRemaining = data.size
4134
var offset = 0
4235
while (wcRemaining > 0) {
4336
// random write sizes
4437
val wc = minOf(wcRemaining, Random.nextInt(256, 8 * 1024))
4538
val slice = data.sliceArray(offset until offset + wc)
46-
ch.writeFully(slice)
39+
writeFully(slice)
4740
offset += wc
4841
wcRemaining -= wc
4942

5043
if (wcRemaining % 256 == 0) {
5144
delay(Random.nextLong(0, 10))
5245
}
5346
}
54-
}.invokeOnCompletion { cause ->
55-
ch.close(cause)
5647
}
57-
58-
call.respond(content)
5948
}
6049

6150
get("/empty") {

runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Uploads.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import io.ktor.http.*
1111
import io.ktor.server.application.*
1212
import io.ktor.server.response.*
1313
import io.ktor.server.routing.*
14+
import io.ktor.utils.io.availableForRead
15+
import io.ktor.utils.io.readAvailable
1416

1517
private const val CHUNK_SIZE = 1024 * 8
1618

runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/TestServers.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@ internal fun startServers(sslConfigPath: String): Closeable {
8888
return servers
8989
}
9090

91-
private fun tlsServer(instance: TestServer, sslConfig: SslConfig): ApplicationEngine {
91+
private fun tlsServer(instance: TestServer, sslConfig: SslConfig): EmbeddedServer<*, *> {
9292
val description = "${instance.type.name} server on port ${instance.port}"
9393
println("Starting $description...")
94-
val environment = applicationEngineEnvironment {
94+
val rootConfig = serverConfig {
95+
module(instance.initializer)
96+
}
97+
val engineConfig: ApplicationEngine.Configuration.() -> Unit = {
9598
when (instance.type) {
9699
ConnectorType.HTTP -> connector { port = instance.port }
97100

@@ -106,11 +109,10 @@ private fun tlsServer(instance: TestServer, sslConfig: SslConfig): ApplicationEn
106109
enabledProtocols = instance.protocolName?.let(::listOf)
107110
}
108111
}
109-
110-
modules.add(instance.initializer)
111112
}
113+
112114
return try {
113-
embeddedServer(Jetty, environment).start()
115+
embeddedServer(Jetty, rootConfig, engineConfig).start()
114116
} catch (e: Exception) {
115117
println("$description failed to start with exception $e")
116118
throw e

runtime/protocol/http-client-engines/test-suite/jvm/test/aws/smithy/kotlin/runtime/http/test/FileUploadDownloadTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import aws.smithy.kotlin.runtime.hashing.sha256
1212
import aws.smithy.kotlin.runtime.http.*
1313
import aws.smithy.kotlin.runtime.http.complete
1414
import aws.smithy.kotlin.runtime.http.request.HttpRequest
15+
import aws.smithy.kotlin.runtime.http.test.suite.DOWNLOAD_SIZE
1516
import aws.smithy.kotlin.runtime.http.test.util.AbstractEngineTest
1617
import aws.smithy.kotlin.runtime.http.test.util.test
1718
import aws.smithy.kotlin.runtime.http.test.util.testSetup
@@ -62,16 +63,17 @@ class FileUploadDownloadTest : AbstractEngineTest() {
6263

6364
val expectedSha256 = call.response.headers["expected-sha256"] ?: fail("missing expected-sha256 header")
6465
val contentLength = call.response.body.contentLength ?: fail("expected Content-Length")
65-
check(contentLength < Int.MAX_VALUE)
66+
assertEquals(DOWNLOAD_SIZE, contentLength)
6667

6768
val body = call.response.body
6869
val stream = checkNotNull(body.toByteStream())
6970

7071
val file = RandomTempFile(0)
7172
stream.writeToFile(file)
73+
assertEquals(DOWNLOAD_SIZE, file.length())
74+
7275
val readSha256 = file.readBytes().sha256().encodeToHex()
7376
assertEquals(expectedSha256, readSha256)
74-
assertEquals(contentLength, file.length())
7577
} finally {
7678
call.complete()
7779
}

runtime/protocol/http-test/jvm/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class TestWithLocalServer {
2222
protected val serverPort: Int = ServerSocket(0).use { it.localPort }
2323
protected val testHost: String = "localhost"
2424

25-
public abstract val server: ApplicationEngine
25+
public abstract val server: EmbeddedServer<*, *>
2626

2727
@BeforeTest
2828
public fun startServer(): Unit = runBlocking {

tests/benchmarks/http-benchmarks/jvm/src/aws/smithy/kotlin/benchmarks/http/HttpEngineBenchmarks.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import aws.smithy.kotlin.runtime.io.SdkSource
1919
import aws.smithy.kotlin.runtime.io.source
2020
import aws.smithy.kotlin.runtime.net.Host
2121
import aws.smithy.kotlin.runtime.net.Scheme
22-
import io.ktor.server.application.*
2322
import io.ktor.server.engine.*
2423
import io.ktor.server.netty.*
2524
import io.ktor.server.response.*
2625
import io.ktor.server.routing.*
26+
import io.ktor.utils.io.core.remaining
27+
import io.ktor.utils.io.readRemaining
2728
import kotlinx.benchmark.Blackhole
2829
import kotlinx.coroutines.launch
2930
import kotlinx.coroutines.runBlocking

0 commit comments

Comments
 (0)