Skip to content

Commit

Permalink
fix: unify JVM scaffold to match go (#4722)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Feb 28, 2025
1 parent 0bdf07e commit 543c1f6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@
public class {{ .Name | camel }} {
@Export
@Verb
public String hello(String request) {
return "Hello, " + request + "!";
public HelloResponse hello(HelloRequest request) {
return new HelloResponse().setMessage("Hello, " + request.getName() + "!");
}

public static class HelloRequest {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

public static class HelloResponse {

private String message;

public String getMessage() {
return message;
}

public HelloResponse setMessage(String message) {
this.message = message;
return this;
}
}
}
20 changes: 10 additions & 10 deletions jvm-runtime/jvm_hot_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func TestLifecycleJVM(t *testing.T) {
deployment := ""
in.Run(t,
in.WithLanguages("java"),
in.WithLanguages("java", "kotlin"),
in.WithDevMode(),
in.GitInit(),
in.Exec("rm", "ftl-project.toml"),
Expand All @@ -33,19 +33,19 @@ func TestLifecycleJVM(t *testing.T) {
}
}
}),
in.Call("echo", "hello", "Bob", func(t testing.TB, response string) {
assert.Equal(t, "Hello, Bob!", response)
in.Call("echo", "hello", map[string]string{"name": "Bob"}, func(t testing.TB, response map[string]string) {
assert.Equal(t, "Hello, Bob!", response["message"])
}),
// Now test hot reload
// Deliberate compile error, we need to check that we can recover from this
in.IfLanguage("java", in.EditFile("echo", func(content []byte) []byte {
return []byte(strings.ReplaceAll(string(content), "Hello", "Bye"))
return []byte(strings.ReplaceAll(string(content), "\"Hello", "\"Bye"))
}, "src/main/java/ftl/echo/Echo.java")),
in.IfLanguage("kotlin", in.EditFile("echo", func(content []byte) []byte {
return []byte(strings.ReplaceAll(string(content), "Hello", "Bye"))
}, "src/main/kotlin/ftl/echo/Echo.kt")),
in.Call("echo", "hello", "Bob", func(t testing.TB, response string) {
assert.Equal(t, "Bye, Bob!", response)
in.Call("echo", "hello", map[string]string{"name": "Bob"}, func(t testing.TB, response map[string]string) {
assert.Equal(t, "Bye, Bob!", response["message"])
}),
in.VerifySchema(func(ctx context.Context, t testing.TB, sch *schema.Schema) {
// Non structurally changing edits should not trigger a new deployment.
Expand All @@ -71,8 +71,8 @@ func TestLifecycleJVM(t *testing.T) {
in.IfLanguage("kotlin", in.EditFile("echo", func(content []byte) []byte {
return []byte(strings.ReplaceAll(string(content), "broken", ""))
}, "src/main/kotlin/ftl/echo/Echo.kt")),
in.Call("echo", "hello", "Bob", func(t testing.TB, response string) {
assert.Equal(t, "Bye, Bob!", response)
in.Call("echo", "hello", map[string]string{"name": "Bob"}, func(t testing.TB, response map[string]string) {
assert.Equal(t, "Bye, Bob!", response["message"])
}),
in.VerifySchema(func(ctx context.Context, t testing.TB, sch *schema.Schema) {
// Non structurally changing edits should not trigger a new deployment.
Expand All @@ -94,8 +94,8 @@ func TestLifecycleJVM(t *testing.T) {
</dependencies>`, 1))
}, "pom.xml"),

in.Call("echo", "hello", "Bob", func(t testing.TB, response string) {
assert.Equal(t, "Bye, Bob!", response)
in.Call("echo", "hello", map[string]string{"name": "Bob"}, func(t testing.TB, response map[string]string) {
assert.Equal(t, "Bye, Bob!", response["message"])
}),
// Now lets add a database, add the ftl config
in.EditFile("echo", func(content []byte) []byte {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package {{ .Group }}

import xyz.block.ftl.*

data class HelloRequest(val name: String)
data class HelloResponse(val message: String)

@Export
@Verb
fun hello(req: String): String = "Hello, $req!"
fun hello(req: HelloRequest): HelloResponse = HelloResponse("Hello, ${req.name}!")

0 comments on commit 543c1f6

Please sign in to comment.