Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use @SQLDatasource declaration #4729

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private FTLRunnerConnection getRunnerConnection() {
waitForRunner();
if (runnerDetails == null) {
log.error("Failed to get runner details");
return new MockRunnerConnection();
return this.runnerConnection = new MockRunnerConnection();
}
}
runnerConnection = new FTLRunnerConnectionImpl(runnerDetails.getProxyAddress(),
Expand Down
14 changes: 7 additions & 7 deletions jvm-runtime/jvm_hot_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
7 changes: 5 additions & 2 deletions jvm-runtime/plugin/common/jvmcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down
Loading