use cheetah_string::CheetahString;
use rocketmq_common::common::message::message_queue::MessageQueue;
pub trait AllocateMessageQueueStrategy: Send + Sync {
fn allocate(
&self,
consumer_group: &CheetahString,
current_cid: &CheetahString,
mq_all: &[MessageQueue],
cid_all: &[CheetahString],
) -> rocketmq_error::RocketMQResult<Vec<MessageQueue>>;
fn get_name(&self) -> &'static str;
}
pub type AbstractAllocateMessageQueueStrategy = dyn AllocateMessageQueueStrategy;
#[cfg(test)]
mod tests {
use super::*;
struct NoopStrategy;
impl AllocateMessageQueueStrategy for NoopStrategy {
fn allocate(
&self,
_consumer_group: &CheetahString,
_current_cid: &CheetahString,
_mq_all: &[MessageQueue],
_cid_all: &[CheetahString],
) -> rocketmq_error::RocketMQResult<Vec<MessageQueue>> {
Ok(Vec::new())
}
fn get_name(&self) -> &'static str {
"NOOP"
}
}
#[test]
fn abstract_allocate_message_queue_strategy_alias_accepts_real_strategy() {
let strategy = NoopStrategy;
let abstract_strategy: &AbstractAllocateMessageQueueStrategy = &strategy;
assert_eq!(abstract_strategy.get_name(), "NOOP");
}
}