Skip to content

Commit

Permalink
chore: Java PubSub Tests (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Aug 15, 2024
1 parent 1d9a0e3 commit 2b27ccc
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 4 deletions.
9 changes: 7 additions & 2 deletions backend/controller/pubsub/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestPubSub(t *testing.T) {
calls := 20
events := calls * 10
in.Run(t,
in.WithLanguages("java", "go"),
in.CopyModule("publisher"),
in.CopyModule("subscriber"),
in.Deploy("publisher"),
Expand All @@ -34,13 +35,14 @@ func TestPubSub(t *testing.T) {
WHERE
state = 'success'
AND origin = '%s'
`, dal.AsyncOriginPubSub{Subscription: schema.RefKey{Module: "subscriber", Name: "testSubscription"}}.String()),
`, dal.AsyncOriginPubSub{Subscription: schema.RefKey{Module: "subscriber", Name: "testTopicSubscription"}}.String()),
events),
)
}

func TestConsumptionDelay(t *testing.T) {
in.Run(t,
in.WithLanguages("go", "java"),
in.CopyModule("publisher"),
in.CopyModule("subscriber"),
in.Deploy("publisher"),
Expand Down Expand Up @@ -84,6 +86,7 @@ func TestConsumptionDelay(t *testing.T) {
func TestRetry(t *testing.T) {
retriesPerCall := 2
in.Run(t,
in.WithLanguages("java", "go"),
in.CopyModule("publisher"),
in.CopyModule("subscriber"),
in.Deploy("publisher"),
Expand Down Expand Up @@ -113,7 +116,8 @@ func TestRetry(t *testing.T) {
FROM async_calls
WHERE
state = 'error'
AND error = 'call to verb subscriber.catch failed: catching error'
AND error LIKE '%%subscriber.catch %%'
AND error LIKE '%%catching error%%'
AND catching = true
AND origin = '%s'
`, dal.AsyncOriginPubSub{Subscription: schema.RefKey{Module: "subscriber", Name: "doomedSubscription"}}.String()),
Expand All @@ -135,6 +139,7 @@ func TestRetry(t *testing.T) {
}

func TestExternalPublishRuntimeCheck(t *testing.T) {
// No java as there is no API for this
in.Run(t,
in.CopyModule("publisher"),
in.CopyModule("subscriber"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

var _ = ftl.Subscription(publisher.TestTopic, "testSubscription")
var _ = ftl.Subscription(publisher.TestTopic, "testTopicSubscription")

var catchCount atomic.Value[int]

//ftl:verb
//ftl:subscribe testSubscription
//ftl:subscribe testTopicSubscription
func Consume(ctx context.Context, req publisher.PubSubEvent) error {
ftl.LoggerFromContext(ctx).Infof("Subscriber is consuming %v", req.Time)
return nil
Expand Down
2 changes: 2 additions & 0 deletions backend/controller/pubsub/testdata/java/publisher/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "publisher"
language = "java"
141 changes: 141 additions & 0 deletions backend/controller/pubsub/testdata/java/publisher/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?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>publisher</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<ftl.version>1.0-SNAPSHOT</ftl.version>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<kotlin.version>2.0.0</kotlin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.12.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.2.5</surefire-plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>xyz.block</groupId>
<artifactId>ftl-java-runtime</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>kotlin-extensions</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>native-image-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.block.ftl.java.test.publisher;

import java.time.ZonedDateTime;

public class PubSubEvent {

private ZonedDateTime time;

public ZonedDateTime getTime() {
return time;
}

public PubSubEvent setTime(ZonedDateTime time) {
this.time = time;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package xyz.block.ftl.java.test.publisher;

import io.quarkus.logging.Log;
import xyz.block.ftl.Export;
import xyz.block.ftl.Topic;
import xyz.block.ftl.TopicDefinition;
import xyz.block.ftl.Verb;

public class Publisher {


@Export
@TopicDefinition("testTopic")
interface TestTopic extends Topic<PubSubEvent> {

}

@Export
@TopicDefinition("topic2")
interface Topic2 extends Topic<PubSubEvent> {

}

@Verb
void publishTen(TestTopic testTopic) throws Exception {
for (var i = 0; i < 10; ++i) {
var t = java.time.ZonedDateTime.now();
Log.infof("Publishing %s", t);
testTopic.publish(new PubSubEvent().setTime(t));
}
}

@Verb
void publishOne(TestTopic testTopic) throws Exception {
var t = java.time.ZonedDateTime.now();
Log.infof("Publishing %s", t);
testTopic.publish(new PubSubEvent().setTime(t));
}

@Verb
void publishOneToTopic2(Topic2 topic2) throws Exception {
var t = java.time.ZonedDateTime.now();
Log.infof("Publishing %s", t);
topic2.publish(new PubSubEvent().setTime(t));
}
}

2 changes: 2 additions & 0 deletions backend/controller/pubsub/testdata/java/subscriber/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "subscriber"
language = "java"
Loading

0 comments on commit 2b27ccc

Please sign in to comment.