Skip to content

Commit 1b627e9

Browse files
authored
[ISSUE #1567]🔥Add DeleteSubscriptionGroupRequestHeader struct🍻
1 parent 392252b commit 1b627e9

2 files changed

Lines changed: 85 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
@@ -20,6 +20,7 @@ pub mod client_request_header;
2020
pub mod consume_message_directly_result_request_header;
2121
pub mod consumer_send_msg_back_request_header;
2222
pub mod create_topic_request_header;
23+
pub mod delete_subscription_group_request_header;
2324
pub mod delete_topic_request_header;
2425
pub mod end_transaction_request_header;
2526
pub mod get_all_topic_config_response_header;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 DeleteSubscriptionGroupRequestHeader {
27+
#[required]
28+
pub group_name: CheetahString,
29+
30+
pub clean_offset: bool,
31+
32+
#[serde(flatten)]
33+
pub rpc_request_header: Option<RpcRequestHeader>,
34+
}
35+
36+
#[cfg(test)]
37+
mod tests {
38+
use cheetah_string::CheetahString;
39+
40+
use super::*;
41+
42+
#[test]
43+
fn delete_subscription_group_request_header_serializes_correctly() {
44+
let header = DeleteSubscriptionGroupRequestHeader {
45+
group_name: CheetahString::from_static_str("test_group"),
46+
clean_offset: true,
47+
rpc_request_header: None,
48+
};
49+
let serialized = serde_json::to_string(&header).unwrap();
50+
let expected = r#"{"groupName":"test_group","cleanOffset":true}"#;
51+
assert_eq!(serialized, expected);
52+
}
53+
54+
#[test]
55+
fn delete_subscription_group_request_header_deserializes_correctly() {
56+
let data = r#"{"groupName":"test_group","cleanOffset":true}"#;
57+
let header: DeleteSubscriptionGroupRequestHeader = serde_json::from_str(data).unwrap();
58+
assert_eq!(
59+
header.group_name,
60+
CheetahString::from_static_str("test_group")
61+
);
62+
assert!(header.clean_offset);
63+
assert!(!header.rpc_request_header.is_none());
64+
}
65+
66+
#[test]
67+
fn delete_subscription_group_request_header_handles_missing_optional_fields() {
68+
let data = r#"{"groupName":"test_group","cleanOffset":false}"#;
69+
let header: DeleteSubscriptionGroupRequestHeader = serde_json::from_str(data).unwrap();
70+
assert_eq!(
71+
header.group_name,
72+
CheetahString::from_static_str("test_group")
73+
);
74+
assert!(!header.clean_offset);
75+
assert!(!header.rpc_request_header.is_none());
76+
}
77+
78+
#[test]
79+
fn delete_subscription_group_request_header_handles_invalid_data() {
80+
let data = r#"{"groupName":12345}"#;
81+
let result: Result<DeleteSubscriptionGroupRequestHeader, _> = serde_json::from_str(data);
82+
assert!(result.is_err());
83+
}
84+
}

0 commit comments

Comments
 (0)