Skip to content

Commit a0b4080

Browse files
authored
[ISSUE #1569]🔥Add GetConsumerRunningInfoRequestHeader struct🚀
1 parent c4aa8ff commit a0b4080

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

rocketmq-remoting/src/protocol/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod get_consume_stats_request_header;
2727
pub mod get_consumer_connection_list_request_header;
2828
pub mod get_consumer_listby_group_request_header;
2929
pub mod get_consumer_listby_group_response_header;
30+
pub mod get_consumer_running_info_request_header;
3031
pub mod get_earliest_msg_storetime_response_header;
3132
pub mod get_max_offset_request_header;
3233
pub mod get_max_offset_response_header;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
use cheetah_string::CheetahString;
18+
use rocketmq_macros::RequestHeaderCodec;
19+
use serde::Deserialize;
20+
use serde::Serialize;
21+
22+
use crate::rpc::rpc_request_header::RpcRequestHeader;
23+
24+
#[derive(Clone, Debug, Serialize, Deserialize, Default, RequestHeaderCodec)]
25+
#[serde(rename_all = "camelCase")]
26+
pub 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)]
40+
mod 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_none());
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_none());
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+
}

0 commit comments

Comments
 (0)