Skip to main content

rocketmq_remoting/protocol/header/
remove_broker_request_header.rs

1// Copyright 2026 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, Default, Serialize, Deserialize, RequestHeaderCodecV2)]
21#[serde(rename_all = "camelCase")]
22pub struct RemoveBrokerRequestHeader {
23    #[required]
24    pub broker_name: CheetahString,
25    #[required]
26    pub broker_cluster_name: CheetahString,
27    #[required]
28    pub broker_id: u64,
29}
30
31#[cfg(test)]
32mod tests {
33    use std::collections::HashMap;
34
35    use super::*;
36    use crate::protocol::command_custom_header::CommandCustomHeader;
37    use crate::protocol::command_custom_header::FromMap;
38
39    #[test]
40    fn remove_broker_request_header_serializes_broker_identity() {
41        let header = RemoveBrokerRequestHeader {
42            broker_name: CheetahString::from_static_str("broker-a"),
43            broker_cluster_name: CheetahString::from_static_str("DefaultCluster"),
44            broker_id: 1,
45        };
46
47        let map = header.to_map().expect("header should encode");
48        assert_eq!(
49            map.get(&CheetahString::from_static_str("brokerName")),
50            Some(&CheetahString::from_static_str("broker-a"))
51        );
52        assert_eq!(
53            map.get(&CheetahString::from_static_str("brokerClusterName")),
54            Some(&CheetahString::from_static_str("DefaultCluster"))
55        );
56        assert_eq!(
57            map.get(&CheetahString::from_static_str("brokerId")),
58            Some(&CheetahString::from_static_str("1"))
59        );
60    }
61
62    #[test]
63    fn remove_broker_request_header_deserializes_broker_identity() {
64        let mut map = HashMap::new();
65        map.insert(
66            CheetahString::from_static_str("brokerName"),
67            CheetahString::from_static_str("broker-a"),
68        );
69        map.insert(
70            CheetahString::from_static_str("brokerClusterName"),
71            CheetahString::from_static_str("DefaultCluster"),
72        );
73        map.insert(
74            CheetahString::from_static_str("brokerId"),
75            CheetahString::from_static_str("1"),
76        );
77
78        let header = <RemoveBrokerRequestHeader as FromMap>::from(&map).expect("header should decode");
79        assert_eq!(header.broker_name, CheetahString::from_static_str("broker-a"));
80        assert_eq!(
81            header.broker_cluster_name,
82            CheetahString::from_static_str("DefaultCluster")
83        );
84        assert_eq!(header.broker_id, 1);
85    }
86}