@@ -5,14 +5,11 @@ import aws.sdk.kotlin.services.s3.S3Client
55import aws.sdk.kotlin.services.s3.model.GetObjectRequest
66import aws.sdk.kotlin.services.s3.model.PutObjectRequest
77import aws.sdk.kotlin.services.s3.presigners.presign
8- import aws.smithy.kotlin.runtime.content.ByteStream
98import aws.smithy.kotlin.runtime.content.decodeToString
109import aws.smithy.kotlin.runtime.http.response.complete
1110import aws.smithy.kotlin.runtime.http.sdkHttpClient
1211import aws.smithy.kotlin.runtime.http.toByteStream
13- import kotlinx.coroutines.ExperimentalCoroutinesApi
14- import kotlinx.coroutines.runBlocking
15- import kotlinx.coroutines.test.runTest
12+ import kotlinx.coroutines.*
1613import org.junit.jupiter.api.AfterAll
1714import org.junit.jupiter.api.BeforeAll
1815import org.junit.jupiter.api.TestInstance
@@ -27,8 +24,13 @@ class S3PresignerTest {
2724 const val DEFAULT_REGION = " us-east-2"
2825 }
2926
27+ private val engine = CrtHttpEngine {
28+ maxConnections = 64u
29+ }
30+
3031 private val client = S3Client {
3132 region = DEFAULT_REGION
33+ httpClientEngine = engine
3234 }
3335
3436 private lateinit var testBucket: String
@@ -39,58 +41,36 @@ class S3PresignerTest {
3941 }
4042
4143 @AfterAll
42- private fun cleanup () = runBlocking {
44+ private fun cleanup (): Unit = runBlocking {
4345 S3TestUtils .deleteBucketAndAllContents(client, testBucket)
46+ client.close()
47+ engine.close()
4448 }
4549
4650 @Test
47- fun testPutObjectPresigner () = runTest {
51+ fun testRoundTripBlns () = runBlocking {
4852 val contents = " presign-test"
53+ val dispatcher = Dispatchers .IO .limitedParallelism(64 )
54+ val httpClient = sdkHttpClient(engine)
4955
50- // FIXME - run these concurrently, test takes forever
5156 testKeyNames.forEach { keyName ->
52- val presignedRequest = PutObjectRequest {
53- bucket = testBucket
54- key = keyName
55- }.presign(client.config, 60 .seconds)
56-
57- S3TestUtils .responseCodeFromPut(presignedRequest, contents)
58-
59- val req = GetObjectRequest {
60- bucket = testBucket
61- key = keyName
62- }
63- val roundTrippedContents = client.getObject(req) { it.body?.decodeToString() }
64-
65- assertEquals(contents, roundTrippedContents)
66- }
67- }
57+ launch(dispatcher) {
58+ val presignedPutRequest = PutObjectRequest {
59+ bucket = testBucket
60+ key = keyName
61+ }.presign(client.config, 60 .seconds)
6862
69- @Test
70- fun testGetObjectPresigner () = runTest {
71- val contents = " presign-test"
72-
73- // FIXME - run these concurrently, test takes forever
74- testKeyNames.reversed().forEach { keyName ->
75- client.putObject {
76- bucket = testBucket
77- key = keyName
78- body = ByteStream .fromString(contents)
79- }
63+ S3TestUtils .responseCodeFromPut(presignedPutRequest, contents)
8064
81- val presignedRequest = GetObjectRequest {
82- bucket = testBucket
83- key = keyName
84- }.presign(client.config, 60 .seconds)
65+ val presignedGetRequest = GetObjectRequest {
66+ bucket = testBucket
67+ key = keyName
68+ }.presign(client.config, 60 .seconds)
8569
86- CrtHttpEngine ().use { engine ->
87- val httpClient = sdkHttpClient(engine)
88-
89- val call = httpClient.call(presignedRequest)
70+ val call = httpClient.call(presignedGetRequest)
71+ val body = call.response.body.toByteStream()?.decodeToString()
9072 call.complete()
91-
9273 assertEquals(200 , call.response.status.value)
93- val body = call.response.body.toByteStream()?.decodeToString()
9474 assertEquals(contents, body)
9575 }
9676 }
@@ -248,7 +228,7 @@ val testKeyNames: List<String>
248228 # Unicode additional control characters: all of the characters with
249229 # general category Cf (in Unicode 8.0.0).
250230 # The next line may appear to be blank or mojibake in some viewers.
251-
231+
252232
253233 # "Byte order marks", U+FEFF and U+FFFE, each on its own line.
254234 # The next two lines may appear to be blank or mojibake in some viewers.
0 commit comments