-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for doing http calls from the plugin /w the jaxrs filter. #37
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/WellKnownHeaders.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.roastedroot.proxywasm; | ||
|
|
||
| /** | ||
| * Holds constants for the well-known header keys. | ||
| */ | ||
| public final class WellKnownHeaders { | ||
| private WellKnownHeaders() {} | ||
|
|
||
| public static final String SCHEME = ":scheme"; | ||
| public static final String AUTHORITY = ":authority"; | ||
| public static final String PATH = ":path"; | ||
| public static final String METHOD = ":method"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...-example/src/test/java/io/roastedroot/proxywasm/jaxrs/example/DispatchCallOnTickTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package io.roastedroot.proxywasm.jaxrs.example; | ||
|
|
||
| import static io.roastedroot.proxywasm.jaxrs.example.Helpers.assertLogsContain; | ||
| 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 org.junit.jupiter.api.Test; | ||
|
|
||
| @QuarkusTest | ||
| public class DispatchCallOnTickTest { | ||
|
|
||
| @Inject WasmPluginFeature feature; | ||
|
|
||
| @Test | ||
| public void test() throws InterruptedException, StartException { | ||
| WasmPlugin plugin = feature.pool("dispatchCallOnTickTest").borrow(); | ||
| assertNotNull(plugin); | ||
|
|
||
| var logger = (MockLogger) plugin.logger(); | ||
| Thread.sleep(300); | ||
|
|
||
| // for (var l : logger.loggedMessages()) { | ||
| // System.out.println(l); | ||
| // } | ||
| assertLogsContain( | ||
| logger.loggedMessages(), | ||
| "set tick period milliseconds: 100", | ||
| "called 1 for contextID=1", | ||
| "called 2 for contextID=1", | ||
| "response header for the dispatched call: Content-Type: text/plain;charset=UTF-8", | ||
| "response header for the dispatched call: echo-accept: */*", | ||
| "response header for the dispatched call: echo-content-length: 0", | ||
| "response header for the dispatched call: echo-Host: some_authority"); | ||
| plugin.close(); // so that the ticks don't keep running in the background. | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...m-jaxrs-quarkus-example/src/test/java/io/roastedroot/proxywasm/jaxrs/example/Helpers.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package io.roastedroot.proxywasm.jaxrs.example; | ||
|
|
||
| import java.util.ArrayList; | ||
| import org.junit.jupiter.api.Assertions; | ||
|
|
||
| public class Helpers { | ||
| private Helpers() {} | ||
|
|
||
| public static void assertLogsContain(ArrayList<String> loggedMessages, String... message) { | ||
| for (String m : message) { | ||
| Assertions.assertTrue( | ||
| loggedMessages.contains(m), "logged messages does not contain: " + m); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to trigger
plugin.close()instead waiting here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We basically have to wait for the tick events to get delivered to the plugin. . They are getting delivered every 100 ms (configured by the plugin). If we want avoid the wait, we would need to implement a new wasm module, avoiding the use of the async tick event to trigger the http call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for explaining, (the config is not in the diff).
A
Thread.sleepalways makes me a little anxious should we use Awaitility or something similar to avoid this becoming flaky over time?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.. I think I might just implement a better wasm plugin that allows us to test things better.