Skip to main content

rocketmq_protocol/protocol/header/
exchange_ha_info_response_header.rs

1use cheetah_string::CheetahString;
2use rocketmq_macros::RequestHeaderCodec;
3// Copyright 2023 The RocketMQ Rust Authors
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// 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.
16use serde::Deserialize;
17use serde::Serialize;
18
19#[derive(Debug, Clone, Serialize, Deserialize, RequestHeaderCodec)]
20#[serde(rename_all = "camelCase")]
21#[header(
22    type_id = "rocketmq_protocol::protocol::header::exchange_ha_info_response_header::ExchangeHaInfoResponseHeader",
23    java_class = "org.apache.rocketmq.remoting.protocol.header.ExchangeHAInfoResponseHeader"
24)]
25pub struct ExchangeHaInfoResponseHeader {
26    pub master_ha_address: Option<CheetahString>,
27    pub master_flush_offset: Option<i64>,
28    pub master_address: Option<CheetahString>,
29}
30
31#[cfg(test)]
32mod tests {
33    use cheetah_string::CheetahString;
34
35    use super::*;
36
37    fn create_cheetah_string(value: &str) -> Option<CheetahString> {
38        Some(CheetahString::from(value))
39    }
40
41    #[test]
42    fn serialize_with_all_fields_set() {
43        let header = ExchangeHaInfoResponseHeader {
44            master_ha_address: create_cheetah_string("127.0.0.1:10911"),
45            master_flush_offset: Some(1024),
46            master_address: create_cheetah_string("127.0.0.1"),
47        };
48
49        let serialized = serde_json::to_string(&header).unwrap();
50        assert!(serialized.contains("\"masterHaAddress\":\"127.0.0.1:10911\""));
51        assert!(serialized.contains("\"masterFlushOffset\":1024"));
52        assert!(serialized.contains("\"masterAddress\":\"127.0.0.1\""));
53    }
54}