forked from roastedroot/proxy-wasm-java-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchCallOnTickTest.java
More file actions
46 lines (37 loc) · 1.58 KB
/
DispatchCallOnTickTest.java
File metadata and controls
46 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package io.roastedroot.proxywasm;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.dylibso.chicory.wasm.Parser;
import java.nio.file.Path;
import java.util.Map;
import org.junit.jupiter.api.Test;
/**
* Java port of https://github.com/proxy-wasm/proxy-wasm-go-sdk/blob/ab4161dcf9246a828008b539a82a1556cf0f2e24/examples/dispatch_call_on_tick/main_test.go
*/
public class DispatchCallOnTickTest {
static int tickMilliseconds = 100;
@Test
public void testOnTick() throws StartException {
var handler = new MockHandler();
var module =
Parser.parse(Path.of("./src/test/go-examples/dispatch_call_on_tick/main.wasm"));
ProxyWasm.Builder builder = ProxyWasm.builder().withPluginHandler(handler);
try (var host = builder.build(module)) {
assertEquals(tickMilliseconds, handler.getTickPeriodMilliseconds());
for (int i = 1; i <= 10; i++) {
host.tick(); // call OnTick
}
assertEquals(10, handler.getHttpCalls().size());
handler.getHttpCalls().entrySet().stream()
.forEach(
entry -> {
host.sendHttpCallResponse(
entry.getKey(), Map.of(), Map.of(), new byte[0]);
});
// Check Envoy logs.
for (int i = 1; i <= 10; i++) {
handler.assertLogsContain(
String.format("called %d for contextID=%d", i, host.contextId()));
}
}
}
}