Skip to main content

rocketmq_remoting/protocol/header/
get_earliest_msg_storetime_response_header.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 rocketmq_macros::RequestHeaderCodecV2;
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Deserialize, Serialize, Default, RequestHeaderCodecV2)]
20pub struct GetEarliestMsgStoretimeResponseHeader {
21    #[required]
22    pub timestamp: i64,
23}
24
25#[cfg(test)]
26mod tests {
27    use serde_json;
28
29    use super::*;
30
31    #[test]
32    fn get_earliest_msg_storetime_response_header_display_format() {
33        let header = GetEarliestMsgStoretimeResponseHeader { timestamp: 1234567890 };
34        assert_eq!(
35            format!("{:?}", header),
36            "GetEarliestMsgStoretimeResponseHeader { timestamp: 1234567890 }"
37        );
38    }
39
40    #[test]
41    fn get_earliest_msg_storetime_response_header_serialize() {
42        let header = GetEarliestMsgStoretimeResponseHeader { timestamp: 1234567890 };
43        let serialized = serde_json::to_string(&header).unwrap();
44        assert_eq!(serialized, r#"{"timestamp":1234567890}"#);
45    }
46
47    #[test]
48    fn get_earliest_msg_storetime_response_header_deserialize() {
49        let json = r#"{"timestamp":1234567890}"#;
50        let header: GetEarliestMsgStoretimeResponseHeader = serde_json::from_str(json).unwrap();
51        assert_eq!(header.timestamp, 1234567890);
52    }
53
54    #[test]
55    fn get_earliest_msg_storetime_response_header_default() {
56        let header = GetEarliestMsgStoretimeResponseHeader::default();
57        assert_eq!(header.timestamp, 0);
58    }
59}