rocketmq_remoting/protocol/header/
get_consumer_running_info_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 */
17use cheetah_string::CheetahString;
18use rocketmq_macros::RequestHeaderCodecV2;
19use serde::Deserialize;
20use serde::Serialize;
21
22use crate::rpc::rpc_request_header::RpcRequestHeader;
23
24#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
25#[serde(rename_all = "camelCase")]
26pub struct GetConsumerRunningInfoRequestHeader {
27    #[required]
28    pub consumer_group: CheetahString,
29
30    #[required]
31    pub client_id: CheetahString,
32
33    pub jstack_enable: bool,
34
35    #[serde(flatten)]
36    pub rpc_request_header: Option<RpcRequestHeader>,
37}
38
39#[cfg(test)]
40mod tests {
41    use cheetah_string::CheetahString;
42
43    use super::*;
44
45    #[test]
46    fn get_consumer_running_info_request_header_serializes_correctly() {
47        let header = GetConsumerRunningInfoRequestHeader {
48            consumer_group: CheetahString::from_static_str("test_group"),
49            client_id: CheetahString::from_static_str("client_id"),
50            jstack_enable: true,
51            rpc_request_header: None,
52        };
53        let serialized = serde_json::to_string(&header).unwrap();
54        let expected =
55            r#"{"consumerGroup":"test_group","clientId":"client_id","jstackEnable":true}"#;
56        assert_eq!(serialized, expected);
57    }
58
59    #[test]
60    fn get_consumer_running_info_request_header_deserializes_correctly() {
61        let data = r#"{"consumerGroup":"test_group","clientId":"client_id","jstackEnable":true}"#;
62        let header: GetConsumerRunningInfoRequestHeader = serde_json::from_str(data).unwrap();
63        assert_eq!(
64            header.consumer_group,
65            CheetahString::from_static_str("test_group")
66        );
67        assert_eq!(
68            header.client_id,
69            CheetahString::from_static_str("client_id")
70        );
71        assert!(header.jstack_enable);
72        assert!(header.rpc_request_header.is_some());
73    }
74
75    #[test]
76    fn get_consumer_running_info_request_header_handles_missing_optional_fields() {
77        let data = r#"{"consumerGroup":"test_group","clientId":"client_id","jstackEnable":false}"#;
78        let header: GetConsumerRunningInfoRequestHeader = serde_json::from_str(data).unwrap();
79        assert_eq!(
80            header.consumer_group,
81            CheetahString::from_static_str("test_group")
82        );
83        assert_eq!(
84            header.client_id,
85            CheetahString::from_static_str("client_id")
86        );
87        assert!(!header.jstack_enable);
88        assert!(header.rpc_request_header.is_some());
89    }
90
91    #[test]
92    fn get_consumer_running_info_request_header_handles_invalid_data() {
93        let data = r#"{"consumerGroup":12345,"clientId":"client_id"}"#;
94        let result: Result<GetConsumerRunningInfoRequestHeader, _> = serde_json::from_str(data);
95        assert!(result.is_err());
96    }
97}