Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE #574] Add test case for MessageQueue #578

Closed
wants to merge 2 commits into from
Closed
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
43 changes: 43 additions & 0 deletions rocketmq-common/src/common/message/message_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,46 @@ impl PartialOrd for MessageQueue {
Some(self.cmp(other))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn message_queue_creation() {
let mq = MessageQueue::new("topic", "broker", 1);
assert_eq!(mq.topic, "topic");
assert_eq!(mq.broker_name, "broker");
assert_eq!(mq.queue_id, 1);
}

#[test]
fn message_queue_display() {
let mq = MessageQueue::new("topic", "broker", 1);
assert_eq!(
format!("{}", mq),
"MessageQueue { topic: topic, broker_name: broker, queue_id: 1 }"
);
}

#[test]
fn message_queue_ordering_same_topic_and_broker() {
let mq1 = MessageQueue::new("topic", "broker", 1);
let mq2 = MessageQueue::new("topic", "broker", 2);
assert!(mq1 < mq2);
}

#[test]
fn message_queue_ordering_different_topic() {
let mq1 = MessageQueue::new("topic1", "broker", 1);
let mq2 = MessageQueue::new("topic2", "broker", 1);
assert!(mq1 < mq2);
}

#[test]
fn message_queue_ordering_different_broker() {
let mq1 = MessageQueue::new("topic", "broker1", 1);
let mq2 = MessageQueue::new("topic", "broker2", 1);
assert!(mq1 < mq2);
}
}
Loading