From e65c812430f329f9e631791da2f3d743a38224b1 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 28 Feb 2025 14:22:54 +1100 Subject: [PATCH] fix: use @SQLDatasource declaration --- internal/integration/harness.go | 2 +- .../src/main/java/xyz/block/ftl/SQLDatasource.java | 6 +----- jvm-runtime/jvm_hot_reload_test.go | 14 +++++++------- jvm-runtime/plugin/common/jvmcommon.go | 7 +++++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/internal/integration/harness.go b/internal/integration/harness.go index a33f4e8839..5a16e66e10 100644 --- a/internal/integration/harness.go +++ b/internal/integration/harness.go @@ -43,6 +43,7 @@ import ( ) const dumpPath = "/tmp/ftl-kube-report" +const appDumpPatch = "/tmp/ftl-test-app" var RedPandaBrokers = []string{"127.0.0.1:19092"} @@ -363,7 +364,6 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) { kubeClient: optional.Ptr(kubeClient), } defer dumpKubePods(ctx, ic.kubeClient, ic.kubeNamespace) - if opts.startController || opts.kube { ic.Admin = admin ic.Schema = schema diff --git a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatasource.java b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatasource.java index 468dceb0f7..51f385ef83 100644 --- a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatasource.java +++ b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatasource.java @@ -1,19 +1,15 @@ package xyz.block.ftl; -import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; /** * Annotation to specify a SQL datasource. * - * This can be added anywhere in your application, but it is recommended to add it to a package-info.java file - * at the root of your package hierarchy. + * This can be added anywhere in your application. * */ @Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.PACKAGE, ElementType.TYPE }) public @interface SQLDatasource { /** * The name of the datasource. diff --git a/jvm-runtime/jvm_hot_reload_test.go b/jvm-runtime/jvm_hot_reload_test.go index cb0895e959..f9f4a18746 100644 --- a/jvm-runtime/jvm_hot_reload_test.go +++ b/jvm-runtime/jvm_hot_reload_test.go @@ -97,13 +97,13 @@ func TestLifecycleJVM(t *testing.T) { 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 { - return []byte(` -quarkus.datasource.testdb.db-kind=postgresql -quarkus.hibernate-orm.datasource=testdb -`) - }, "src/main/resources/application.properties"), + // Now let's add the DB + in.IfLanguage("java", in.EditFile("echo", func(content []byte) []byte { + return []byte(strings.ReplaceAll(string(content), "@Export", "@Export\n\n@SQLDatasource(name = \"testdb\", type = SQLDatabaseType.POSTGRESQL)")) + }, "src/main/java/ftl/echo/Echo.java")), + in.IfLanguage("kotlin", in.EditFile("echo", func(content []byte) []byte { + return []byte(strings.ReplaceAll(string(content), "@Export", "@Export\n\n@SQLDatasource(name = \"testdb\", type = SQLDatabaseType.POSTGRESQL)")) + }, "src/main/kotlin/ftl/echo/Echo.kt")), // Create a new datasource in.Exec("ftl", "postgres", "new", "echo.testdb"), diff --git a/jvm-runtime/plugin/common/jvmcommon.go b/jvm-runtime/plugin/common/jvmcommon.go index 21a8574001..c7a459fde5 100644 --- a/jvm-runtime/plugin/common/jvmcommon.go +++ b/jvm-runtime/plugin/common/jvmcommon.go @@ -447,9 +447,11 @@ func (s *Service) runQuarkusDev(parentCtx context.Context, stream *connect.Serve case bc := <-events: logger.Debugf("Build context updated") buildCtx = bc.buildCtx + result, err := client.Reload(ctx, connect.NewRequest(&hotreloadpb.ReloadRequest{Force: true})) if err != nil { - return fmt.Errorf("failed to invoke hot reload for build context update %w", err) + logger.Errorf(err, "failed to invoke hot reload for build context update") + continue } reloadEvents <- &buildResult{state: result.Msg.GetState(), forceReload: true, buildContextUpdated: true, failed: result.Msg.Failed} case <-fileEvents: @@ -475,7 +477,8 @@ func (s *Service) runQuarkusDev(parentCtx context.Context, stream *connect.Serve changed := false result, err := client.Reload(ctx, connect.NewRequest(&hotreloadpb.ReloadRequest{Force: true})) if err != nil { - return fmt.Errorf("failed to invoke hot reload for build context update %w", err) + logger.Errorf(err, "failed to invoke hot reload for file update") + continue } reloadEvents <- &buildResult{state: result.Msg.GetState(), forceReload: changed, failed: result.Msg.Failed} case <-ctx.Done():