Skip to main content

rocketmq_protocol/protocol/body/
pop_process_queue_info.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use serde::Deserialize;
16use serde::Serialize;
17
18#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
19#[serde(rename_all = "camelCase")]
20pub struct PopProcessQueueInfo {
21    wait_ack_count: i32,
22    droped: bool,
23    last_pop_timestamp: u64,
24}
25
26impl PopProcessQueueInfo {
27    pub fn new(wait_ack_count: i32, droped: bool, last_pop_timestamp: u64) -> Self {
28        Self {
29            wait_ack_count,
30            droped,
31            last_pop_timestamp,
32        }
33    }
34
35    pub fn wait_ack_count(&self) -> i32 {
36        self.wait_ack_count
37    }
38
39    pub fn set_wait_ack_count(&mut self, wait_ack_count: i32) {
40        self.wait_ack_count = wait_ack_count;
41    }
42
43    pub fn droped(&self) -> bool {
44        self.droped
45    }
46
47    pub fn set_droped(&mut self, droped: bool) {
48        self.droped = droped;
49    }
50
51    pub fn last_pop_timestamp(&self) -> u64 {
52        self.last_pop_timestamp
53    }
54
55    pub fn set_last_pop_timestamp(&mut self, last_pop_timestamp: u64) {
56        self.last_pop_timestamp = last_pop_timestamp;
57    }
58}
59
60impl std::fmt::Display for PopProcessQueueInfo {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        write!(
63            f,
64            "PopProcessQueueInfo [wait_ack_count: {}, droped: {}, last_pop_timestamp: {}]",
65            self.wait_ack_count, self.droped, self.last_pop_timestamp
66        )
67    }
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn pop_process_queue_accessors_and_setters() {
76        let mut queue = PopProcessQueueInfo::new(10, false, 123456789);
77        assert_eq!(queue.wait_ack_count(), 10);
78        assert!(!queue.droped());
79        assert_eq!(queue.last_pop_timestamp(), 123456789);
80
81        queue.set_wait_ack_count(20);
82        queue.set_droped(true);
83        queue.set_last_pop_timestamp(987654321);
84
85        assert_eq!(queue.wait_ack_count(), 20);
86        assert!(queue.droped());
87        assert_eq!(queue.last_pop_timestamp(), 987654321);
88    }
89
90    #[test]
91    fn pop_process_queue_display() {
92        let queue: PopProcessQueueInfo = PopProcessQueueInfo::new(10, false, 123456789);
93        let display = format!("{}", queue);
94        assert_eq!(
95            display,
96            "PopProcessQueueInfo [wait_ack_count: 10, droped: false, last_pop_timestamp: 123456789]"
97        );
98    }
99}