Skip to content

Commit 958657f

Browse files
committed
Revert "TimeStream Query is no longer accepting new customers, remove E2E test"
This reverts commit 66ec97b.
1 parent 3acc92b commit 958657f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.services.timestreamquery
6+
7+
import aws.sdk.kotlin.services.timestreamquery.model.DescribeEndpointsResponse
8+
import aws.sdk.kotlin.services.timestreamquery.model.ListScheduledQueriesResponse
9+
import aws.smithy.kotlin.runtime.client.ResponseInterceptorContext
10+
import aws.smithy.kotlin.runtime.client.operationName
11+
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
12+
import aws.smithy.kotlin.runtime.http.request.HttpRequest
13+
import aws.smithy.kotlin.runtime.http.response.HttpResponse
14+
import kotlinx.coroutines.runBlocking
15+
import org.junit.jupiter.api.Assertions.assertEquals
16+
import org.junit.jupiter.api.Assertions.assertNotNull
17+
import org.junit.jupiter.api.Test
18+
import org.junit.jupiter.api.TestInstance
19+
20+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
21+
class EndpointDiscoveryTest {
22+
@Test
23+
fun testEndpointDiscovery() = runBlocking {
24+
val operationLog = mutableListOf<String>()
25+
var discoveredHost: String? = null
26+
27+
val interceptor = object : HttpInterceptor {
28+
override fun readAfterExecution(
29+
context: ResponseInterceptorContext<Any, Any, HttpRequest?, HttpResponse?>,
30+
) {
31+
operationLog += context.executionContext.operationName!!
32+
33+
when (val response = context.response.getOrNull()) {
34+
is DescribeEndpointsResponse -> discoveredHost = response.endpoints!!.first().address
35+
36+
is ListScheduledQueriesResponse -> {
37+
// Make sure every request _except_ DescribeEndpoints uses the discovered endpoint
38+
assertNotNull(discoveredHost)
39+
assertEquals(discoveredHost, context.protocolRequest!!.url.host.toString())
40+
}
41+
42+
else -> error("Unexpected response ${context.response}")
43+
}
44+
}
45+
}
46+
47+
TimestreamQueryClient {
48+
region = "us-west-2"
49+
interceptors += interceptor
50+
}.use { tsq ->
51+
tsq.listScheduledQueries()
52+
53+
// Have to discover the endpoint the first time
54+
assertEquals(listOf("DescribeEndpoints", "ListScheduledQueries"), operationLog)
55+
operationLog.clear()
56+
57+
tsq.listScheduledQueries()
58+
59+
// Don't have to discover the endpoint again because it's cached
60+
assertEquals(listOf("ListScheduledQueries"), operationLog)
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)