You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "Divyansh200102 (via GitHub)" <gi...@apache.org> on 2024/02/24 16:21:29 UTC
[PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Divyansh200102 opened a new pull request, #5451:
URL: https://github.com/apache/shenyu/pull/5451
<!-- Describe your PR here; e.g. Fixes #issueNo -->
<!--
Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
-->
Make sure that:
- [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
- [ ] You submit test cases (unit or integration tests) that back your changes.
- [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501789889
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Could you please take a look and tell why is this error coming @loongs-zhang .It says `Can't find wasm file` the wasm file is located in the resources folder so this error shouldn't be coming?The same error is coming for #5452
```Powershell
"C:\Program Files\Java\jdk-21\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar=55442:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-launcher\1.8.2\junit-platform-launcher-1.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit-rt.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\test-classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-
plugin\shenyu-plugin-wasm-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-sync-data-center\shenyu-sync-data-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-common\target\classes;C:\Users\Divyansh\.m2\repository\com\google\code\gson\gson\2.9.0\gson-2.9.0.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Divyansh\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm-tree\9.2\asm-tree-9.2.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm
\9.2\asm-9.2.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-core\1.0.38\reactor-netty-core-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler\4.1.100.Final\netty-handler-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-common\4.1.100.Final\netty-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver\4.1.100.Final\netty-resolver-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-buffer\4.1.100.Final\netty-buffer-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport\4.1.100.Final\netty-transport-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.100.Final\netty-transport-native-unix-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec\4.1.100.Final\netty-codec-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler-proxy\4.1.100.Final\netty-handler-proxy-4.1.100.Final.jar
;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-socks\4.1.100.Final\netty-codec-socks-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns\4.1.100.Final\netty-resolver-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-dns\4.1.100.Final\netty-codec-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-native-macos\4.1.100.Final\netty-resolver-dns-native-macos-4.1.100.Final-osx-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-classes-macos\4.1.100.Final\netty-resolver-dns-classes-macos-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-epoll\4.1.100.Final\netty-transport-native-epoll-4.1.100.Final-linux-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.100.Final\netty-transport-classes-epoll-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-http\1.0.38\reactor-netty-htt
p-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http\4.1.100.Final\netty-codec-http-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http2\4.1.100.Final\netty-codec-http2-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-webflux\5.3.30\spring-webflux-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-beans\5.3.30\spring-beans-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-web\5.3.30\spring-web-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-context\5.3.30\spring-context-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-aop\5.3.30\spring-aop-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-expression\5.3.30\spring-expression-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\Divyansh\.m2\repository\io\github\kawamuray\wasmtime\wasmtime-java\
0.19.0\wasmtime-java-0.19.0.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-base\target\classes;C:\Users\Divyansh\.m2\repository\com\github\ben-manes\caffeine\caffeine\2.9.3\caffeine-2.9.3.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-spi\target\classes;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-kotlin\2.13.5\jackson-module-kotlin-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-annota
tions\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-reflect\1.6.21\kotlin-reflect-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-test\5.3.30\spring-test-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-core\5.3.30\spring-core-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-jcl\5.3.30\spring-jcl-5.3.30.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-test\3.4.33\reactor-test-3.4.33.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-core\3.4.33\reactor-core-3.4.33.jar;C:\Users\Divyansh\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\rea
ctive-streams-1.0.4.jar;C:\Users\Divyansh\.m2\repository\org\assertj\assertj-core\3.22.0\assertj-core-3.22.0.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Divyansh\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Divyansh\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\Divyansh\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\Divyansh\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\Divyansh\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\slf4
j\jcl-over-slf4j\1.7.36\jcl-over-slf4j-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\vintage\junit-vintage-engine\5.8.2\junit-vintage-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;C:\Users\Divyansh\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users\Divyansh\.m2\repository\org\apig
uardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-library\2.2\hamcrest-library-2.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-junit-jupiter\3.5.15\mockito-junit-jupiter-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-core\3.5.15\mockito-core-3.5.15.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy\1.14.11\byte-buddy-1.14.11.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar;C:\Users\Divyansh\.m2\repository\org\objenesis\objenesis\3.1\objenesis-3.1.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-inline\3.5.15\mockito-inline-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\awaitility\awaitility\4.0.3\awaitility-4.0.3.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\Divyansh\.m2\repository\javax\xml\
bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\Divyansh\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
15:48:43.553 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_64623547734575093793.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1502181064
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/rust-wasm-data-handler-plugin/src/lib.rs:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#[link(wasm_import_module = "shenyu")]
+extern "C" {
+ fn get_args(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn put_result(arg_id: i64, addr: i64, len: i32) -> i32;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn doExecute(arg_id: i64) {
Review Comment:
For the rust part do i replace the name like you told in https://github.com/apache/shenyu/issues/5427#issuecomment-1951839935
Example
```diff
#[no_mangle]
-pub unsafe extern "C" fn doExecute(arg_id: i64) {
+pub unsafe extern "C" fn handlerPlugin(arg_id: i64) {
+pub unsafe extern "C" fn removePlugin(arg_id: i64) {
```
and then the rest of the code remains same?
```rust
let mut buf = [0u8; 32];
let buf_ptr = buf.as_mut_ptr() as i64;
eprintln!("rust side-> buffer base address: {}", buf_ptr);
// get arg from java
let len = get_args(arg_id, buf_ptr, buf.len() as i32);
let java_arg = std::str::from_utf8(&buf[..len as usize]).unwrap();
eprintln!("rust side-> recv:{}", java_arg);
// pass rust result to java
let rust_result = "rust result".as_bytes();
let result_ptr = rust_result.as_ptr() as i64;
_ = put_result(arg_id, result_ptr, rust_result.len() as i32);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1502164827
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/rust-wasm-data-handler-plugin/src/lib.rs:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#[link(wasm_import_module = "shenyu")]
+extern "C" {
+ fn get_args(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn put_result(arg_id: i64, addr: i64, len: i32) -> i32;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn doExecute(arg_id: i64) {
Review Comment:
`handlerPlugin`/`removePlugin`/`handlerSelector`/`removeSelector`/`handlerRule`/`removeRule`, where is the rust part ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501833925
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
The class is `shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java`, so the correct WASM file name is `org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang merged PR #5451:
URL: https://github.com/apache/shenyu/pull/5451
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501804382
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
@loongs-zhang Could you please take a look at the below error? It says `Can't find the wasm file`. It's coming when I made below change but since the wasm file is located in resources folder I am sure why this error is coming.The same error is coming in #5452
```diff
- static class TestWasmPluginDataHandler implements PluginDataHandler{
+ static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
```
```powershell
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
17:18:08.304 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_6411715251905330268411.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501834033
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
> shenyu-plugin/shenyu-plugin-wasm-base/src/test/resources/org.apache.shenyu.plugin.wasm.base.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
You lost the `handler `.
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
> shenyu-plugin/shenyu-plugin-wasm-base/src/test/resources/org.apache.shenyu.plugin.wasm.base.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
You lost the `handler`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501742177
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Need to inherit `AbstractWasmPluginDataHandler`, now this implementation will `not` load&call the WASM function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501804382
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
@loongs-zhang Could you please take a look at the below error? It says `Can't find the wasm file`. It's coming when I made below change but since the wasm file is located in resources folder I am not sure why this error is coming.The same error is coming in #5452
```diff
- static class TestWasmPluginDataHandler implements PluginDataHandler{
+ static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
```
```powershell
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
17:18:08.304 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_6411715251905330268411.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
Is the error coming because I did not include below part?
```java
@Override
protected Map<String, Func> initWasmCallJavaFunc(final Store<Void> store) {
Map<String, Func> funcMap = new HashMap<>();
funcMap.put("get_args", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
(argId, addr, len) -> {
String config = "hello from java " + argId;
LOG.info("java side->" + config);
assertEquals("hello from java 0", config);
ByteBuffer buf = super.getBuffer();
for (int i = 0; i < len && i < config.length(); i++) {
buf.put(addr.intValue() + i, (byte) config.charAt(i));
}
return Math.min(config.length(), len);
}));
funcMap.put("put_result", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
(argId, addr, len) -> {
ByteBuffer buf = super.getBuffer();
byte[] bytes = new byte[len];
for (int i = 0; i < len; i++) {
bytes[i] = buf.get(addr.intValue() + i);
}
String result = new String(bytes, StandardCharsets.UTF_8);
assertEquals("rust result", result);
RESULTS.put(argId, result);
LOG.info("java side->" + result);
return 0;
}));
return funcMap;
}
```
If so could you please tell how exactly do I use this in my code ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1966124389
Yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1966453806
> Yes
Does the `lib.rs` look fine now ? @loongs-zhang
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962970467
> In `AbstractWasmPluginDataHandler`, the `handlerPlugin`/`removePlugin`/`handlerSelector`/`removeSelector`/`handlerRule`/`removeRule` has been fully implemented, in my opinion, the `TestWasmPluginDataHandler` should like:
>
> ```java
> static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
>
> private static final Map<Long, String> RESULTS = new ConcurrentHashMap<>();
>
> @Override
> protected Map<String, Func> initWasmCallJavaFunc(final Store<Void> store) {
> Map<String, Func> funcMap = new HashMap<>();
> funcMap.put("get_args", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
> (argId, addr, len) -> {
> String config = "hello from java " + argId;
> LOG.info("java side->" + config);
> assertEquals("hello from java 0", config);
> ByteBuffer buf = super.getBuffer();
> for (int i = 0; i < len && i < config.length(); i++) {
> buf.put(addr.intValue() + i, (byte) config.charAt(i));
> }
> return Math.min(config.length(), len);
> }));
> funcMap.put("put_result", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
> (argId, addr, len) -> {
> ByteBuffer buf = super.getBuffer();
> byte[] bytes = new byte[len];
> for (int i = 0; i < len; i++) {
> bytes[i] = buf.get(addr.intValue() + i);
> }
> String result = new String(bytes, StandardCharsets.UTF_8);
> assertEquals("rust result", result);
> RESULTS.put(argId, result);
> LOG.info("java side->" + result);
> return 0;
> }));
> return funcMap;
> }
> }
> ```
Thanks a lot!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1966587970
LGTM, finally, it is necessary to update the WASM file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501789889
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Could you please take a look and tell why is this error coming @loongs-zhang .It says `Can't find wasm file` the wasm file is located in the resources folder so this error shouldn't be coming?
```Powershell
"C:\Program Files\Java\jdk-21\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar=55442:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-launcher\1.8.2\junit-platform-launcher-1.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit-rt.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\test-classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-
plugin\shenyu-plugin-wasm-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-sync-data-center\shenyu-sync-data-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-common\target\classes;C:\Users\Divyansh\.m2\repository\com\google\code\gson\gson\2.9.0\gson-2.9.0.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Divyansh\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm-tree\9.2\asm-tree-9.2.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm
\9.2\asm-9.2.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-core\1.0.38\reactor-netty-core-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler\4.1.100.Final\netty-handler-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-common\4.1.100.Final\netty-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver\4.1.100.Final\netty-resolver-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-buffer\4.1.100.Final\netty-buffer-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport\4.1.100.Final\netty-transport-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.100.Final\netty-transport-native-unix-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec\4.1.100.Final\netty-codec-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler-proxy\4.1.100.Final\netty-handler-proxy-4.1.100.Final.jar
;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-socks\4.1.100.Final\netty-codec-socks-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns\4.1.100.Final\netty-resolver-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-dns\4.1.100.Final\netty-codec-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-native-macos\4.1.100.Final\netty-resolver-dns-native-macos-4.1.100.Final-osx-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-classes-macos\4.1.100.Final\netty-resolver-dns-classes-macos-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-epoll\4.1.100.Final\netty-transport-native-epoll-4.1.100.Final-linux-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.100.Final\netty-transport-classes-epoll-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-http\1.0.38\reactor-netty-htt
p-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http\4.1.100.Final\netty-codec-http-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http2\4.1.100.Final\netty-codec-http2-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-webflux\5.3.30\spring-webflux-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-beans\5.3.30\spring-beans-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-web\5.3.30\spring-web-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-context\5.3.30\spring-context-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-aop\5.3.30\spring-aop-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-expression\5.3.30\spring-expression-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\Divyansh\.m2\repository\io\github\kawamuray\wasmtime\wasmtime-java\
0.19.0\wasmtime-java-0.19.0.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-base\target\classes;C:\Users\Divyansh\.m2\repository\com\github\ben-manes\caffeine\caffeine\2.9.3\caffeine-2.9.3.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-spi\target\classes;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-kotlin\2.13.5\jackson-module-kotlin-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-annota
tions\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-reflect\1.6.21\kotlin-reflect-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-test\5.3.30\spring-test-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-core\5.3.30\spring-core-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-jcl\5.3.30\spring-jcl-5.3.30.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-test\3.4.33\reactor-test-3.4.33.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-core\3.4.33\reactor-core-3.4.33.jar;C:\Users\Divyansh\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\rea
ctive-streams-1.0.4.jar;C:\Users\Divyansh\.m2\repository\org\assertj\assertj-core\3.22.0\assertj-core-3.22.0.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Divyansh\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Divyansh\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\Divyansh\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\Divyansh\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\Divyansh\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\slf4
j\jcl-over-slf4j\1.7.36\jcl-over-slf4j-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\vintage\junit-vintage-engine\5.8.2\junit-vintage-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;C:\Users\Divyansh\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users\Divyansh\.m2\repository\org\apig
uardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-library\2.2\hamcrest-library-2.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-junit-jupiter\3.5.15\mockito-junit-jupiter-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-core\3.5.15\mockito-core-3.5.15.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy\1.14.11\byte-buddy-1.14.11.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar;C:\Users\Divyansh\.m2\repository\org\objenesis\objenesis\3.1\objenesis-3.1.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-inline\3.5.15\mockito-inline-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\awaitility\awaitility\4.0.3\awaitility-4.0.3.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\Divyansh\.m2\repository\javax\xml\
bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\Divyansh\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
15:48:43.553 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_64623547734575093793.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501742177
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Need to inherit `AbstractWasmPluginDataHandler`, now this implementation will not load&call the WASM function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962877585
@loongs-zhang for the `lib.rs` of the plugin of `AbstractShenyuWasmPlugin` you said that for the ` doexecute` method replacing the name will do the job
```Shell
#[no_mangle]
pub unsafe extern "C" fn doExecute(arg_id: i64) {
let mut buf = [0u8; 32];
let buf_ptr = buf.as_mut_ptr() as i64;
eprintln!("rust side-> buffer base address: {}", buf_ptr);
// get arg from java
let len = get_args(arg_id, buf_ptr, buf.len() as i32);
let java_arg = std::str::from_utf8(&buf[..len as usize]).unwrap();
eprintln!("rust side-> recv:{}", java_arg);
// pass rust result to java
let rust_result = "rust result".as_bytes();
let result_ptr = rust_result.as_ptr() as i64;
_ = put_result(arg_id, result_ptr, rust_result.len() as i32);
}
```
so in this case of `AbstractWasmPluginDataHandler` where methods like `handlerPlugin`,`removePlugin`,`handlerSelector` needs to be called how do i write the rust wasm part here for `lib.rs` for the plugin of `AbstractWasmPluginDataHandler`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1963878559
> rust part incorrect
For the rust part do i replace the name like you told in https://github.com/apache/shenyu/issues/5427#issuecomment-1951839935
Example
```diff
#[no_mangle]
-pub unsafe extern "C" fn doExecute(arg_id: i64) {
+pub unsafe extern "C" fn handlerPlugin(arg_id: i64) {
+pub unsafe extern "C" fn removePlugin(arg_id: i64) {
```
and then the rest of the code remains same?
```rust
let mut buf = [0u8; 32];
let buf_ptr = buf.as_mut_ptr() as i64;
eprintln!("rust side-> buffer base address: {}", buf_ptr);
// get arg from java
let len = get_args(arg_id, buf_ptr, buf.len() as i32);
let java_arg = std::str::from_utf8(&buf[..len as usize]).unwrap();
eprintln!("rust side-> recv:{}", java_arg);
// pass rust result to java
let rust_result = "rust result".as_bytes();
let result_ptr = rust_result.as_ptr() as i64;
_ = put_result(arg_id, result_ptr, rust_result.len() as i32);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1966590157
> LGTM, finally, it is necessary to update the WASM file.
I understand also do i add a readme file as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962555166
@loongs-zhang Could you please take a look at this PR and suggest changes if needed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962970992
After the imporvements the tests seem to be running fine in on my system no idea why the checks are failing?

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501789889
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Could you please take a look and tell why is this error coming @loongs-zhang .It says `Can't find wasm file` the wasm file is located in the resources folder so this error shouldn't be coming?It started comnig when made this change
```diff
-static class TestWasmPluginDataHandler implements PluginDataHandler {
+static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
```
```Powershell
"C:\Program Files\Java\jdk-21\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar=55442:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-launcher\1.8.2\junit-platform-launcher-1.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit-rt.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\test-classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-
plugin\shenyu-plugin-wasm-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-sync-data-center\shenyu-sync-data-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-common\target\classes;C:\Users\Divyansh\.m2\repository\com\google\code\gson\gson\2.9.0\gson-2.9.0.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Divyansh\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm-tree\9.2\asm-tree-9.2.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm
\9.2\asm-9.2.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-core\1.0.38\reactor-netty-core-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler\4.1.100.Final\netty-handler-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-common\4.1.100.Final\netty-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver\4.1.100.Final\netty-resolver-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-buffer\4.1.100.Final\netty-buffer-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport\4.1.100.Final\netty-transport-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.100.Final\netty-transport-native-unix-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec\4.1.100.Final\netty-codec-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler-proxy\4.1.100.Final\netty-handler-proxy-4.1.100.Final.jar
;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-socks\4.1.100.Final\netty-codec-socks-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns\4.1.100.Final\netty-resolver-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-dns\4.1.100.Final\netty-codec-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-native-macos\4.1.100.Final\netty-resolver-dns-native-macos-4.1.100.Final-osx-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-classes-macos\4.1.100.Final\netty-resolver-dns-classes-macos-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-epoll\4.1.100.Final\netty-transport-native-epoll-4.1.100.Final-linux-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.100.Final\netty-transport-classes-epoll-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-http\1.0.38\reactor-netty-htt
p-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http\4.1.100.Final\netty-codec-http-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http2\4.1.100.Final\netty-codec-http2-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-webflux\5.3.30\spring-webflux-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-beans\5.3.30\spring-beans-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-web\5.3.30\spring-web-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-context\5.3.30\spring-context-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-aop\5.3.30\spring-aop-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-expression\5.3.30\spring-expression-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\Divyansh\.m2\repository\io\github\kawamuray\wasmtime\wasmtime-java\
0.19.0\wasmtime-java-0.19.0.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-base\target\classes;C:\Users\Divyansh\.m2\repository\com\github\ben-manes\caffeine\caffeine\2.9.3\caffeine-2.9.3.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-spi\target\classes;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-kotlin\2.13.5\jackson-module-kotlin-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-annota
tions\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-reflect\1.6.21\kotlin-reflect-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-test\5.3.30\spring-test-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-core\5.3.30\spring-core-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-jcl\5.3.30\spring-jcl-5.3.30.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-test\3.4.33\reactor-test-3.4.33.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-core\3.4.33\reactor-core-3.4.33.jar;C:\Users\Divyansh\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\rea
ctive-streams-1.0.4.jar;C:\Users\Divyansh\.m2\repository\org\assertj\assertj-core\3.22.0\assertj-core-3.22.0.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Divyansh\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Divyansh\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\Divyansh\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\Divyansh\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\Divyansh\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\slf4
j\jcl-over-slf4j\1.7.36\jcl-over-slf4j-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\vintage\junit-vintage-engine\5.8.2\junit-vintage-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;C:\Users\Divyansh\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users\Divyansh\.m2\repository\org\apig
uardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-library\2.2\hamcrest-library-2.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-junit-jupiter\3.5.15\mockito-junit-jupiter-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-core\3.5.15\mockito-core-3.5.15.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy\1.14.11\byte-buddy-1.14.11.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar;C:\Users\Divyansh\.m2\repository\org\objenesis\objenesis\3.1\objenesis-3.1.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-inline\3.5.15\mockito-inline-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\awaitility\awaitility\4.0.3\awaitility-4.0.3.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\Divyansh\.m2\repository\javax\xml\
bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\Divyansh\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
15:48:43.553 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_64623547734575093793.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
The same error is coming for #5452
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962418019
## [Codecov](https://app.codecov.io/gh/apache/shenyu/pull/5451?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 60.16%. Comparing base [(`05d3bf0`)](https://app.codecov.io/gh/apache/shenyu/commit/05d3bf0f09ee3db2893d961a0fb5a22e0d5a0f29?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`a1f5e23`)](https://app.codecov.io/gh/apache/shenyu/pull/5451?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #5451 +/- ##
============================================
- Coverage 60.98% 60.16% -0.83%
+ Complexity 8624 8551 -73
============================================
Files 1259 1263 +4
Lines 38432 38542 +110
Branches 3679 3676 -3
============================================
- Hits 23439 23190 -249
- Misses 12877 13284 +407
+ Partials 2116 2068 -48
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/shenyu/pull/5451?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501789889
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Could you please take a look and tell why is this error coming @loongs-zhang .It says `Can't find wasm file` the wasm file is located in the resources folder so this error shouldn't be coming?It started comnig when made this change
```diff
-static class TestWasmPluginDataHandler implements PluginDataHandler {
+static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
```
```Powershell
"C:\Program Files\Java\jdk-21\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar=55442:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-launcher\1.8.2\junit-platform-launcher-1.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit-rt.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\test-classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-
plugin\shenyu-plugin-wasm-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-sync-data-center\shenyu-sync-data-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-common\target\classes;C:\Users\Divyansh\.m2\repository\com\google\code\gson\gson\2.9.0\gson-2.9.0.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Divyansh\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm-tree\9.2\asm-tree-9.2.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm
\9.2\asm-9.2.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-core\1.0.38\reactor-netty-core-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler\4.1.100.Final\netty-handler-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-common\4.1.100.Final\netty-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver\4.1.100.Final\netty-resolver-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-buffer\4.1.100.Final\netty-buffer-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport\4.1.100.Final\netty-transport-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.100.Final\netty-transport-native-unix-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec\4.1.100.Final\netty-codec-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler-proxy\4.1.100.Final\netty-handler-proxy-4.1.100.Final.jar
;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-socks\4.1.100.Final\netty-codec-socks-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns\4.1.100.Final\netty-resolver-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-dns\4.1.100.Final\netty-codec-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-native-macos\4.1.100.Final\netty-resolver-dns-native-macos-4.1.100.Final-osx-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-classes-macos\4.1.100.Final\netty-resolver-dns-classes-macos-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-epoll\4.1.100.Final\netty-transport-native-epoll-4.1.100.Final-linux-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.100.Final\netty-transport-classes-epoll-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-http\1.0.38\reactor-netty-htt
p-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http\4.1.100.Final\netty-codec-http-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http2\4.1.100.Final\netty-codec-http2-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-webflux\5.3.30\spring-webflux-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-beans\5.3.30\spring-beans-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-web\5.3.30\spring-web-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-context\5.3.30\spring-context-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-aop\5.3.30\spring-aop-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-expression\5.3.30\spring-expression-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\Divyansh\.m2\repository\io\github\kawamuray\wasmtime\wasmtime-java\
0.19.0\wasmtime-java-0.19.0.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-base\target\classes;C:\Users\Divyansh\.m2\repository\com\github\ben-manes\caffeine\caffeine\2.9.3\caffeine-2.9.3.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-spi\target\classes;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-kotlin\2.13.5\jackson-module-kotlin-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-annota
tions\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-reflect\1.6.21\kotlin-reflect-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-test\5.3.30\spring-test-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-core\5.3.30\spring-core-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-jcl\5.3.30\spring-jcl-5.3.30.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-test\3.4.33\reactor-test-3.4.33.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-core\3.4.33\reactor-core-3.4.33.jar;C:\Users\Divyansh\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\rea
ctive-streams-1.0.4.jar;C:\Users\Divyansh\.m2\repository\org\assertj\assertj-core\3.22.0\assertj-core-3.22.0.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Divyansh\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Divyansh\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\Divyansh\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\Divyansh\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\Divyansh\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\slf4
j\jcl-over-slf4j\1.7.36\jcl-over-slf4j-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\vintage\junit-vintage-engine\5.8.2\junit-vintage-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;C:\Users\Divyansh\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users\Divyansh\.m2\repository\org\apig
uardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-library\2.2\hamcrest-library-2.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-junit-jupiter\3.5.15\mockito-junit-jupiter-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-core\3.5.15\mockito-core-3.5.15.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy\1.14.11\byte-buddy-1.14.11.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar;C:\Users\Divyansh\.m2\repository\org\objenesis\objenesis\3.1\objenesis-3.1.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-inline\3.5.15\mockito-inline-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\awaitility\awaitility\4.0.3\awaitility-4.0.3.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\Divyansh\.m2\repository\javax\xml\
bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\Divyansh\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
15:48:43.553 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_64623547734575093793.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
The same error is coming for #5452
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1501789889
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/java/org/apache/shenyu/plugin/wasm/base/handler/AbstractWasmPluginDataHandlerTest.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.wasm.base.handler;
+
+import org.apache.shenyu.common.dto.PluginData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AbstractWasmPluginDataHandlerTest {
+ private RuleData ruleData;
+
+ private PluginData pluginData;
+
+ private SelectorData selectorData;
+
+ private TestWasmPluginDataHandler testWasmPluginDataHandler;
+
+ private PluginDataHandler pluginDataHandler;
+
+ @BeforeEach
+ public void setUp() {
+ this.ruleData = mock(RuleData.class);
+ this.pluginData = mock(PluginData.class);
+ this.selectorData = mock(SelectorData.class);
+ this.testWasmPluginDataHandler = new TestWasmPluginDataHandler();
+ this.pluginDataHandler = () -> "SHENYU";
+ when(ruleData.getId()).thenReturn("SHENYU");
+ when(pluginData.getId()).thenReturn("SHENYU");
+ when(selectorData.getId()).thenReturn("SHENYU");
+ }
+
+ /**
+ * The handler plugin test.
+ */
+ @Test
+ public void handlerPluginTest() {
+ pluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ assertEquals(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()).getId(), pluginData.getId());
+ }
+
+ /**
+ * The remove plugin test.
+ */
+ @Test
+ public void removePluginTest() {
+ pluginDataHandler.removePlugin(pluginData);
+ testWasmPluginDataHandler.handlerPlugin(pluginData);
+ testWasmPluginDataHandler.removePlugin(pluginData);
+ assertNull(testWasmPluginDataHandler.getPluginDataMap().get(pluginData.getId()));
+ }
+
+ /**
+ * The handler selector test.
+ */
+ @Test
+ public void handlerSelectorTest() {
+ pluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ assertEquals(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()).getId(), selectorData.getId());
+ }
+
+ /**
+ * The remove selector test.
+ */
+ @Test
+ public void removeSelectorTest() {
+ pluginDataHandler.removeSelector(selectorData);
+ testWasmPluginDataHandler.handlerSelector(selectorData);
+ testWasmPluginDataHandler.removeSelector(selectorData);
+ assertNull(testWasmPluginDataHandler.getSelectorDataMap().get(selectorData.getId()));
+ }
+
+ /**
+ * The handler rule test.
+ */
+ @Test
+ public void handlerRuleTest() {
+ pluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ assertEquals(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()).getId(), ruleData.getId());
+ }
+
+ /**
+ * The remove rule test.
+ */
+ @Test
+ public void removeRuleTest() {
+ pluginDataHandler.removeRule(ruleData);
+ testWasmPluginDataHandler.handlerRule(ruleData);
+ testWasmPluginDataHandler.removeRule(ruleData);
+ assertNull(testWasmPluginDataHandler.getRuleDataMap().get(ruleData.getId()));
+ }
+
+ /**
+ * The plugin named test.
+ */
+ @Test
+ public void pluginNamedTest() {
+ assertEquals("SHENYU", pluginDataHandler.pluginNamed());
+ assertEquals("SHENYU_TEST", testWasmPluginDataHandler.pluginNamed());
+ }
+
+ static class TestWasmPluginDataHandler implements PluginDataHandler {
Review Comment:
Could you please take a look and tell why is this error coming @loongs-zhang .The wasm file is located in the resources folder so this error shouldn't be coming?
```Powershell
"C:\Program Files\Java\jdk-21\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar=55442:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-launcher\1.8.2\junit-platform-launcher-1.8.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.3.2\plugins\junit\lib\junit-rt.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\test-classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-wasm-base\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-
plugin\shenyu-plugin-wasm-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-sync-data-center\shenyu-sync-data-api\target\classes;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-common\target\classes;C:\Users\Divyansh\.m2\repository\com\google\code\gson\gson\2.9.0\gson-2.9.0.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.5\jackson-datatype-jdk8-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.5\jackson-datatype-jsr310-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.5\jackson-module-parameter-names-2.13.5.jar;C:\Users\Divyansh\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm-tree\9.2\asm-tree-9.2.jar;C:\Users\Divyansh\.m2\repository\org\ow2\asm\asm
\9.2\asm-9.2.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-core\1.0.38\reactor-netty-core-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler\4.1.100.Final\netty-handler-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-common\4.1.100.Final\netty-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver\4.1.100.Final\netty-resolver-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-buffer\4.1.100.Final\netty-buffer-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport\4.1.100.Final\netty-transport-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-unix-common\4.1.100.Final\netty-transport-native-unix-common-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec\4.1.100.Final\netty-codec-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-handler-proxy\4.1.100.Final\netty-handler-proxy-4.1.100.Final.jar
;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-socks\4.1.100.Final\netty-codec-socks-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns\4.1.100.Final\netty-resolver-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-dns\4.1.100.Final\netty-codec-dns-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-native-macos\4.1.100.Final\netty-resolver-dns-native-macos-4.1.100.Final-osx-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-resolver-dns-classes-macos\4.1.100.Final\netty-resolver-dns-classes-macos-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-native-epoll\4.1.100.Final\netty-transport-native-epoll-4.1.100.Final-linux-x86_64.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-transport-classes-epoll\4.1.100.Final\netty-transport-classes-epoll-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\netty\reactor-netty-http\1.0.38\reactor-netty-htt
p-1.0.38.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http\4.1.100.Final\netty-codec-http-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\io\netty\netty-codec-http2\4.1.100.Final\netty-codec-http2-4.1.100.Final.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-webflux\5.3.30\spring-webflux-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-beans\5.3.30\spring-beans-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-web\5.3.30\spring-web-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-context\5.3.30\spring-context-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-aop\5.3.30\spring-aop-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-expression\5.3.30\spring-expression-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\Divyansh\.m2\repository\io\github\kawamuray\wasmtime\wasmtime-java\
0.19.0\wasmtime-java-0.19.0.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-plugin\shenyu-plugin-base\target\classes;C:\Users\Divyansh\.m2\repository\com\github\ben-manes\caffeine\caffeine\2.9.3\caffeine-2.9.3.jar;C:\Users\Divyansh\Documents\GitHub\shenyu\shenyu-spi\target\classes;C:\Users\Divyansh\.m2\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-classic\1.2.12\logback-classic-1.2.12.jar;C:\Users\Divyansh\.m2\repository\ch\qos\logback\logback-core\1.2.12\logback-core-1.2.12.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\module\jackson-module-kotlin\2.13.5\jackson-module-kotlin-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.5\jackson-databind-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.5\jackson-core-2.13.5.jar;C:\Users\Divyansh\.m2\repository\com\fasterxml\jackson\core\jackson-annota
tions\2.13.5\jackson-annotations-2.13.5.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-reflect\1.6.21\kotlin-reflect-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.6.21\kotlin-stdlib-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.6.21\kotlin-stdlib-common-1.6.21.jar;C:\Users\Divyansh\.m2\repository\org\jetbrains\annotations\13.0\annotations-13.0.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-test\5.3.30\spring-test-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-core\5.3.30\spring-core-5.3.30.jar;C:\Users\Divyansh\.m2\repository\org\springframework\spring-jcl\5.3.30\spring-jcl-5.3.30.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-test\3.4.33\reactor-test-3.4.33.jar;C:\Users\Divyansh\.m2\repository\io\projectreactor\reactor-core\3.4.33\reactor-core-3.4.33.jar;C:\Users\Divyansh\.m2\repository\org\reactivestreams\reactive-streams\1.0.4\rea
ctive-streams-1.0.4.jar;C:\Users\Divyansh\.m2\repository\org\assertj\assertj-core\3.22.0\assertj-core-3.22.0.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\Divyansh\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Divyansh\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\Divyansh\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\Divyansh\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\Divyansh\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\Divyansh\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\slf4
j\jcl-over-slf4j\1.7.36\jcl-over-slf4j-1.7.36.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\vintage\junit-vintage-engine\5.8.2\junit-vintage-engine-5.8.2.jar;C:\Users\Divyansh\.m2\repository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;C:\Users\Divyansh\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users\Divyansh\.m2\repository\org\apig
uardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-library\2.2\hamcrest-library-2.2.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-junit-jupiter\3.5.15\mockito-junit-jupiter-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-core\3.5.15\mockito-core-3.5.15.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy\1.14.11\byte-buddy-1.14.11.jar;C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar;C:\Users\Divyansh\.m2\repository\org\objenesis\objenesis\3.1\objenesis-3.1.jar;C:\Users\Divyansh\.m2\repository\org\mockito\mockito-inline\3.5.15\mockito-inline-3.5.15.jar;C:\Users\Divyansh\.m2\repository\org\awaitility\awaitility\4.0.3\awaitility-4.0.3.jar;C:\Users\Divyansh\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\Divyansh\.m2\repository\javax\xml\
bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\Divyansh\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest
WARNING: A Java agent has been loaded dynamically (C:\Users\Divyansh\.m2\repository\net\bytebuddy\byte-buddy-agent\1.12.23\byte-buddy-agent-1.12.23.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
15:48:43.553 [main] DEBUG io.github.kawamuray.wasmtime.NativeLibraryLoader - Loading Wasmtime JNI library from C:\Users\Divyansh\AppData\Local\Temp\wasmtime_jni_0.19.0_windows_x86_64623547734575093793.dll
org.apache.shenyu.plugin.wasm.api.exception.ShenyuWasmInitException: Can't find wasm file: org.apache.shenyu.plugin.wasm.base.handler.AbstractWasmPluginDataHandlerTest$TestWasmPluginDataHandler.wasm
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "loongs-zhang (via GitHub)" <gi...@apache.org>.
loongs-zhang commented on PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#issuecomment-1962961971
In `AbstractWasmPluginDataHandler`, the `handlerPlugin`/`removePlugin`/`handlerSelector`/`removeSelector`/`handlerRule`/`removeRule`, in my opinion, the `TestWasmPluginDataHandler` should like:
```java
static class TestWasmPluginDataHandler extends AbstractWasmPluginDataHandler {
private static final Map<Long, String> RESULTS = new ConcurrentHashMap<>();
@Override
protected Map<String, Func> initWasmCallJavaFunc(final Store<Void> store) {
Map<String, Func> funcMap = new HashMap<>();
funcMap.put("get_args", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
(argId, addr, len) -> {
String config = "hello from java " + argId;
LOG.info("java side->" + config);
assertEquals("hello from java 0", config);
ByteBuffer buf = super.getBuffer();
for (int i = 0; i < len && i < config.length(); i++) {
buf.put(addr.intValue() + i, (byte) config.charAt(i));
}
return Math.min(config.length(), len);
}));
funcMap.put("put_result", WasmFunctions.wrap(store, WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
(argId, addr, len) -> {
ByteBuffer buf = super.getBuffer();
byte[] bytes = new byte[len];
for (int i = 0; i < len; i++) {
bytes[i] = buf.get(addr.intValue() + i);
}
String result = new String(bytes, StandardCharsets.UTF_8);
assertEquals("rust result", result);
RESULTS.put(argId, result);
LOG.info("java side->" + result);
return 0;
}));
return funcMap;
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1502698081
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/rust-wasm-data-handler-plugin/src/lib.rs:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#[link(wasm_import_module = "shenyu")]
+extern "C" {
+ fn get_args(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn put_result(arg_id: i64, addr: i64, len: i32) -> i32;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn doExecute(arg_id: i64) {
Review Comment:
> `handlerPlugin`/`removePlugin`/`handlerSelector`/`removeSelector`/`handlerRule`/`removeRule`, where is the rust part ?
I'll add it in the next commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add test case for `AbstractWasmPluginDataHandler` [shenyu]
Posted by "Divyansh200102 (via GitHub)" <gi...@apache.org>.
Divyansh200102 commented on code in PR #5451:
URL: https://github.com/apache/shenyu/pull/5451#discussion_r1502181064
##########
shenyu-plugin/shenyu-plugin-wasm-base/src/test/rust-wasm-data-handler-plugin/src/lib.rs:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#[link(wasm_import_module = "shenyu")]
+extern "C" {
+ fn get_args(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn put_result(arg_id: i64, addr: i64, len: i32) -> i32;
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn doExecute(arg_id: i64) {
Review Comment:
For the rust part do i replace the name like you told in https://github.com/apache/shenyu/issues/5427#issuecomment-1951839935
Example
```diff
#[no_mangle]
-pub unsafe extern "C" fn doExecute(arg_id: i64) {
+pub unsafe extern "C" fn handlerPlugin(arg_id: i64) {
+pub unsafe extern "C" fn removePlugin(arg_id: i64) {
```
and then the rest of the code remains same?
```rust
let mut buf = [0u8; 32];
let buf_ptr = buf.as_mut_ptr() as i64;
eprintln!("rust side-> buffer base address: {}", buf_ptr);
// get arg from java
let len = get_args(arg_id, buf_ptr, buf.len() as i32);
let java_arg = std::str::from_utf8(&buf[..len as usize]).unwrap();
eprintln!("rust side-> recv:{}", java_arg);
// pass rust result to java
let rust_result = "rust result".as_bytes();
let result_ptr = rust_result.as_ptr() as i64;
_ = put_result(arg_id, result_ptr, rust_result.len() as i32);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org