pub struct MockReceivedCommand<C: Command> {
cmd: C,
context: Context,
reply_tx: Arc<Mutex<Option<Sender<Vec<u8>>>>>,
}Expand description
Mock implementation of ReceivedCommand for unit tests.
Captures the reply sent by ReceivedCommand::reply in a channel
so tests can assert on what the handler replied without a running NATS
server. Obtain a (MockReceivedCommand<C>, ReplyChecker<C::Reply>) pair
from MockReceivedCommand::new.
Fields§
§cmd: CThe wrapped command.
context: ContextThe OTel context associated with this command.
reply_tx: Arc<Mutex<Option<Sender<Vec<u8>>>>>Channel the handler’s reply is sent on; taken on first reply.
Implementations§
Source§impl<C: Command> MockReceivedCommand<C>
impl<C: Command> MockReceivedCommand<C>
Sourcepub fn new(cmd: C) -> (Self, ReplyChecker<C::Reply>)
pub fn new(cmd: C) -> (Self, ReplyChecker<C::Reply>)
Creates a MockReceivedCommand paired with a ReplyChecker that
receives the reply sent by
reply.
Sourcepub(crate) fn with_reply_channel(cmd: C, reply_tx: Sender<Vec<u8>>) -> Self
pub(crate) fn with_reply_channel(cmd: C, reply_tx: Sender<Vec<u8>>) -> Self
Constructs a received command whose reply is delivered through
reply_tx.
Used by the in-memory bus to route a handler’s reply back to the
originating Requester::request call,
instead of capturing it in a ReplyChecker.
Trait Implementations§
Source§impl<C: Command> Deref for MockReceivedCommand<C>
impl<C: Command> Deref for MockReceivedCommand<C>
Source§impl<C: Command> ReceivedCommand<C> for MockReceivedCommand<C>
impl<C: Command> ReceivedCommand<C> for MockReceivedCommand<C>
Source§async fn ack(&self) -> Result<(), Error>
async fn ack(&self) -> Result<(), Error>
Does nothing: there is no broker here to acknowledge to. Tests that need to observe acknowledgement order need a double of their own.