Skip to content

Commit

Permalink
chore: add kotlin test (#2395)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Aug 16, 2024
1 parent ef3e3dd commit 9f40854
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 21 deletions.
32 changes: 24 additions & 8 deletions integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,33 @@ func GitInit() Action {
func CopyModule(module string) Action {
return Chain(
CopyDir(module, module),
func(t testing.TB, ic TestContext) {
root := filepath.Join(ic.workDir, module)
// TODO: Load the module configuration from the module itself and use that to determine the language-specific stuff.
if _, err := os.Stat(filepath.Join(root, "go.mod")); err == nil {
err := ftlexec.Command(ic, log.Debug, root, "go", "mod", "edit", "-replace", "github.com/TBD54566975/ftl="+ic.RootDir).RunBuffered(ic)
assert.NoError(t, err)
}
},
editGoMod(module),
)
}

// Copy a module from the testdata directory to the working directory
// This will always use the specified language regardless of the language under test
//
// Ensures that any language-specific local modifications are made correctly,
// such as Go module file replace directives for FTL.
func CopyModuleWithLanguage(module string, language string) Action {
return Chain(
CopyDir(filepath.Join("..", language, module), module),
editGoMod(module),
)
}

func editGoMod(module string) func(t testing.TB, ic TestContext) {
return func(t testing.TB, ic TestContext) {
root := filepath.Join(ic.workDir, module)
// TODO: Load the module configuration from the module itself and use that to determine the language-specific stuff.
if _, err := os.Stat(filepath.Join(root, "go.mod")); err == nil {
err := ftlexec.Command(ic, log.Debug, root, "go", "mod", "edit", "-replace", "github.com/TBD54566975/ftl="+ic.RootDir).RunBuffered(ic)
assert.NoError(t, err)
}
}
}

// SetEnv sets an environment variable for the duration of the test.
//
// Note that the FTL controller will already be running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private TypeName toKotlinTypeName(Type type, Map<DeclRef, Type> typeAliasMap) {
} else if (type.hasBool()) {
return new ClassName("kotlin", "Boolean");
} else if (type.hasFloat()) {
return new ClassName("kotlin", "Boolean");
return new ClassName("kotlin", "Double");
} else if (type.hasBytes()) {
return new ClassName("kotlin", "ByteArray");
} else if (type.hasAny()) {
Expand Down
14 changes: 7 additions & 7 deletions jvm-runtime/jvm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/alecthomas/repr"
)

func TestJavaToGoCall(t *testing.T) {
func TestJVMToGoCall(t *testing.T) {

exampleObject := TestObject{
IntField: 43,
Expand Down Expand Up @@ -105,11 +105,11 @@ func TestJavaToGoCall(t *testing.T) {
//tests = append(tests, PairedPrefixVerbTest("nilvalue", "optionalTestObjectOptionalFieldsVerb", ftl.None[any]())...)

in.Run(t,
in.WithLanguages("java"),
in.CopyModule("gomodule"),
in.CopyModule("javamodule"),
in.WithLanguages("kotlin", "java"),
in.CopyModuleWithLanguage("gomodule", "go"),
in.CopyModule("passthrough"),
in.Deploy("gomodule"),
in.Deploy("javamodule"),
in.Deploy("passthrough"),
in.SubTests(tests...),
)
}
Expand All @@ -121,8 +121,8 @@ func PairedTest(name string, testFunc func(module string) in.Action) []in.SubTes
Action: testFunc("gomodule"),
},
{
Name: name + "-Java",
Action: testFunc("javamodule"),
Name: name + "-jvm",
Action: testFunc("passthrough"),
},
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions jvm-runtime/testdata/java/javamodule/ftl.toml

This file was deleted.

2 changes: 2 additions & 0 deletions jvm-runtime/testdata/java/passthrough/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "passthrough"
language = "java"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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>xyz.block.ftl.examples</groupId>
<artifactId>javamodule</artifactId>
<artifactId>passthrough</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.block.ftl.java.test;
package xyz.block.ftl.test;

import java.time.ZonedDateTime;
import java.util.List;
Expand Down Expand Up @@ -35,7 +35,7 @@
import xyz.block.ftl.Export;
import xyz.block.ftl.Verb;

public class TestInvokeGo {
public class TestInvokeGoFromJava {

@Export
@Verb
Expand Down
2 changes: 2 additions & 0 deletions jvm-runtime/testdata/kotlin/passthrough/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "passthrough"
language = "kotlin"
36 changes: 36 additions & 0 deletions jvm-runtime/testdata/kotlin/passthrough/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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>xyz.block.ftl.examples</groupId>
<artifactId>passthrough</artifactId>
<version>1.0-SNAPSHOT</version>

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

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/ftl-clients</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package xyz.block.ftl.test

import ftl.gomodule.*
import xyz.block.ftl.Export
import xyz.block.ftl.Verb
import java.time.ZonedDateTime

@Export
@Verb
fun emptyVerb(emptyVerbClient: EmptyVerbClient) {
emptyVerbClient.call()
}

@Export
@Verb
fun sinkVerb(input: String, sinkVerbClient: SinkVerbClient) {
sinkVerbClient.call(input)
}

@Export
@Verb
fun sourceVerb(sourceVerbClient: SourceVerbClient): String {
return sourceVerbClient.call()
}

@Export
@Verb
fun errorEmptyVerb(client: ErrorEmptyVerbClient) {
client.call()
}

@Export
@Verb
fun intVerb(payload: Long, client: IntVerbClient): Long {
return client.call(payload)
}

@Export
@Verb
fun floatVerb(payload: Double, client: FloatVerbClient): Double {
return client.call(payload)
}

@Export
@Verb
fun stringVerb(payload: String, client: StringVerbClient): String {
return client.call(payload)
}

@Export
@Verb
fun bytesVerb(payload: ByteArray, client: BytesVerbClient): ByteArray {
return client.call(payload)
}

@Export
@Verb
fun boolVerb(payload: Boolean, client: BoolVerbClient): Boolean {
return client.call(payload)
}

@Export
@Verb
fun stringArrayVerb(payload: List<String>, client: StringArrayVerbClient): List<String> {
return client.call(payload)
}

@Export
@Verb
fun stringMapVerb(payload: Map<String, String>, client: StringMapVerbClient): Map<String, String> {
return client.call(payload)
}

@Export
@Verb
fun timeVerb(instant: ZonedDateTime, client: TimeVerbClient): ZonedDateTime {
return client.call(instant)
}

@Export
@Verb
fun testObjectVerb(payload: TestObject, client: TestObjectVerbClient): TestObject {
return client.call(payload)
}

@Export
@Verb
fun testObjectOptionalFieldsVerb(
payload: TestObjectOptionalFields,
client: TestObjectOptionalFieldsVerbClient
): TestObjectOptionalFields {
return client.call(payload)
}

// now the same again but with option return / input types
@Export
@Verb
fun optionalIntVerb(payload: Long, client: OptionalIntVerbClient): Long {
return client.call(payload)
}

@Export
@Verb
fun optionalFloatVerb(payload: Double, client: OptionalFloatVerbClient): Double {
return client.call(payload)
}

@Export
@Verb
fun optionalStringVerb(payload: String, client: OptionalStringVerbClient): String {
return client.call(payload)
}

@Export
@Verb
fun optionalBytesVerb(payload: ByteArray?, client: OptionalBytesVerbClient): ByteArray {
return client.call(payload!!)
}

@Export
@Verb
fun optionalBoolVerb(payload: Boolean, client: OptionalBoolVerbClient): Boolean {
return client.call(payload)
}

@Export
@Verb
fun optionalStringArrayVerb(payload: List<String>, client: OptionalStringArrayVerbClient): List<String> {
return client.call(payload)
}

@Export
@Verb
fun optionalStringMapVerb(payload: Map<String, String>, client: OptionalStringMapVerbClient): Map<String, String> {
return client.call(payload)
}

@Export
@Verb
fun optionalTimeVerb(instant: ZonedDateTime?, client: OptionalTimeVerbClient): ZonedDateTime {
return client.call(instant!!)
}

@Export
@Verb
fun optionalTestObjectVerb(payload: TestObject?, client: OptionalTestObjectVerbClient): TestObject {
return client.call(payload!!)
}

@Export
@Verb
fun optionalTestObjectOptionalFieldsVerb(
payload: TestObjectOptionalFields?,
client: OptionalTestObjectOptionalFieldsVerbClient
): TestObjectOptionalFields {
return client.call(payload!!)
}

0 comments on commit 9f40854

Please sign in to comment.