From 9037b2ea308180b2f54641ce310dfdca5f69fb01 Mon Sep 17 00:00:00 2001 From: mxsm Date: Sun, 8 Dec 2024 13:28:24 +0800 Subject: [PATCH] =?UTF-8?q?[ISSUE=20#1658]=F0=9F=9A=80Add=20AckResult=20st?= =?UTF-8?q?ruct=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rocketmq-client/src/consumer.rs | 1 + rocketmq-client/src/consumer/ack_result.rs | 95 ++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 rocketmq-client/src/consumer/ack_result.rs diff --git a/rocketmq-client/src/consumer.rs b/rocketmq-client/src/consumer.rs index 3dbe24c7..e8d52215 100644 --- a/rocketmq-client/src/consumer.rs +++ b/rocketmq-client/src/consumer.rs @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +pub(crate) mod ack_result; pub(crate) mod ack_status; pub mod allocate_message_queue_strategy; pub(crate) mod consumer_impl; diff --git a/rocketmq-client/src/consumer/ack_result.rs b/rocketmq-client/src/consumer/ack_result.rs new file mode 100644 index 00000000..02e2d30f --- /dev/null +++ b/rocketmq-client/src/consumer/ack_result.rs @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +use cheetah_string::CheetahString; + +use crate::consumer::ack_status::AckStatus; + +#[derive(Debug, Clone)] +pub struct AckResult { + pub(crate) status: AckStatus, + pub(crate) extra_info: CheetahString, + pub(crate) pop_time: i64, +} + +impl std::fmt::Display for AckResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "AckResult [AckStatus={:?}, extraInfo={}]", + self.status, self.extra_info + ) + } +} + +#[cfg(test)] +mod tests { + use cheetah_string::CheetahString; + + use super::*; + + #[test] + fn ack_result_display_format() { + let ack_result = AckResult { + status: AckStatus::Ok, + extra_info: CheetahString::from("extra info"), + pop_time: 123456789, + }; + assert_eq!( + format!("{}", ack_result), + "AckResult [AckStatus=Ok, extraInfo=extra info]" + ); + } + + #[test] + fn ack_result_display_format_with_not_exist_status() { + let ack_result = AckResult { + status: AckStatus::NotExist, + extra_info: CheetahString::from("extra info"), + pop_time: 987654321, + }; + assert_eq!( + format!("{}", ack_result), + "AckResult [AckStatus=NotExist, extraInfo=extra info]" + ); + } + + #[test] + fn ack_result_display_format_with_empty_extra_info() { + let ack_result = AckResult { + status: AckStatus::Ok, + extra_info: CheetahString::from(""), + pop_time: 123456789, + }; + assert_eq!( + format!("{}", ack_result), + "AckResult [AckStatus=Ok, extraInfo=]" + ); + } + + #[test] + fn ack_result_display_format_with_negative_pop_time() { + let ack_result = AckResult { + status: AckStatus::Ok, + extra_info: CheetahString::from("extra info"), + pop_time: -123456789, + }; + assert_eq!( + format!("{}", ack_result), + "AckResult [AckStatus=Ok, extraInfo=extra info]" + ); + } +}