Skip to main content

rocketmq_protocol/protocol/header/
trigger_lite_dispatch_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::RequestHeaderCodec;
17use serde::Deserialize;
18use serde::Serialize;
19
20#[derive(Clone, Debug, Serialize, Deserialize, RequestHeaderCodec)]
21#[serde(rename_all = "camelCase")]
22#[header(
23    type_id = "rocketmq_protocol::protocol::header::trigger_lite_dispatch_request_header::TriggerLiteDispatchRequestHeader",
24    java_class = "org.apache.rocketmq.remoting.protocol.header.TriggerLiteDispatchRequestHeader"
25)]
26pub struct TriggerLiteDispatchRequestHeader {
27    #[header(required)]
28    pub group: CheetahString,
29    pub client_id: Option<CheetahString>,
30}
31
32#[cfg(test)]
33mod tests {
34    use std::collections::HashMap;
35
36    use super::*;
37    use crate::protocol::command_custom_header::CommandCustomHeader;
38    use crate::protocol::command_custom_header::FromMap;
39
40    #[test]
41    fn trigger_lite_dispatch_request_header_serializes_to_map() {
42        let header = TriggerLiteDispatchRequestHeader {
43            group: "group".into(),
44            client_id: Some("client".into()),
45        };
46
47        let map = header.to_map().unwrap();
48        assert_eq!(map.get(&CheetahString::from_static_str("group")).unwrap(), "group");
49        assert_eq!(map.get(&CheetahString::from_static_str("clientId")).unwrap(), "client");
50    }
51
52    #[test]
53    fn trigger_lite_dispatch_request_header_deserializes_from_map() {
54        let mut map = HashMap::new();
55        map.insert(
56            CheetahString::from_static_str("group"),
57            CheetahString::from_static_str("group"),
58        );
59        map.insert(
60            CheetahString::from_static_str("clientId"),
61            CheetahString::from_static_str("client"),
62        );
63
64        let header = <TriggerLiteDispatchRequestHeader as FromMap>::from(&map).unwrap();
65        assert_eq!(header.group, "group");
66        assert_eq!(header.client_id, Some("client".into()));
67    }
68}