From 6474c392d463cab070e3c8c4bfce445cb80612af Mon Sep 17 00:00:00 2001 From: Ian Smith Botsford Date: Tue, 14 Dec 2021 22:24:33 +0000 Subject: [PATCH 1/2] feat: upgrade to Kotlin 1.6.10 --- .../sdk/kotlin/runtime/config/CachedValue.kt | 4 ++-- .../kotlin/runtime/config/imds/ImdsClient.kt | 7 +++--- .../runtime/config/imds/TokenMiddleware.kt | 7 +++--- .../kotlin/runtime/config/CachedValueTest.kt | 22 +++++++++---------- .../runtime/config/imds/ImdsClientTest.kt | 12 +++++----- .../runtime/auth/signing/Sigv4TestSuite.kt | 4 ++-- .../http/engine/crt/AsyncStressTest.kt | 4 ++-- build.gradle.kts | 3 +-- examples/build.gradle.kts | 2 +- gradle.properties | 16 +++++++------- 10 files changed, 41 insertions(+), 40 deletions(-) diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/CachedValue.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/CachedValue.kt index 76b9c02b4eb..d81a4dc3da8 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/CachedValue.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/CachedValue.kt @@ -29,10 +29,10 @@ internal data class ExpiringValue (val value: T, val expiresAt: Instant) @OptIn(ExperimentalTime::class) internal class CachedValue ( private var value: ExpiringValue? = null, - private val bufferTime: Duration = Duration.seconds(0), + private val bufferTime: Duration = Duration.ZERO, private val clock: Clock = Clock.System ) { - constructor(value: T, expiresAt: Instant, bufferTime: Duration = Duration.seconds(0), clock: Clock = Clock.System) : this(ExpiringValue(value, expiresAt), bufferTime, clock) + constructor(value: T, expiresAt: Instant, bufferTime: Duration = Duration.ZERO, clock: Clock = Clock.System) : this(ExpiringValue(value, expiresAt), bufferTime, clock) private val mu = Mutex() /** diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt index 8ba3d982d02..cacc6709354 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt @@ -26,6 +26,7 @@ import aws.smithy.kotlin.runtime.time.Clock import aws.smithy.kotlin.runtime.util.Platform import aws.smithy.kotlin.runtime.util.PlatformProvider import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime /** @@ -70,8 +71,8 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata init { require(maxRetries > 0) { "maxRetries must be greater than zero" } val engine = builder.engine ?: CrtHttpEngine { - connectTimeout = Duration.seconds(1) - socketReadTimeout = Duration.seconds(1) + connectTimeout = 1.seconds + socketReadTimeout = 1.seconds } httpClient = sdkHttpClient(engine) @@ -161,7 +162,7 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata /** * Override the time-to-live for the session token */ - public var tokenTtl: Duration = Duration.seconds(DEFAULT_TOKEN_TTL_SECONDS) + public var tokenTtl: Duration = DEFAULT_TOKEN_TTL_SECONDS.seconds /** * Configure the [SdkLogMode] used by the client diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt index a6f01a75a55..ee058b4a556 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt @@ -17,6 +17,7 @@ import aws.smithy.kotlin.runtime.http.request.url import aws.smithy.kotlin.runtime.http.response.complete import aws.smithy.kotlin.runtime.time.Clock import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime /** @@ -32,10 +33,10 @@ internal const val X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token" @OptIn(ExperimentalTime::class) internal class TokenMiddleware( private val httpClient: SdkHttpClient, - private val ttl: Duration = Duration.seconds(DEFAULT_TOKEN_TTL_SECONDS), + private val ttl: Duration = DEFAULT_TOKEN_TTL_SECONDS.seconds, private val clock: Clock = Clock.System ) : ModifyRequestMiddleware { - private var cachedToken = CachedValue(null, bufferTime = Duration.seconds(TOKEN_REFRESH_BUFFER_SECONDS), clock = clock) + private var cachedToken = CachedValue(null, bufferTime = TOKEN_REFRESH_BUFFER_SECONDS.seconds, clock = clock) override fun install(op: SdkHttpOperation<*, *>) { op.execution.finalize.register(this) @@ -71,7 +72,7 @@ internal class TokenMiddleware( HttpStatusCode.OK -> { val ttl = call.response.headers[X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS]?.toLong() ?: throw EC2MetadataError(200, "No TTL provided in IMDS response") val token = call.response.body.readAll() ?: throw EC2MetadataError(200, "No token provided in IMDS response") - val expires = clock.now() + Duration.seconds(ttl) + val expires = clock.now() + ttl.seconds Token(token, expires) } else -> { diff --git a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/CachedValueTest.kt b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/CachedValueTest.kt index f632ee006aa..1c3f2255de8 100644 --- a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/CachedValueTest.kt +++ b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/CachedValueTest.kt @@ -13,7 +13,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.yield import kotlin.test.* -import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime @OptIn(ExperimentalTime::class) @@ -31,7 +31,7 @@ class CachedValueTest { @Test fun testExpiration() = runSuspendTest { val epoch = Instant.fromEpochSeconds(0) - val expiresAt = epoch + Duration.seconds(10) + val expiresAt = epoch + 10.seconds val clock = ManualClock(epoch) val value = CachedValue("foo", expiresAt, clock = clock) @@ -39,7 +39,7 @@ class CachedValueTest { assertFalse(value.isExpired()) assertEquals("foo", value.get()) - clock.advance(Duration.seconds(10)) + clock.advance(10.seconds) assertTrue(value.isExpired()) assertNull(value.get()) } @@ -47,15 +47,15 @@ class CachedValueTest { @Test fun testExpirationBuffer() = runSuspendTest { val epoch = Instant.fromEpochSeconds(0) - val expiresAt = epoch + Duration.seconds(100) + val expiresAt = epoch + 100.seconds val clock = ManualClock(epoch) - val value = CachedValue("foo", expiresAt, bufferTime = Duration.seconds(30), clock = clock) + val value = CachedValue("foo", expiresAt, bufferTime = 30.seconds, clock = clock) assertFalse(value.isExpired()) assertEquals("foo", value.get()) - clock.advance(Duration.seconds(70)) + clock.advance(70.seconds) assertTrue(value.isExpired()) assertNull(value.get()) } @@ -63,16 +63,16 @@ class CachedValueTest { @Test fun testGetOrLoad() = runSuspendTest { val epoch = Instant.fromEpochSeconds(0) - val expiresAt = epoch + Duration.seconds(100) + val expiresAt = epoch + 100.seconds val clock = ManualClock(epoch) - val value = CachedValue("foo", expiresAt, bufferTime = Duration.seconds(30), clock = clock) + val value = CachedValue("foo", expiresAt, bufferTime = 30.seconds, clock = clock) var count = 0 val mu = Mutex() val initializer = suspend { mu.withLock { count++ } - ExpiringValue("bar", expiresAt + Duration.seconds(count * 100)) + ExpiringValue("bar", expiresAt + count.seconds * 100) } assertFalse(value.isExpired()) @@ -80,13 +80,13 @@ class CachedValueTest { assertEquals(0, count) // t = 90 - clock.advance(Duration.seconds(90)) + clock.advance(90.seconds) assertEquals("bar", value.getOrLoad(initializer)) assertFalse(value.isExpired()) assertEquals(1, count) // t = 180 - clock.advance(Duration.seconds(90)) + clock.advance(90.seconds) repeat(10) { async { value.getOrLoad(initializer) diff --git a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/imds/ImdsClientTest.kt b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/imds/ImdsClientTest.kt index 8e688ceede3..ae373711ce7 100644 --- a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/imds/ImdsClientTest.kt +++ b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/imds/ImdsClientTest.kt @@ -21,7 +21,7 @@ import io.kotest.matchers.string.shouldContain import kotlinx.coroutines.withTimeout import kotlinx.serialization.json.* import kotlin.test.* -import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime @OptIn(ExperimentalTime::class) @@ -80,12 +80,12 @@ class ImdsClientTest { engine = connection endpointConfiguration = EndpointConfiguration.ModeOverride(EndpointMode.IPv6) clock = testClock - tokenTtl = Duration.seconds(600) + tokenTtl = 600.seconds } val r1 = client.get("/latest/metadata") assertEquals("output 1", r1) - testClock.advance(Duration.seconds(600)) + testClock.advance(600.seconds) val r2 = client.get("/latest/metadata") assertEquals("output 2", r2) @@ -127,17 +127,17 @@ class ImdsClientTest { engine = connection endpointConfiguration = EndpointConfiguration.ModeOverride(EndpointMode.IPv6) clock = testClock - tokenTtl = Duration.seconds(600) + tokenTtl = 600.seconds } val r1 = client.get("/latest/metadata") assertEquals("output 1", r1) - testClock.advance(Duration.seconds(400)) + testClock.advance(400.seconds) val r2 = client.get("/latest/metadata") assertEquals("output 2", r2) - testClock.advance(Duration.seconds(150)) + testClock.advance(150.seconds) val r3 = client.get("/latest/metadata") assertEquals("output 3", r3) diff --git a/aws-runtime/aws-signing/jvm/test/aws/sdk/kotlin/runtime/auth/signing/Sigv4TestSuite.kt b/aws-runtime/aws-signing/jvm/test/aws/sdk/kotlin/runtime/auth/signing/Sigv4TestSuite.kt index cc6db1c886e..39f00f13fd3 100644 --- a/aws-runtime/aws-signing/jvm/test/aws/sdk/kotlin/runtime/auth/signing/Sigv4TestSuite.kt +++ b/aws-runtime/aws-signing/jvm/test/aws/sdk/kotlin/runtime/auth/signing/Sigv4TestSuite.kt @@ -32,7 +32,7 @@ import kotlin.io.path.exists import kotlin.io.path.name import kotlin.io.path.readText import kotlin.test.* -import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime private const val DEFAULT_SIGNING_ISO_DATE = "2015-08-30T12:36:00Z" @@ -205,7 +205,7 @@ class Sigv4TestSuite { config.service = json["service"]!!.jsonPrimitive.content json["expiration_in_seconds"]?.jsonPrimitive?.int?.let { - config.expiresAfter = Duration.seconds(it) + config.expiresAfter = it.seconds } json["normalize"]?.jsonPrimitive?.boolean?.let { diff --git a/aws-runtime/http-client-engine-crt/jvm/test/aws/sdk/kotlin/runtime/http/engine/crt/AsyncStressTest.kt b/aws-runtime/http-client-engine-crt/jvm/test/aws/sdk/kotlin/runtime/http/engine/crt/AsyncStressTest.kt index 4cc713fbeb0..61facfa08fc 100644 --- a/aws-runtime/http-client-engine-crt/jvm/test/aws/sdk/kotlin/runtime/http/engine/crt/AsyncStressTest.kt +++ b/aws-runtime/http-client-engine-crt/jvm/test/aws/sdk/kotlin/runtime/http/engine/crt/AsyncStressTest.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.async import kotlinx.coroutines.withTimeout import kotlinx.coroutines.yield import kotlin.test.Test -import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime class AsyncStressTest : TestWithLocalServer() { @@ -90,7 +90,7 @@ class AsyncStressTest : TestWithLocalServer() { } } - withTimeout(Duration.seconds(5)) { + withTimeout(5.seconds) { repeat(1_000) { async { try { diff --git a/build.gradle.kts b/build.gradle.kts index 84f108616c7..0c7aadcb80a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,10 +3,9 @@ * SPDX-License-Identifier: Apache-2.0. */ import java.util.Properties -import java.net.URL plugins { - kotlin("jvm") version "1.5.31" apply false + kotlin("jvm") version "1.6.10" apply false id("org.jetbrains.dokka") id("io.github.gradle-nexus.publish-plugin") version "1.1.0" } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index a9877c7be02..16ccc9545f4 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") version "1.5.31" + kotlin("jvm") version "1.6.10" } val awsSdkKotlinVersion: String by project diff --git a/gradle.properties b/gradle.properties index f3ea588178d..618435ec085 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,23 +12,23 @@ sdkVersion=0.9.6-SNAPSHOT smithyVersion=1.13.1 smithyGradleVersion=0.5.3 # smithy-kotlin codegen and runtime are versioned together -smithyKotlinVersion=0.7.4-beta +smithyKotlinVersion=0.7.5-SNAPSHOT # kotlin -kotlinVersion=1.5.31 -dokkaVersion=1.5.31 +kotlinVersion=1.6.10 +dokkaVersion=1.6.0 # kotlin JVM kotlinJVMTargetVersion=1.8 # kotlin libraries -coroutinesVersion=1.5.1 -atomicFuVersion=0.16.1 -kotlinxSerializationVersion=1.3.0 -ktorVersion=1.6.3 +coroutinesVersion=1.5.2 +atomicFuVersion=0.17.0 +kotlinxSerializationVersion=1.3.1 +ktorVersion=1.6.7 # crt -crtKotlinVersion=0.5.0-alpha +crtKotlinVersion=0.5.1-SNAPSHOT # testing/utility junitVersion=5.6.2 From 0e6ef2252159c4b1fa1a5ed5b0da8b9f2cc77ec1 Mon Sep 17 00:00:00 2001 From: Ian Smith Botsford Date: Tue, 14 Dec 2021 22:34:28 +0000 Subject: [PATCH 2/2] fix broken Gradle build --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index 0c7aadcb80a..169c88c23e4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0. */ import java.util.Properties +import java.net.URL plugins { kotlin("jvm") version "1.6.10" apply false