Added the initial session service.

This commit is contained in:
2025-04-05 09:50:54 -04:00
parent 0eef663889
commit d8623f9691
3 changed files with 114 additions and 5 deletions

View File

@ -29,7 +29,7 @@ impl Message {
}
}
fn reply(&self, data: MsgType) -> Message {
pub fn reply(&self, data: MsgType) -> Message {
Self {
id: self.id.clone(),
class: data,
@ -52,6 +52,10 @@ impl Message {
pub fn get_data(&self) -> &HashMap<String, Field> {
&self.data
}
pub fn get_id(&self) -> Uuid {
self.id.clone()
}
}
impl From<Request> for Message {
@ -122,6 +126,12 @@ mod messages {
assert_eq!(result.get(one).unwrap().to_string(), one);
assert_eq!(result.get(&two).unwrap().to_string(), two);
}
#[test]
fn get_message_id() {
let msg = Message::new(MsgType::Session);
assert_eq!(msg.get_id(), msg.id);
}
}
#[derive(Clone)]
@ -149,9 +159,13 @@ impl Queue {
pub fn send(&self, msg: Message) {
let store = self.store.read().unwrap();
let senders = store.get(&msg.get_class()).unwrap();
for sender in senders.into_iter() {
sender.send(msg.clone()).unwrap();
match store.get(&msg.get_class()) {
Some(senders) => {
for sender in senders.into_iter() {
sender.send(msg.clone()).unwrap();
}
}
None => {}
}
}
}
@ -231,4 +245,10 @@ mod queues {
let msg = rx.recv().unwrap();
assert_eq!(msg.get_class(), &MsgType::Session);
}
#[test]
fn unassigned_message_should_not_panic() {
let queue = Queue::new();
queue.send(Message::new(MsgType::Session));
}
}