Skip to content

Commit

Permalink
feat: exemplar scaffolding and integration test 1/3 (#2763)
Browse files Browse the repository at this point in the history
Exemplar scaffolding with three modules that tests the features: config,
ingress, verb calls, pubsub, fsm, cron (java)
  • Loading branch information
safeer authored Sep 30, 2024
1 parent 7a3b45c commit dce6a18
Show file tree
Hide file tree
Showing 14 changed files with 743 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ testdata/**/go.work
testdata/**/go.work.sum
**/testdata/**/ftl-module-schema/
**/examples/**/ftl-module-schema/**/*
**/smoketest/**/ftl-module-schema/**/*
go-runtime/schema/testdata/test/test.go
.cache

# Leaving old _ftl for now to avoid old stuff getting checked in
**/testdata/**/_ftl
**/examples/**/_ftl
**/smoketest/**/_ftl
**/types.ftl.go
!go-runtime/ftl/ftltest/testdata/go/verbtypes/types.ftl.go
**/testdata/**/.ftl
**/examples/**/.ftl
**/smoketest/**/.ftl
/.ftl

buildengine/.gitignore
Expand Down
2 changes: 1 addition & 1 deletion ftl-project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "ftl"
module-dirs = ["examples/go"]
module-dirs = ["examples/go", "smoketest"]
ftl-min-version = ""
hermit = false
no-git = false
Expand Down
2 changes: 2 additions & 0 deletions smoketest/origin/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "origin"
language = "go"
48 changes: 48 additions & 0 deletions smoketest/origin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module ftl/origin

go 1.23.1

require github.com/TBD54566975/ftl v1.1.5

require (
connectrpc.com/connect v1.16.2 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.1 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/swaggest/jsonschema-go v0.3.72 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/TBD54566975/ftl => /Users/safeer/dev/ftl
152 changes: 152 additions & 0 deletions smoketest/origin/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions smoketest/origin/origin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package origin

import (
"context"
"time"

"ftl/builtin"

"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

var nonce = ftl.Config[string]("nonce")

//ftl:export
var AgentBroadcast = ftl.Topic[Agent]("agentBroadcast")

type Agent struct {
ID int `json:"id"`
Alias string `json:"alias"`
LicenseToKill bool `json:"license_to_kill"`
HiredAt time.Time `json:"hired_at"`
BriefedAt ftl.Option[time.Time] `json:"briefed_at"`
}

type PostAgentResponse struct {
ID int `json:"id"`
}

type PostAgentErrorResponse string

//ftl:ingress POST /http/agent
func PostAgent(ctx context.Context, req builtin.HttpRequest[Agent, ftl.Unit, ftl.Unit]) (builtin.HttpResponse[PostAgentResponse, PostAgentErrorResponse], error) {
agent := Agent{
ID: req.Body.ID,
Alias: req.Body.Alias,
LicenseToKill: req.Body.LicenseToKill,
HiredAt: req.Body.HiredAt,
}
AgentBroadcast.Publish(ctx, agent)
return builtin.HttpResponse[PostAgentResponse, PostAgentErrorResponse]{
Status: 201,
Body: ftl.Some(PostAgentResponse{ID: agent.ID}),
}, nil
}

// Exported verb

type GetNonceRequest struct{}
type GetNonceResponse struct{ Nonce string }

//ftl:verb export
func GetNonce(ctx context.Context, req GetNonceRequest) (GetNonceResponse, error) {
return GetNonceResponse{Nonce: nonce.Get(ctx)}, nil
}
2 changes: 2 additions & 0 deletions smoketest/pulse/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "pulse"
language = "java"
14 changes: 14 additions & 0 deletions smoketest/pulse/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ftl.com.example</groupId>
<artifactId>pulse</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>xyz.block.ftl</groupId>
<artifactId>ftl-build-parent-java</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

</project>
33 changes: 33 additions & 0 deletions smoketest/pulse/src/main/java/com/example/Pulse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example;

import java.io.FileWriter;
import java.io.IOException;

import ftl.origin.GetNonceClient;
import ftl.origin.GetNonceRequest;
import ftl.origin.GetNonceResponse;
import ftl.relay.GetLogFileClient;
import ftl.relay.GetLogFileRequest;
import ftl.relay.GetLogFileResponse;
import io.quarkus.logging.Log;
import xyz.block.ftl.Cron;

public class Pulse {

@Cron("1s")
public void cron10s(GetNonceClient getNonceClient, GetLogFileClient getLogFileClient) throws Exception {
GetNonceResponse nr = getNonceClient.call(new GetNonceRequest());
GetLogFileResponse lfr = getLogFileClient.call(new GetLogFileRequest());
Log.infof("Cron job triggered, nonce %s, log file: %s", nr.getNonce(), lfr.getPath());
appendLog(lfr.getPath(), "cron %s", nr.getNonce());
}

public static void appendLog(String path, String msg, Object... args) {
try (FileWriter writer = new FileWriter(path, true)) {
writer.write(String.format(msg + "%n", args));
} catch (IOException e) {
throw new RuntimeException("Error writing to log file", e);
}
}

}
2 changes: 2 additions & 0 deletions smoketest/relay/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "relay"
language = "go"
Loading

0 comments on commit dce6a18

Please sign in to comment.