-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Kotlin Spring Boot starter (#433)
* Introduce sdk-spring-boot-kotlin-starter and move common spring boot integration code in sdk-spring-boot * Dependency cleanup
- Loading branch information
1 parent
b40c904
commit f19f538
Showing
24 changed files
with
216 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
`kotlin-conventions` | ||
`library-publishing-conventions` | ||
alias(libs.plugins.ksp) | ||
alias(libs.plugins.spring.dependency.management) | ||
} | ||
|
||
description = "Restate SDK Spring Boot Kotlin starter" | ||
|
||
dependencies { | ||
compileOnly(libs.jspecify) | ||
|
||
api(project(":sdk-api-kotlin")) | ||
api(project(":sdk-spring-boot")) | ||
|
||
kspTest(project(":sdk-api-kotlin-gen")) | ||
testImplementation(project(":sdk-testing")) | ||
testImplementation(libs.kotlinx.coroutines.test) | ||
testImplementation(libs.spring.boot.starter.test) | ||
|
||
// We need these for the deployment manifest | ||
testImplementation(project(":sdk-core")) | ||
testImplementation(libs.jackson.annotations) | ||
testImplementation(libs.jackson.databind) | ||
} |
24 changes: 24 additions & 0 deletions
24
sdk-spring-boot-kotlin-starter/src/test/kotlin/dev/restate/sdk/springboot/kotlin/Greeter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot.kotlin | ||
|
||
import dev.restate.sdk.annotation.Handler | ||
import dev.restate.sdk.kotlin.Context | ||
import dev.restate.sdk.springboot.RestateService | ||
import org.springframework.beans.factory.annotation.Value | ||
|
||
@RestateService(name = "greeter") | ||
class Greeter { | ||
@Value("\${greetingPrefix}") lateinit var greetingPrefix: String | ||
|
||
@Handler | ||
fun greet(ctx: Context, person: String): String { | ||
return greetingPrefix + person | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...-starter/src/test/kotlin/dev/restate/sdk/springboot/kotlin/RestateHttpEndpointBeanTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot.kotlin | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import dev.restate.sdk.core.manifest.EndpointManifestSchema | ||
import dev.restate.sdk.core.manifest.Service | ||
import dev.restate.sdk.springboot.RestateHttpEndpointBean | ||
import java.io.IOException | ||
import java.net.URI | ||
import java.net.http.HttpClient | ||
import java.net.http.HttpRequest | ||
import java.net.http.HttpResponse | ||
import org.assertj.core.api.Assertions | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest( | ||
classes = [RestateHttpEndpointBean::class, Greeter::class], | ||
properties = ["restate.sdk.http.port=0"]) | ||
class RestateHttpEndpointBeanTest { | ||
@Autowired lateinit var restateHttpEndpointBean: RestateHttpEndpointBean | ||
|
||
@Test | ||
@Throws(IOException::class, InterruptedException::class) | ||
fun httpEndpointShouldBeRunning() { | ||
assertThat(restateHttpEndpointBean.isRunning).isTrue() | ||
assertThat(restateHttpEndpointBean.actualPort()).isPositive() | ||
|
||
// Check if discovery replies containing the Greeter service | ||
val client = HttpClient.newHttpClient() | ||
val response = | ||
client.send<String?>( | ||
HttpRequest.newBuilder() | ||
.GET() | ||
.uri( | ||
URI.create( | ||
("http://localhost:" + restateHttpEndpointBean.actualPort()).toString() + | ||
"/discover")) | ||
.header("Accept", "application/vnd.restate.endpointmanifest.v1+json") | ||
.build(), | ||
HttpResponse.BodyHandlers.ofString()) | ||
Assertions.assertThat(response.statusCode()).isEqualTo(200) | ||
|
||
val endpointManifest = | ||
ObjectMapper() | ||
.readValue<EndpointManifestSchema>(response.body(), EndpointManifestSchema::class.java) | ||
|
||
Assertions.assertThat<Service?>(endpointManifest.services) | ||
.map<String>({ it.name }) | ||
.containsOnly("greeter") | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...in-starter/src/test/kotlin/dev/restate/sdk/springboot/kotlin/SdkTestingIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot.kotlin | ||
|
||
import dev.restate.sdk.client.Client | ||
import dev.restate.sdk.testing.BindService | ||
import dev.restate.sdk.testing.RestateClient | ||
import dev.restate.sdk.testing.RestateTest | ||
import kotlinx.coroutines.test.runTest | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.Timeout | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest(classes = [Greeter::class], properties = ["greetingPrefix=Something something "]) | ||
@RestateTest(containerImage = "ghcr.io/restatedev/restate:main") | ||
class SdkTestingIntegrationTest { | ||
@Autowired @BindService lateinit var greeter: Greeter | ||
|
||
@Test | ||
@Timeout(value = 10) | ||
fun greet(@RestateClient ingressClient: Client) = runTest { | ||
val client = greeterClient.fromClient(ingressClient) | ||
|
||
Assertions.assertThat(client.greet("Francesco")).isEqualTo("Something something Francesco") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
plugins { | ||
`java-conventions` | ||
`java-library` | ||
`test-jar-conventions` | ||
`library-publishing-conventions` | ||
alias(libs.plugins.spring.dependency.management) | ||
} | ||
|
||
description = "Restate SDK Spring Boot integration" | ||
|
||
dependencies { | ||
compileOnly(libs.jspecify) | ||
|
||
api(project(":sdk-common")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
|
||
implementation(project(":sdk-http-vertx")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
implementation(project(":sdk-request-identity")) | ||
implementation(libs.vertx.core) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
|
||
implementation(libs.spring.boot.starter) | ||
|
||
// Spring is going to bring jackson in with this | ||
implementation(libs.spring.boot.starter.json) | ||
|
||
testImplementation(libs.spring.boot.starter.test) | ||
} | ||
|
||
tasks.withType<JavaCompile> { options.compilerArgs.add("-parameters") } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.