Skip to content

Commit 62e2f1d

Browse files
committed
clean up miscellaneous grammar, naming, and code factoring issues
1 parent 16292b4 commit 62e2f1d

File tree

6 files changed

+29
-37
lines changed

6 files changed

+29
-37
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ object RuntimeTypes {
9898
}
9999

100100
object Core : RuntimeTypePackage(KotlinDependency.CORE) {
101-
val Clock = symbol("Clock", "time")
102101
val ExecutionContext = symbol("ExecutionContext", "operation")
103102
val ErrorMetadata = symbol("ErrorMetadata")
104103
val ServiceErrorMetadata = symbol("ServiceErrorMetadata")

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/discovery/DefaultEndpointDiscovererGenerator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ class DefaultEndpointDiscovererGenerator(private val ctx: CodegenContext, privat
3636

3737
fun render() {
3838
delegator.applyFileWriter(symbol) {
39+
val service = clientName(ctx.settings.sdkId)
3940
dokka(
4041
"""
41-
A class which looks up specific endpoints for ${ctx.settings.sdkId} calls via the `$operationName`
42-
API. These unique endpoints are cached as appropriate to avoid unnecessary latency in subsequent
43-
calls.
42+
A class which looks up specific endpoints for $service calls via the `$operationName` API. These
43+
unique endpoints are cached as appropriate to avoid unnecessary latency in subsequent calls.
4444
@param cache An [ExpiringKeyedCache] implementation used to cache discovered hosts
4545
""".trimIndent(),
4646
)
47+
4748
withBlock(
48-
"#1L class #2T(#1L val cache: #3T<DiscoveryParams, #4T> = #5T(10.#6T, #7T.System)) : #8T {",
49+
"#1L class #2T(#1L val cache: #3T<DiscoveryParams, #4T> = #5T(10.#6T)) : #7T {",
4950
"}",
5051
ctx.settings.api.visibility,
5152
symbol,
5253
RuntimeTypes.Core.Collections.ExpiringKeyedCache,
5354
RuntimeTypes.Core.Net.Host,
5455
RuntimeTypes.Core.Collections.PeriodicSweepCache,
5556
KotlinTypes.Time.minutes,
56-
RuntimeTypes.Core.Clock,
5757
EndpointDiscovererInterfaceGenerator.symbolFor(ctx.settings),
5858
) {
5959
renderAsEndpointResolver()

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/discovery/EndpointDiscoveryIntegration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class EndpointDiscoveryIntegration : KotlinIntegration {
6262
override fun customizeMiddleware(
6363
ctx: ProtocolGenerator.GenerationContext,
6464
resolved: List<ProtocolMiddleware>,
65-
): List<ProtocolMiddleware> = super.customizeMiddleware(ctx, resolved) + listOf(DiscoveredEndpointErrorMiddleware)
65+
): List<ProtocolMiddleware> = resolved + DiscoveredEndpointErrorMiddleware
6666

6767
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = isEnabledFor(model, settings)
6868

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/discovery/DefaultEndpointDiscovererGeneratorTest.kt

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,35 @@ import software.amazon.smithy.kotlin.codegen.test.shouldContainOnlyOnceWithDiff
1212
import software.amazon.smithy.kotlin.codegen.test.toCodegenContext
1313

1414
class DefaultEndpointDiscovererGeneratorTest {
15+
private val renderedCodegen: String = run {
16+
val model = model()
17+
val testCtx = model.newTestContext()
18+
val delegator = testCtx.generationCtx.delegator
19+
val generator = DefaultEndpointDiscovererGenerator(testCtx.toCodegenContext(), delegator)
20+
generator.render()
21+
22+
delegator.flushWriters()
23+
val testManifest = delegator.fileManifest as MockManifest
24+
testManifest.expectFileString("/src/main/kotlin/com/test/endpoints/DefaultTestEndpointDiscoverer.kt")
25+
}
26+
1527
@Test
1628
fun testClass() {
17-
val actual = render()
18-
19-
actual.shouldContainOnlyOnceWithDiff(
29+
renderedCodegen.shouldContainOnlyOnceWithDiff(
2030
"""
2131
/**
22-
* A class which looks up specific endpoints for Test calls via the `getEndpoints`
23-
* API. These unique endpoints are cached as appropriate to avoid unnecessary latency in subsequent
24-
* calls.
32+
* A class which looks up specific endpoints for Test calls via the `getEndpoints` API. These
33+
* unique endpoints are cached as appropriate to avoid unnecessary latency in subsequent calls.
2534
* @param cache An [ExpiringKeyedCache] implementation used to cache discovered hosts
2635
*/
27-
public class DefaultTestEndpointDiscoverer(public val cache: ExpiringKeyedCache<DiscoveryParams, Host> = PeriodicSweepCache(10.minutes, Clock.System)) : TestEndpointDiscoverer {
36+
public class DefaultTestEndpointDiscoverer(public val cache: ExpiringKeyedCache<DiscoveryParams, Host> = PeriodicSweepCache(10.minutes)) : TestEndpointDiscoverer {
2837
""".trimIndent(),
2938
)
3039
}
3140

3241
@Test
3342
fun testAsEndpointResolver() {
34-
val actual = render()
35-
36-
actual.shouldContainOnlyOnceWithDiff(
43+
renderedCodegen.shouldContainOnlyOnceWithDiff(
3744
"""
3845
override fun asEndpointResolver(client: TestClient, delegate: EndpointResolver): EndpointResolver = EndpointResolver { request ->
3946
if (client.config.endpointUrl == null) {
@@ -60,26 +67,12 @@ class DefaultEndpointDiscovererGeneratorTest {
6067

6168
@Test
6269
fun testInvalidate() {
63-
val actual = render()
64-
65-
actual.shouldContainOnlyOnceWithDiff(
70+
renderedCodegen.shouldContainOnlyOnceWithDiff(
6671
"""
6772
override public suspend fun invalidate(context: ExecutionContext) {
6873
context.getOrNull(DiscoveryParamsKey)?.let { cache.invalidate(it) }
6974
}
7075
""".formatForTest(),
7176
)
7277
}
73-
74-
private fun render(): String {
75-
val model = model()
76-
val testCtx = model.newTestContext()
77-
val delegator = testCtx.generationCtx.delegator
78-
val generator = DefaultEndpointDiscovererGenerator(testCtx.toCodegenContext(), delegator)
79-
generator.render()
80-
81-
delegator.flushWriters()
82-
val testManifest = delegator.fileManifest as MockManifest
83-
return testManifest.expectFileString("/src/main/kotlin/com/test/endpoints/DefaultTestEndpointDiscoverer.kt")
84-
}
8578
}

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/discovery/EndpointDiscoveryTestUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ fun model() =
1010
// language=smithy
1111
"""
1212
namespace com.test
13-
13+
1414
use aws.protocols#awsJson1_1
1515
use aws.api#service
1616
use aws.auth#sigv4
17-
17+
1818
@service(sdkId: "test")
1919
@sigv4(name: "test")
2020
@awsJson1_1
@@ -30,7 +30,7 @@ fun model() =
3030
@error("client")
3131
@httpError(421)
3232
structure BadEndpointError { }
33-
33+
3434
@http(method: "GET", uri: "/endpoints")
3535
operation GetEndpoints {
3636
input: GetEndpointsInput

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/collections/ExpiringKeyedCache.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import aws.smithy.kotlin.runtime.util.ExpiringValue
1111
* [invalidate] methods are `suspend` functions to allow for cross-context synchronization and potentially-expensive
1212
* value lookup.
1313
*
14-
* Values in the cache _may_ expire and are retrieved as [ExpiringValue]. When a value absent/expired in the cache,
14+
* Values in the cache _may_ expire and are retrieved as [ExpiringValue]. When a value is absent/expired in the cache,
1515
* invoking [get] will cause a lookup to occur via the function's `valueLookup` parameter.
1616
*
1717
* @param K The type of the keys of this cache
@@ -29,7 +29,7 @@ public interface ExpiringKeyedCache<K, V> {
2929
* exceptions, fall back to other caches, etc.
3030
* @param key The key for which to look up a value
3131
* @param valueLookup A possibly-suspending function which returns the read-through value associated with a given
32-
* key. This function is invoked when the cache, for a given key, does not contain a value or the value is expired.
32+
* key. This function is invoked when the cache does not contain the given [key] or when the value is expired.
3333
*/
3434
public suspend fun get(key: K, valueLookup: suspend (K) -> ExpiringValue<V>): V
3535

0 commit comments

Comments
 (0)