2018-01-23 07:28:29 +01:00
|
|
|
extern crate actix;
|
|
|
|
extern crate actix_redis;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate redis_async;
|
|
|
|
extern crate futures;
|
|
|
|
extern crate env_logger;
|
|
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
|
use actix_redis::{RedisActor, Command, Error, RespValue};
|
|
|
|
use futures::Future;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_error_connect() {
|
|
|
|
let sys = System::new("test");
|
|
|
|
|
|
|
|
let addr = RedisActor::start("localhost:54000");
|
|
|
|
let _addr2 = addr.clone();
|
|
|
|
|
|
|
|
Arbiter::handle().spawn_fn(move || {
|
2018-02-16 01:53:05 +01:00
|
|
|
addr.send(Command(resp_array!["GET", "test"]))
|
2018-01-23 07:28:29 +01:00
|
|
|
.then(|res| {
|
|
|
|
match res {
|
|
|
|
Ok(Err(Error::NotConnected)) => (),
|
|
|
|
_ => panic!("Should not happen {:?}", res),
|
|
|
|
}
|
2018-02-16 01:53:05 +01:00
|
|
|
Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
2018-01-23 07:28:29 +01:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
sys.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_redis() {
|
|
|
|
env_logger::init();
|
|
|
|
let sys = System::new("test");
|
|
|
|
|
|
|
|
let addr = RedisActor::start("127.0.0.1:6379");
|
|
|
|
let _addr2 = addr.clone();
|
|
|
|
|
|
|
|
Arbiter::handle().spawn_fn(move || {
|
|
|
|
let addr2 = addr.clone();
|
2018-02-16 01:53:05 +01:00
|
|
|
addr.send(Command(resp_array!["SET", "test", "value"]))
|
2018-01-23 07:28:29 +01:00
|
|
|
.then(move |res| match res {
|
|
|
|
Ok(Ok(resp)) => {
|
|
|
|
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
|
2018-02-16 01:53:05 +01:00
|
|
|
addr2.send(Command(resp_array!["GET", "test"]))
|
2018-01-23 07:28:29 +01:00
|
|
|
.then(|res| {
|
|
|
|
match res {
|
|
|
|
Ok(Ok(resp)) => {
|
|
|
|
println!("RESP: {:?}", resp);
|
|
|
|
assert_eq!(
|
|
|
|
resp, RespValue::BulkString((&b"value"[..]).into()));
|
|
|
|
},
|
|
|
|
_ => panic!("Should not happen {:?}", res),
|
|
|
|
}
|
2018-02-16 01:53:05 +01:00
|
|
|
Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
2018-01-23 07:28:29 +01:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
},
|
|
|
|
_ => panic!("Should not happen {:?}", res),
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
sys.run();
|
|
|
|
}
|