Skip to content

Commit

Permalink
Compat with ZDaemon changes
Browse files Browse the repository at this point in the history
  • Loading branch information
petehayes102 committed Jun 6, 2016
1 parent 5ab74f0 commit ca70b5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tempdir = "0.3.*"

czmq = { git = "https://github.com/petehayes102/rust-czmq.git", branch = "dev" }
rustc-serialize = "0.3.*"
zdaemon = { git = "https://github.com/betweenlines/zdaemon.git" }
zdaemon = { git = "https://github.com/betweenlines/zdaemon.git", branch = "dev" }
zmq = { git = "https://github.com/petehayes102/rust-zmq.git", branch = "tmp-master" }

[lib]
Expand Down
26 changes: 15 additions & 11 deletions src/zap_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl ZapPublisher {
}

impl Endpoint for ZapPublisher {
fn get_socket(&self) -> &ZSock {
&self.proxy.publisher
fn get_sockets(&self) -> Vec<&ZSock> {
vec![&self.proxy.publisher]
}

fn recv(&mut self) -> StdResult<(), DError> {
fn recv(&mut self, _: &ZSock) -> StdResult<(), DError> {
let frame = try!(ZFrame::recv(&self.proxy.publisher));

let bytes = match try!(frame.data()) {
Expand Down Expand Up @@ -98,11 +98,11 @@ impl ZapSubscriber {
}

impl Endpoint for ZapSubscriber {
fn get_socket(&self) -> &ZSock {
&self.proxy.publisher
fn get_sockets(&self) -> Vec<&ZSock> {
vec![&self.proxy.publisher]
}

fn recv(&mut self) -> StdResult<(), DError> {
fn recv(&mut self, _: &ZSock) -> StdResult<(), DError> {
// Cache certificate
let proxy = Rc::get_mut(&mut self.proxy).unwrap();
let msg = try!(proxy.cache.borrow_mut().recv(&proxy.subscriber));
Expand Down Expand Up @@ -152,24 +152,26 @@ mod tests {
cache: Rc::new(RefCell::new(cache)),
});

let fake = ZSock::new(ZSockType::REP);

let mut publisher = ZapPublisher::new(proxy);

let client = ZSock::new_sub("inproc://zap_proxy_test_publisher", Some("user")).unwrap();
client.set_rcvtimeo(Some(500));

publisher.recv().unwrap();
publisher.recv(&fake).unwrap();
let msg = ZMsg::recv(&client).unwrap();
msg.popstr().unwrap().unwrap(); // Discard topic
assert_eq!(msg.popstr().unwrap().unwrap(), "ADD");
assert_eq!(msg.popstr().unwrap().unwrap(), user_pubkey);
assert_eq!(msg.popbytes().unwrap().unwrap(), user_meta);

client.set_unsubscribe("user");
publisher.recv().unwrap();
publisher.recv(&fake).unwrap();
assert!(client.recv_str().is_err());

client.set_subscribe("");
publisher.recv().unwrap();
publisher.recv(&fake).unwrap();
let msg = ZMsg::recv(&client).unwrap();
msg.popstr().unwrap().unwrap(); // Discard topic
assert_eq!(msg.popstr().unwrap().unwrap(), "ADD");
Expand Down Expand Up @@ -201,6 +203,8 @@ mod tests {
let xsub = ZSock::new_xsub("@inproc://zap_proxy_test_subscriber").unwrap();
xsub.set_rcvtimeo(Some(500));

let fake = ZSock::new(ZSockType::REP);

let proxy = Rc::new(ZapProxy {
publisher: xpub,
subscriber: xsub,
Expand All @@ -222,7 +226,7 @@ mod tests {
msg.addbytes(&user_meta).unwrap();
msg.send(&server).unwrap();

subscriber.recv().unwrap();
subscriber.recv(&fake).unwrap();
assert!(subscriber.proxy.cache.borrow().get(&user_pubkey).is_some());

let msg = ZMsg::new();
Expand All @@ -232,7 +236,7 @@ mod tests {
msg.addbytes(&host_meta).unwrap();
msg.send(&server).unwrap();

subscriber.recv().unwrap();
subscriber.recv(&fake).unwrap();
assert!(subscriber.proxy.cache.borrow().get(&host_pubkey).is_some());
}
}

0 comments on commit ca70b5b

Please sign in to comment.