Skip to content
Merged
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
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
<spotless-maven-plugin.version>2.44.3</spotless-maven-plugin.version>
<maven.compiler.version>3.14.0</maven.compiler.version>
<compiler-plugin.version>${maven.compiler.version}</compiler-plugin.version>
<surefire-plugin.version>3.5.2</surefire-plugin.version>
<failsafe-plugin.version>${surefire-plugin.version}</failsafe-plugin.version>

<!-- test time versions -->
<junit.version>5.12.0</junit.version>
Expand All @@ -50,6 +52,7 @@
<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.19.3</quarkus.platform.version>
<quarkus.version>3.21.0</quarkus.version>

</properties>

Expand Down Expand Up @@ -204,4 +207,20 @@
</plugins>
</pluginManagement>
</build>

<profiles>

<!-- Quarkus is only supported on JDK 17 and newer-->
<profile>
<id>jdk-17-and-newer</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<modules>
<module>proxy-wasm-jaxrs-quarkus</module>
<module>proxy-wasm-jaxrs-quarkus-example</module>
</modules>
</profile>
</profiles>

</project>
2 changes: 1 addition & 1 deletion proxy-wasm-java-host/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>proxy-wasm-java-host</artifactId>
<packaging>jar</packaging>

<name>proxy-wasm-java-host</name>

<dependencies>
Expand Down
45 changes: 45 additions & 0 deletions proxy-wasm-jaxrs-quarkus-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
.flattened-pom.xml

# Eclipse
.project
.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# Plugin directory
/.quarkus/cli/plugins/
# TLS Certificates
.certs/
122 changes: 122 additions & 0 deletions proxy-wasm-jaxrs-quarkus-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?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>

<parent>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-java-host-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>proxy-wasm-jaxrs-quarkus-example</artifactId>
<packaging>jar</packaging>
<name>proxy-wasm-jaxrs-quarkus-example</name>

<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>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-jaxrs-quarkus</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Let's test with Quarkus -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</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-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<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>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</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>
</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,52 @@
package io.roastedroot.proxywasm.jaxrs.example;

import com.dylibso.chicory.wasm.Parser;
import com.dylibso.chicory.wasm.WasmModule;
import io.roastedroot.proxywasm.StartException;
import io.roastedroot.proxywasm.jaxrs.WasmPlugin;
import io.roastedroot.proxywasm.jaxrs.WasmPluginFactory;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import java.nio.file.Path;
import java.util.Map;

@ApplicationScoped
public class App {

public static final String EXAMPLES_DIR = "../proxy-wasm-java-host/src/test";

public static WasmModule parseTestModule(String file) {
return Parser.parse(Path.of(EXAMPLES_DIR + file));
}

@Produces
public WasmPluginFactory foreignCallOnTickTest() throws StartException {
return () ->
WasmPlugin.builder()
.withName("foreignCallOnTickTest")
.withLogger(new MockLogger())
.withMinTickPeriodMilliseconds(
100) // plugin wants a tick every 1 ms, that's too often
.withForeignFunctions(Map.of("compress", data -> data))
.build(parseTestModule("/go-examples/foreign_call_on_tick/main.wasm"));
}

@Produces
public WasmPluginFactory notSharedHttpHeaders() throws StartException {
return () ->
WasmPlugin.builder()
.withName("notSharedHttpHeaders")
.withShared(false)
.withPluginConfig("{\"header\": \"x-wasm-header\", \"value\": \"foo\"}")
.build(parseTestModule("/go-examples/http_headers/main.wasm"));
}

@Produces
public WasmPluginFactory httpHeaders() throws StartException {
return () ->
WasmPlugin.builder()
.withName("httpHeaders")
.withPluginConfig("{\"header\": \"x-wasm-header\", \"value\": \"foo\"}")
.build(parseTestModule("/go-examples/http_headers/main.wasm"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.roastedroot.proxywasm.jaxrs.example;

import io.roastedroot.proxywasm.LogLevel;
import io.roastedroot.proxywasm.jaxrs.Logger;
import java.util.ArrayList;

public class MockLogger implements Logger {

static final boolean DEBUG = "true".equals(System.getenv("DEBUG"));

final ArrayList<String> loggedMessages = new ArrayList<>();

@Override
public synchronized void log(LogLevel level, String message) {
if (DEBUG) {
System.out.println(level + ": " + message);
}
loggedMessages.add(message);
}

@Override
public synchronized LogLevel getLogLevel() {
return LogLevel.TRACE;
}

public synchronized ArrayList<String> loggedMessages() {
return new ArrayList<>(loggedMessages);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.roastedroot.proxywasm.jaxrs;
package io.roastedroot.proxywasm.jaxrs.example;

import io.roastedroot.proxywasm.jaxrs.NamedWasmPlugin;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.roastedroot.proxywasm.jaxrs.example;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.quarkus.test.junit.QuarkusTest;
import io.roastedroot.proxywasm.StartException;
import io.roastedroot.proxywasm.jaxrs.WasmPlugin;
import io.roastedroot.proxywasm.jaxrs.WasmPluginFeature;
import jakarta.inject.Inject;
import java.util.ArrayList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class ForeignCallOnTickTest {

@Inject WasmPluginFeature feature;

@Test
public void testRequest() throws InterruptedException, StartException {
WasmPlugin plugin = feature.pool("foreignCallOnTickTest").borrow();
assertNotNull(plugin);

var logger = (MockLogger) plugin.logger();
Thread.sleep(200);
assertLogsContain(
logger.loggedMessages(),
String.format(
"foreign function (compress) called: %d, result: %s",
1, "68656c6c6f20776f726c6421"));
plugin.close(); // so that the ticks don't keep running in the background.
}

public synchronized void assertLogsContain(
ArrayList<String> loggedMessages, String... message) {
for (String m : message) {
Assertions.assertTrue(
loggedMessages.contains(m), "logged messages does not contain: " + m);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
package io.roastedroot.proxywasm.jaxrs;
package io.roastedroot.proxywasm.jaxrs.example;

import static io.restassured.RestAssured.given;
import static io.roastedroot.proxywasm.jaxrs.TestHelpers.parseTestModule;
import static org.hamcrest.Matchers.equalTo;

import io.quarkus.test.junit.QuarkusTest;
import io.roastedroot.proxywasm.StartException;
import jakarta.enterprise.inject.Produces;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class HttpHeadersNotSharedTest {

@Produces
public WasmPluginFactory create() throws StartException {
return () ->
WasmPlugin.builder()
.withName("notSharedHttpHeaders")
.withShared(false)
.withPluginConfig("{\"header\": \"x-wasm-header\", \"value\": \"foo\"}")
.build(parseTestModule("/go-examples/http_headers/main.wasm"));
}

@Test
public void testRequest() {

Expand All @@ -30,12 +18,14 @@ public void testRequest() {
.get("/test/notSharedHttpHeaders")
.then()
.statusCode(200)
.body(equalTo("hello world"))
.header("x-proxy-wasm-counter", "1");

given().when()
.get("/test/notSharedHttpHeaders")
.then()
.statusCode(200)
.body(equalTo("hello world"))
.header("x-proxy-wasm-counter", "1");
}
}
Loading
Loading