Skip to main content

MockReceivedCommand

Struct MockReceivedCommand 

Source
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: C

The wrapped command.

§context: Context

The 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>

Source

pub fn new(cmd: C) -> (Self, ReplyChecker<C::Reply>)

Creates a MockReceivedCommand paired with a ReplyChecker that receives the reply sent by reply.

Source

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 + Debug> Debug for MockReceivedCommand<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Command> Deref for MockReceivedCommand<C>

Source§

type Target = C

The resulting type after dereferencing.
Source§

fn deref(&self) -> &C

Dereferences the value.
Source§

impl<C: Command> ReceivedCommand<C> for MockReceivedCommand<C>

Source§

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.

Source§

async fn reply(&self, response: C::Reply) -> Result<(), Error>

Send response back to the requester and acknowledge the command.
Source§

fn context(&self) -> &Context

Returns the OpenTelemetry context propagated with this command.
Source§

fn command(&self) -> &C

Returns a reference to the received command data.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more