rocketmq_remoting/protocol/header/namesrv/
brokerid_change_request_header.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use cheetah_string::CheetahString;
19use rocketmq_macros::RequestHeaderCodecV2;
20use serde::Deserialize;
21use serde::Serialize;
22
23#[derive(Debug, Clone, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
24pub struct NotifyMinBrokerIdChangeRequestHeader {
25    #[serde(rename = "minBrokerId")]
26    pub min_broker_id: Option<u64>,
27
28    #[serde(rename = "brokerName")]
29    pub broker_name: Option<CheetahString>,
30
31    #[serde(rename = "minBrokerAddr")]
32    pub min_broker_addr: Option<CheetahString>,
33
34    #[serde(rename = "offlineBrokerAddr")]
35    pub offline_broker_addr: Option<CheetahString>,
36
37    #[serde(rename = "haBrokerAddr")]
38    pub ha_broker_addr: Option<CheetahString>,
39}
40
41impl NotifyMinBrokerIdChangeRequestHeader {
42    pub fn new(
43        min_broker_id: Option<u64>,
44        broker_name: Option<CheetahString>,
45        min_broker_addr: Option<CheetahString>,
46        offline_broker_addr: Option<CheetahString>,
47        ha_broker_addr: Option<CheetahString>,
48    ) -> Self {
49        NotifyMinBrokerIdChangeRequestHeader {
50            min_broker_id,
51            broker_name,
52            min_broker_addr,
53            offline_broker_addr,
54            ha_broker_addr,
55        }
56    }
57}
58
59#[cfg(test)]
60mod tests {
61    use cheetah_string::CheetahString;
62
63    use super::*;
64
65    #[test]
66    fn new_creates_instance_with_all_fields() {
67        let header = NotifyMinBrokerIdChangeRequestHeader::new(
68            Some(1),
69            Some(CheetahString::from("broker1")),
70            Some(CheetahString::from("addr1")),
71            Some(CheetahString::from("addr2")),
72            Some(CheetahString::from("addr3")),
73        );
74        assert_eq!(header.min_broker_id, Some(1));
75        assert_eq!(header.broker_name.as_deref(), Some("broker1"));
76        assert_eq!(header.min_broker_addr.as_deref(), Some("addr1"));
77        assert_eq!(header.offline_broker_addr.as_deref(), Some("addr2"));
78        assert_eq!(header.ha_broker_addr.as_deref(), Some("addr3"));
79    }
80
81    #[test]
82    fn new_creates_instance_with_none_fields() {
83        let header = NotifyMinBrokerIdChangeRequestHeader::new(None, None, None, None, None);
84        assert_eq!(header.min_broker_id, None);
85        assert_eq!(header.broker_name, None);
86        assert_eq!(header.min_broker_addr, None);
87        assert_eq!(header.offline_broker_addr, None);
88        assert_eq!(header.ha_broker_addr, None);
89    }
90
91    #[test]
92    fn default_creates_instance_with_none_fields() {
93        let header: NotifyMinBrokerIdChangeRequestHeader = Default::default();
94        assert_eq!(header.min_broker_id, None);
95        assert_eq!(header.broker_name, None);
96        assert_eq!(header.min_broker_addr, None);
97        assert_eq!(header.offline_broker_addr, None);
98        assert_eq!(header.ha_broker_addr, None);
99    }
100}