Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions srad-client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ pub struct LastWill {
impl LastWill {
pub fn new_node(group: &str, node_id: &str, payload: Payload) -> Self {
let topic = NodeTopic::new(group, NodeMessageType::NDeath, node_id);
let (qos, retain) = topic.get_publish_quality_retain();
Self {
retain,
qos,
payload: payload.into(),
topic: topic.topic,
retain: true,
qos: QoS::AtLeastOnce,
payload: payload.into(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions srad-eon/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub trait MetricPublisher {
&self,
mut metrics: Vec<PublishMetric>,
) -> impl std::future::Future<Output = Result<(), PublishError>> + Send {
metrics.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
metrics.sort_by_key(|a| a.timestamp);
self.publish_metrics_unsorted(metrics)
}

Expand All @@ -76,7 +76,7 @@ pub trait MetricPublisher {
&self,
mut metrics: Vec<PublishMetric>,
) -> impl std::future::Future<Output = Result<(), PublishError>> + Send {
metrics.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
metrics.sort_by_key(|a| a.timestamp);
self.publish_metrics_unsorted(metrics)
}
}
Expand Down
31 changes: 28 additions & 3 deletions srad-types/src/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl NodeTopic {
NodeMessage::NBirth => (QoS::AtMostOnce, false),
NodeMessage::NData => (QoS::AtMostOnce, false),
NodeMessage::NCmd => (QoS::AtMostOnce, false),
NodeMessage::NDeath => (QoS::AtLeastOnce, false),
NodeMessage::NDeath => (QoS::AtMostOnce, false),
}
}
}
Expand All @@ -85,10 +85,10 @@ impl DeviceTopic {

pub fn get_publish_quality_retain(&self) -> (QoS, bool) {
match self.message_type {
DeviceMessage::DBirth => (QoS::AtLeastOnce, false),
DeviceMessage::DBirth => (QoS::AtMostOnce, false),
DeviceMessage::DData => (QoS::AtMostOnce, false),
DeviceMessage::DCmd => (QoS::AtMostOnce, false),
DeviceMessage::DDeath => (QoS::AtLeastOnce, false),
DeviceMessage::DDeath => (QoS::AtMostOnce, false),
}
}
}
Expand Down Expand Up @@ -188,3 +188,28 @@ pub fn state_host_topic(host_id: &str) -> String {
pub fn state_sub_topic() -> String {
state_host_topic("#")
}

#[cfg(test)]
mod tests {
use super::{DeviceMessage, DeviceTopic, NodeMessage, NodeTopic, QoS};

#[test]
fn node_messages_use_qos_zero_without_retain() {
for message_type in [NodeMessage::NBirth, NodeMessage::NData, NodeMessage::NDeath] {
let topic = NodeTopic::new("group", message_type, "node");
assert_eq!(topic.get_publish_quality_retain(), (QoS::AtMostOnce, false));
}
}

#[test]
fn device_messages_use_qos_zero_without_retain() {
for message_type in [
DeviceMessage::DBirth,
DeviceMessage::DData,
DeviceMessage::DDeath,
] {
let topic = DeviceTopic::new("group", message_type, "node", "device");
assert_eq!(topic.get_publish_quality_retain(), (QoS::AtMostOnce, false));
}
}
}
Loading