@@ -53,57 +53,57 @@ public void shouldInvokeFunctionFromUrlWasmSource() {
53
53
assertThat (output ).isEqualTo ("{\" count\" :4,\" total\" :4,\" vowels\" :\" aeiouyAEIOUY\" }" );
54
54
}
55
55
56
- // @Test
57
- // public void shouldInvokeFunctionFromUrlWasmSourceHostFuncs() {
58
- // var url = "https://github.com/extism/plugins/releases/latest/download/count_vowels_kvstore.wasm";
59
- // var manifest = new Manifest(List.of(UrlWasmSource.fromUrl(url)));
60
- //
61
- // // Our application KV store
62
- // // Pretend this is redis or a database :)
63
- // var kvStore = new HashMap<String, byte[]>();
64
- //
65
- // ExtismFunction kvWrite = (plugin, params, returns, data) -> {
66
- // System.out.println("Hello from Java Host Function!");
67
- // var key = plugin.inputString(params[0]);
68
- // var value = plugin.inputBytes(params[1]);
69
- // System.out.println("Writing to key " + key);
70
- // kvStore.put(key, value);
71
- // };
72
- //
73
- // ExtismFunction kvRead = (plugin, params, returns, data) -> {
74
- // System.out.println("Hello from Java Host Function!");
75
- // var key = plugin.inputString(params[0]);
76
- // System.out.println("Reading from key " + key);
77
- // var value = kvStore.get(key);
78
- // if (value == null) {
79
- // // default to zeroed bytes
80
- // var zero = new byte[]{0,0,0,0};
81
- // plugin.returnBytes(returns[0], zero);
82
- // } else {
83
- // plugin.returnBytes(returns[0], value);
84
- // }
85
- // };
86
- //
87
- // HostFunction kvWriteHostFn = new HostFunction<>(
88
- // "kv_write",
89
- // new LibExtism.ExtismValType[]{LibExtism.ExtismValType.I64, LibExtism.ExtismValType.I64},
90
- // new LibExtism.ExtismValType[0],
91
- // kvWrite,
92
- // Optional.empty()
93
- // );
94
- //
95
- // HostFunction kvReadHostFn = new HostFunction<>(
96
- // "kv_read",
97
- // new LibExtism.ExtismValType[]{LibExtism.ExtismValType.I64},
98
- // new LibExtism.ExtismValType[]{LibExtism.ExtismValType.I64},
99
- // kvRead,
100
- // Optional.empty()
101
- // );
102
- //
103
- // HostFunction[] functions = {kvWriteHostFn, kvReadHostFn};
104
- // var plugin = new Plugin(manifest, false, functions);
105
- // var output = plugin.call("count_vowels", "Hello, World!");
106
- // }
56
+ @ Test
57
+ public void shouldInvokeFunctionFromUrlWasmSourceHostFuncs () {
58
+ var url = "https://github.com/extism/plugins/releases/latest/download/count_vowels_kvstore.wasm" ;
59
+ var manifest = new Manifest (List .of (UrlWasmSource .fromUrl (url )));
60
+
61
+ // Our application KV store
62
+ // Pretend this is redis or a database :)
63
+ var kvStore = new HashMap <String , byte []>();
64
+
65
+ ExtismFunction kvWrite = (plugin , params , returns , data ) -> {
66
+ System .out .println ("Hello from Java Host Function!" );
67
+ var key = plugin .inputString (params [0 ]);
68
+ var value = plugin .inputBytes (params [1 ]);
69
+ System .out .println ("Writing to key " + key );
70
+ kvStore .put (key , value );
71
+ };
72
+
73
+ ExtismFunction kvRead = (plugin , params , returns , data ) -> {
74
+ System .out .println ("Hello from Java Host Function!" );
75
+ var key = plugin .inputString (params [0 ]);
76
+ System .out .println ("Reading from key " + key );
77
+ var value = kvStore .get (key );
78
+ if (value == null ) {
79
+ // default to zeroed bytes
80
+ var zero = new byte []{0 ,0 ,0 ,0 };
81
+ plugin .returnBytes (returns [0 ], zero );
82
+ } else {
83
+ plugin .returnBytes (returns [0 ], value );
84
+ }
85
+ };
86
+
87
+ HostFunction kvWriteHostFn = new HostFunction <>(
88
+ "kv_write" ,
89
+ new LibExtism .ExtismValType []{LibExtism .ExtismValType .I64 , LibExtism .ExtismValType .I64 },
90
+ new LibExtism .ExtismValType [0 ],
91
+ kvWrite ,
92
+ Optional .empty ()
93
+ );
94
+
95
+ HostFunction kvReadHostFn = new HostFunction <>(
96
+ "kv_read" ,
97
+ new LibExtism .ExtismValType []{LibExtism .ExtismValType .I64 },
98
+ new LibExtism .ExtismValType []{LibExtism .ExtismValType .I64 },
99
+ kvRead ,
100
+ Optional .empty ()
101
+ );
102
+
103
+ HostFunction [] functions = {kvWriteHostFn , kvReadHostFn };
104
+ var plugin = new Plugin (manifest , false , functions );
105
+ var output = plugin .call ("count_vowels" , "Hello, World!" );
106
+ }
107
107
108
108
@ Test
109
109
public void shouldInvokeFunctionFromByteArrayWasmSource () {
0 commit comments