rocketmq_common/common/
pop_ack_constants.rs1use crate::common::mix_all;
18use crate::common::topic::TopicValidator;
19
20pub struct PopAckConstants;
21
22impl PopAckConstants {
23 pub const ACK_TIME_INTERVAL: i64 = 1000;
24 pub const SECOND: i64 = 1000;
25 pub const LOCK_TIME: i64 = 5000;
26 pub const RETRY_QUEUE_NUM: i32 = 1;
27 pub const REVIVE_GROUP: &'static str = "CID_RMQ_SYS_REVIVE_GROUP";
28 pub const LOCAL_HOST: &'static str = "127.0.0.1";
29 pub const REVIVE_TOPIC: &'static str = "rmq_sys_REVIVE_LOG_";
30 pub const CK_TAG: &'static str = "ck";
31 pub const ACK_TAG: &'static str = "ack";
32 pub const BATCH_ACK_TAG: &'static str = "bAck";
33 pub const SPLIT: &'static str = "@";
34
35 #[inline]
36 pub fn build_cluster_revive_topic(cluster_name: &str) -> String {
37 format!("{}{}", PopAckConstants::REVIVE_TOPIC, cluster_name)
38 }
39
40 #[inline]
41 pub fn is_start_with_revive_prefix(topic_name: &str) -> bool {
42 topic_name.starts_with(PopAckConstants::REVIVE_TOPIC)
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn build_cluster_revive_topic_appends_correctly() {
52 let cluster_name = "test_cluster";
53 let expected = "rmq_sys_REVIVE_LOG_test_cluster";
54 assert_eq!(
55 PopAckConstants::build_cluster_revive_topic(cluster_name),
56 expected
57 );
58 }
59
60 #[test]
61 fn is_start_with_revive_prefix_returns_true_for_valid_prefix() {
62 let topic_name = "rmq_sys_REVIVE_LOG_test";
63 assert!(PopAckConstants::is_start_with_revive_prefix(topic_name));
64 }
65
66 #[test]
67 fn is_start_with_revive_prefix_returns_false_for_invalid_prefix() {
68 let topic_name = "invalid_prefix_test";
69 assert!(!PopAckConstants::is_start_with_revive_prefix(topic_name));
70 }
71
72 #[test]
73 fn constants_have_correct_values() {
74 assert_eq!(PopAckConstants::ACK_TIME_INTERVAL, 1000);
75 assert_eq!(PopAckConstants::SECOND, 1000);
76 assert_eq!(PopAckConstants::LOCK_TIME, 5000);
77 assert_eq!(PopAckConstants::RETRY_QUEUE_NUM, 1);
78 assert_eq!(PopAckConstants::REVIVE_GROUP, "CID_RMQ_SYS_REVIVE_GROUP");
79 assert_eq!(PopAckConstants::LOCAL_HOST, "127.0.0.1");
80 assert_eq!(PopAckConstants::REVIVE_TOPIC, "rmq_sys_REVIVE_LOG_");
81 assert_eq!(PopAckConstants::CK_TAG, "ck");
82 assert_eq!(PopAckConstants::ACK_TAG, "ack");
83 assert_eq!(PopAckConstants::BATCH_ACK_TAG, "bAck");
84 assert_eq!(PopAckConstants::SPLIT, "@");
85 }
86}