Skip to content

Commit e5c0f64

Browse files
committed
Merge branch 'kn-main' of github.com:smithy-lang/smithy-kotlin into kn-platform
2 parents cda0523 + 99d1214 commit e5c0f64

File tree

18 files changed

+390
-75
lines changed

18 files changed

+390
-75
lines changed

runtime/protocol/http-client/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kotlin {
2727
commonTest {
2828
dependencies {
2929
implementation(libs.kotlinx.coroutines.test)
30+
implementation(project(":runtime:runtime-core"))
3031
implementation(project(":runtime:protocol:http-test"))
3132
}
3233
}

runtime/protocol/http-client/common/test/aws/smithy/kotlin/runtime/http/interceptors/HttpChecksumRequiredInterceptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class HttpChecksumRequiredInterceptorTest {
6868
assertEquals(expected, call.request.headers["x-amz-checksum-crc32"])
6969
}
7070

71-
@IgnoreNative // FIXME Re-enable after Kotlin/Native Implementation
71+
@IgnoreNative
7272
@Test
7373
fun itSetsHeaderForNonBytesContent() = runTest {
7474
val req = HttpRequestBuilder().apply {

runtime/protocol/http-client/common/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import aws.smithy.kotlin.runtime.IgnoreNative
99
import aws.smithy.kotlin.runtime.collections.get
1010
import aws.smithy.kotlin.runtime.compression.CompressionAlgorithm
1111
import aws.smithy.kotlin.runtime.compression.Gzip
12+
import aws.smithy.kotlin.runtime.compression.decompressGzipBytes
1213
import aws.smithy.kotlin.runtime.http.*
1314
import aws.smithy.kotlin.runtime.http.operation.HttpOperationContext
1415
import aws.smithy.kotlin.runtime.http.operation.newTestOperation
@@ -23,8 +24,6 @@ import kotlin.test.assertContentEquals
2324
import kotlin.test.assertEquals
2425
import kotlin.test.assertFailsWith
2526

26-
internal expect fun decompressGzipBytes(bytes: ByteArray): ByteArray
27-
2827
class RequestCompressionInterceptorTest {
2928

3029
private val client = SdkHttpClient(TestEngine())

runtime/protocol/http-client/jvm/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestJvm.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

runtime/protocol/http-client/native/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestNative.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

runtime/runtime-core/api/runtime-core.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ public final class aws/smithy/kotlin/runtime/compression/Gzip : aws/smithy/kotli
330330
public fun getId ()Ljava/lang/String;
331331
}
332332

333+
public final class aws/smithy/kotlin/runtime/compression/GzipTestUtilsJvmKt {
334+
public static final fun decompressGzipBytes ([B)[B
335+
}
336+
333337
public final class aws/smithy/kotlin/runtime/config/EnvironmentSetting {
334338
public static final field Companion Laws/smithy/kotlin/runtime/config/EnvironmentSetting$Companion;
335339
public fun <init> (Lkotlin/jvm/functions/Function1;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V
@@ -465,6 +469,8 @@ public final class aws/smithy/kotlin/runtime/content/ByteStreamJVMKt {
465469
}
466470

467471
public final class aws/smithy/kotlin/runtime/content/ByteStreamKt {
472+
public static final fun asByteStream (Ljava/lang/String;)Laws/smithy/kotlin/runtime/content/ByteStream;
473+
public static final fun asByteStream ([B)Laws/smithy/kotlin/runtime/content/ByteStream;
468474
public static final fun cancel (Laws/smithy/kotlin/runtime/content/ByteStream;)V
469475
public static final fun decodeToString (Laws/smithy/kotlin/runtime/content/ByteStream;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
470476
public static final fun toByteArray (Laws/smithy/kotlin/runtime/content/ByteStream;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipTestUtils.kt renamed to runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/compression/GzipTestUtils.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package aws.smithy.kotlin.runtime.io
5+
package aws.smithy.kotlin.runtime.compression
6+
7+
import aws.smithy.kotlin.runtime.InternalApi
68

79
/**
810
* Decompresses a [ByteArray] compressed using the gzip format
911
*/
10-
internal expect fun decompressGzipBytes(bytes: ByteArray): ByteArray
12+
@InternalApi
13+
public expect fun decompressGzipBytes(bytes: ByteArray): ByteArray

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/content/ByteStream.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package aws.smithy.kotlin.runtime.content
77
import aws.smithy.kotlin.runtime.io.*
88
import aws.smithy.kotlin.runtime.io.internal.SdkDispatchers
99
import kotlinx.coroutines.CoroutineScope
10-
import kotlinx.coroutines.IO
1110
import kotlinx.coroutines.flow.*
1211
import kotlinx.coroutines.launch
1312

@@ -197,3 +196,13 @@ private fun SdkSource.toFlow(bufferSize: Long): Flow<ByteArray> = flow {
197196
emit(sink.readByteArray())
198197
}
199198
}
199+
200+
/**
201+
* Convert this [String] to a [ByteStream]
202+
*/
203+
public fun String.asByteStream(): ByteStream = ByteStream.fromString(this)
204+
205+
/**
206+
* Convert this [ByteArray] to a [ByteStream]
207+
*/
208+
public fun ByteArray.asByteStream(): ByteStream = ByteStream.fromBytes(this)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package aws.smithy.kotlin.runtime.compression
7+
8+
import aws.smithy.kotlin.runtime.content.ByteStream
9+
import aws.smithy.kotlin.runtime.content.toByteArray
10+
import kotlinx.coroutines.test.runTest
11+
import kotlin.test.Test
12+
import kotlin.test.assertContentEquals
13+
14+
class GzipTest {
15+
@Test
16+
fun testCompress() = runTest {
17+
val payload = "Hello World".encodeToByteArray()
18+
val byteStream = ByteStream.fromBytes(payload)
19+
20+
val compressed = Gzip()
21+
.compress(byteStream)
22+
.toByteArray()
23+
24+
val decompressedBytes = decompressGzipBytes(compressed)
25+
assertContentEquals(payload, decompressedBytes)
26+
}
27+
28+
@Test
29+
fun testCompressEmptyByteArray() = runTest {
30+
val payload = ByteArray(0)
31+
val byteStream = ByteStream.fromBytes(payload)
32+
33+
val compressed = Gzip()
34+
.compress(byteStream)
35+
.toByteArray()
36+
37+
val decompressedBytes = decompressGzipBytes(compressed)
38+
39+
assertContentEquals(payload, decompressedBytes)
40+
}
41+
}

runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipByteReadChannelTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
*/
55
package aws.smithy.kotlin.runtime.io
66

7-
import aws.smithy.kotlin.runtime.IgnoreNative
7+
import aws.smithy.kotlin.runtime.compression.decompressGzipBytes
88
import aws.smithy.kotlin.runtime.hashing.crc32
99
import kotlinx.coroutines.test.runTest
1010
import kotlin.test.Test
1111
import kotlin.test.assertContentEquals
1212
import kotlin.test.assertEquals
1313

1414
class GzipByteReadChannelTest {
15-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
1615
@Test
1716
fun testReadAll() = runTest {
1817
val payload = "Hello World"
@@ -32,7 +31,6 @@ class GzipByteReadChannelTest {
3231
assertEquals(bytesHash, decompressedBytes.crc32())
3332
}
3433

35-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
3634
@Test
3735
fun testReadToBuffer() = runTest {
3836
val payload = "Hello World".repeat(1600)
@@ -51,7 +49,6 @@ class GzipByteReadChannelTest {
5149
assertEquals(bytesHash, decompressedBytes.crc32())
5250
}
5351

54-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
5552
@Test
5653
fun testReadRemaining() = runTest {
5754
val payload = "Hello World".repeat(1600)
@@ -71,7 +68,6 @@ class GzipByteReadChannelTest {
7168
assertEquals(bytesHash, decompressedBytes.crc32())
7269
}
7370

74-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
7571
@Test
7672
fun testRead() = runTest {
7773
val payload = "Hello World"
@@ -92,7 +88,6 @@ class GzipByteReadChannelTest {
9288
assertEquals(bytesHash, decompressedBytes.crc32())
9389
}
9490

95-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
9691
@Test
9792
fun testReadLargeBody() = runTest {
9893
val payload = "Hello World".repeat(1600)
@@ -113,7 +108,6 @@ class GzipByteReadChannelTest {
113108
assertEquals(bytesHash, decompressedBytes.crc32())
114109
}
115110

116-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
117111
@Test
118112
fun testReadLargeLimit() = runTest {
119113
val payload = "Hello World"
@@ -134,7 +128,6 @@ class GzipByteReadChannelTest {
134128
assertEquals(bytesHash, decompressedBytes.crc32())
135129
}
136130

137-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
138131
@Test
139132
fun testReadLargeBodyLargeLimit() = runTest {
140133
val payload = "Hello World".repeat(1600)
@@ -155,7 +148,6 @@ class GzipByteReadChannelTest {
155148
assertEquals(bytesHash, decompressedBytes.crc32())
156149
}
157150

158-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
159151
@Test
160152
fun testIsClosedForRead() = runTest {
161153
val payload = "Hello World"
@@ -178,7 +170,6 @@ class GzipByteReadChannelTest {
178170
assertEquals(bytesHash, decompressedBytes.crc32())
179171
}
180172

181-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
182173
@Test
183174
fun testIsClosedForReadLargeBody() = runTest {
184175
val payload = "Hello World".repeat(1600)
@@ -201,7 +192,6 @@ class GzipByteReadChannelTest {
201192
assertEquals(bytesHash, decompressedBytes.crc32())
202193
}
203194

204-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
205195
@Test
206196
fun testIsClosedForReadLargeLimit() = runTest {
207197
val payload = "Hello World"
@@ -224,7 +214,6 @@ class GzipByteReadChannelTest {
224214
assertEquals(bytesHash, decompressedBytes.crc32())
225215
}
226216

227-
@IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
228217
@Test
229218
fun testIsClosedForReadLargeBodyLargeLimit() = runTest {
230219
val payload = "Hello World".repeat(1600)

0 commit comments

Comments
 (0)