-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2125 from fermyon/outbound-redis-runtime-test
Outbound Redis runtime test
- Loading branch information
Showing
28 changed files
with
272 additions
and
853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["sqlite", "helper", "outbound-mysql"] | ||
members = ["sqlite", "helper", "outbound-mysql", "outbound-redis"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "outbound-redis" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
helper = { path = "../helper" } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
use helper::{ensure_eq, ensure_matches, ensure_ok, ensure_some}; | ||
|
||
const REDIS_ADDRESS_ENV: &str = "REDIS_ADDRESS"; | ||
|
||
use bindings::fermyon::spin2_0_0::redis; | ||
|
||
helper::define_component!(Component); | ||
|
||
impl Component { | ||
fn main() -> Result<(), String> { | ||
let address = ensure_ok!(std::env::var(REDIS_ADDRESS_ENV)); | ||
let connection = ensure_ok!(redis::Connection::open(&address)); | ||
|
||
ensure_ok!(connection.set("spin-example-get-set", &b"Eureka!".to_vec())); | ||
|
||
let payload = ensure_some!(ensure_ok!(connection.get("spin-example-get-set"))); | ||
|
||
ensure_eq!(String::from_utf8_lossy(&payload), "Eureka!"); | ||
|
||
ensure_ok!(connection.set("spin-example-incr", &b"0".to_vec())); | ||
|
||
let int_value = ensure_ok!(connection.incr("spin-example-incr")); | ||
|
||
ensure_eq!(int_value, 1); | ||
|
||
let keys = vec!["spin-example-get-set".into(), "spin-example-incr".into()]; | ||
|
||
let del_keys = ensure_ok!(connection.del(&keys)); | ||
|
||
ensure_eq!(del_keys, 2); | ||
|
||
ensure_ok!(connection.execute( | ||
"set", | ||
&[ | ||
redis::RedisParameter::Binary(b"spin-example".to_vec()), | ||
redis::RedisParameter::Binary(b"Eureka!".to_vec()), | ||
], | ||
)); | ||
|
||
ensure_ok!(connection.execute( | ||
"append", | ||
&[ | ||
redis::RedisParameter::Binary(b"spin-example".to_vec()), | ||
redis::RedisParameter::Binary(b" I've got it!".to_vec()), | ||
], | ||
)); | ||
|
||
let values = ensure_ok!(connection.execute( | ||
"get", | ||
&[redis::RedisParameter::Binary(b"spin-example".to_vec())] | ||
)); | ||
|
||
ensure_matches!( | ||
values.as_slice(), | ||
&[redis::RedisResult::Binary(ref b)] if b == b"Eureka! I've got it!" | ||
); | ||
|
||
ensure_ok!(connection.execute( | ||
"set", | ||
&[ | ||
redis::RedisParameter::Binary(b"int-key".to_vec()), | ||
redis::RedisParameter::Int64(0), | ||
], | ||
)); | ||
|
||
let values = ensure_ok!(connection.execute( | ||
"incr", | ||
&[redis::RedisParameter::Binary(b"int-key".to_vec())] | ||
)); | ||
|
||
ensure_matches!(values.as_slice(), &[redis::RedisResult::Int64(1)]); | ||
|
||
let values = ensure_ok!( | ||
connection.execute("get", &[redis::RedisParameter::Binary(b"int-key".to_vec())]) | ||
); | ||
|
||
ensure_matches!( | ||
values.as_slice(), | ||
&[redis::RedisResult::Binary(ref b)] if b == b"1" | ||
); | ||
|
||
ensure_ok!(connection.execute("del", &[redis::RedisParameter::Binary(b"foo".to_vec())])); | ||
|
||
ensure_ok!(connection.execute( | ||
"sadd", | ||
&[ | ||
redis::RedisParameter::Binary(b"foo".to_vec()), | ||
redis::RedisParameter::Binary(b"bar".to_vec()), | ||
redis::RedisParameter::Binary(b"baz".to_vec()), | ||
], | ||
)); | ||
|
||
let values = ensure_ok!(connection.execute( | ||
"smembers", | ||
&[redis::RedisParameter::Binary(b"foo".to_vec())], | ||
)); | ||
|
||
ensure_matches!( | ||
values.as_slice(), | ||
&[ | ||
redis::RedisResult::Binary(ref bar), | ||
redis::RedisResult::Binary(ref baz) | ||
] if bar == b"bar" && baz == b"baz" | ||
); | ||
|
||
ensure_ok!(connection.execute( | ||
"srem", | ||
&[ | ||
redis::RedisParameter::Binary(b"foo".to_vec()), | ||
redis::RedisParameter::Binary(b"baz".to_vec()), | ||
], | ||
)); | ||
|
||
let values = ensure_ok!(connection.execute( | ||
"smembers", | ||
&[redis::RedisParameter::Binary(b"foo".to_vec())] | ||
)); | ||
|
||
ensure_matches!( | ||
values.as_slice(), | ||
&[redis::RedisResult::Binary(ref bar)] if bar == b"bar" | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.