Skip to main content

rocketmq_remoting/protocol/header/controller/
get_replica_info_request_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 cheetah_string::CheetahString;
16use rocketmq_macros::RequestHeaderCodecV2;
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct GetReplicaInfoRequestHeader {
23    pub broker_name: CheetahString,
24}
25
26#[cfg(test)]
27mod tests {
28    use std::collections::HashMap;
29
30    use super::*;
31    use crate::protocol::command_custom_header::CommandCustomHeader;
32    use crate::protocol::command_custom_header::FromMap;
33
34    #[test]
35    fn get_replica_info_request_header_serializes_correctly() {
36        let header = GetReplicaInfoRequestHeader {
37            broker_name: CheetahString::from_static_str("test_broker"),
38        };
39        let map = header.to_map().unwrap();
40        assert_eq!(
41            map.get(&CheetahString::from_static_str("brokerName")).unwrap(),
42            "test_broker"
43        );
44    }
45
46    #[test]
47    fn get_replica_info_request_header_deserializes_correctly() {
48        let mut map = HashMap::new();
49        map.insert(
50            CheetahString::from_static_str("brokerName"),
51            CheetahString::from_static_str("test_broker"),
52        );
53
54        let header = <GetReplicaInfoRequestHeader as FromMap>::from(&map).unwrap();
55        assert_eq!(header.broker_name, "test_broker");
56    }
57
58    #[test]
59    fn get_replica_info_request_header_default() {
60        let header = GetReplicaInfoRequestHeader::default();
61        assert_eq!(header.broker_name, "");
62    }
63
64    #[test]
65    fn get_replica_info_request_header_clone() {
66        let header = GetReplicaInfoRequestHeader {
67            broker_name: CheetahString::from_static_str("test_broker"),
68        };
69        let cloned = header.clone();
70        assert_eq!(header.broker_name, cloned.broker_name);
71    }
72}