Skip to main content

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