1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-08-31 19:37:00 +02:00

migrate to actix 0.9

This commit is contained in:
Nikolay Kim
2019-12-15 23:46:03 +06:00
parent 9f64a38e17
commit 25a2546933
5 changed files with 237 additions and 247 deletions

View File

@@ -1,63 +1,42 @@
#[macro_use]
extern crate redis_async;
use actix::prelude::*;
use actix_redis::{Command, Error, RedisActor, RespValue};
use futures::Future;
#[test]
fn test_error_connect() -> std::io::Result<()> {
let sys = System::new("test");
#[actix_rt::test]
async fn test_error_connect() {
let addr = RedisActor::start("localhost:54000");
let _addr2 = addr.clone();
Arbiter::spawn_fn(move || {
addr.send(Command(resp_array!["GET", "test"])).then(|res| {
match res {
Ok(Err(Error::NotConnected)) => (),
_ => panic!("Should not happen {:?}", res),
}
System::current().stop();
Ok(())
})
});
sys.run()
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Err(Error::NotConnected)) => (),
_ => panic!("Should not happen {:?}", res),
}
}
#[test]
fn test_redis() -> std::io::Result<()> {
#[actix_rt::test]
async fn test_redis() {
env_logger::init();
let sys = System::new("test");
let addr = RedisActor::start("127.0.0.1:6379");
let _addr2 = addr.clone();
let res = addr
.send(Command(resp_array!["SET", "test", "value"]))
.await;
Arbiter::spawn_fn(move || {
let addr2 = addr.clone();
addr.send(Command(resp_array!["SET", "test", "value"]))
.then(move |res| match res {
match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
addr2.send(Command(resp_array!["GET", "test"])).then(|res| {
match res {
Ok(Ok(resp)) => {
println!("RESP: {:?}", resp);
assert_eq!(
resp,
RespValue::BulkString((&b"value"[..]).into())
);
}
_ => panic!("Should not happen {:?}", res),
}
System::current().stop();
Ok(())
})
println!("RESP: {:?}", resp);
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
}
_ => panic!("Should not happen {:?}", res),
})
});
sys.run()
}
}
_ => panic!("Should not happen {:?}", res),
}
}