Skip to main content

TestClient

Trait TestClient 

Source
pub trait TestClient: Send {
    type Broker: Broker;
    type Subscriber: Subscriber;
    type Publisher: Publisher;
    type Error: StdError + Send + Sync + 'static;

    // Required methods
    fn start() -> impl Future<Output = Result<Self, Self::Error>> + Send
       where Self: Sized;
    fn broker(&self) -> &Self::Broker;
    fn publish(
        &self,
        name: &str,
        payload: &[u8],
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn subscribe(
        &self,
        name: &str,
    ) -> impl Future<Output = Result<Self::Subscriber, Self::Error>> + Send;
    fn publisher(
        &self,
    ) -> impl Future<Output = Result<Self::Publisher, Self::Error>> + Send;
    fn expect_published(
        &self,
        name: &str,
        count: usize,
        timeout: Duration,
    ) -> impl Future<Output = Result<Vec<RawMessage>, Self::Error>> + Send;
    fn shutdown(self) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
Expand description

A broker test transport that runs in process, reproducing Core routing without a server.

Implementations live in the same crate as the broker they stand in for, gated by the testing cargo feature. Test code adds the broker crate as a dev-dependency with that feature enabled and constructs a TestClient to drive the system under test.

Required Associated Types§

Source

type Broker: Broker

The broker type this test client emulates.

Source

type Subscriber: Subscriber

The subscriber type opened by subscribe.

Source

type Publisher: Publisher

The publisher type returned by publisher.

Source

type Error: StdError + Send + Sync + 'static

The error type returned by test-client operations.

Required Methods§

Source

fn start() -> impl Future<Output = Result<Self, Self::Error>> + Send
where Self: Sized,

Starts a fresh in-memory broker instance.

§Errors

Returns Self::Error when the test client cannot allocate the required resources.

Source

fn broker(&self) -> &Self::Broker

Returns a handle to the in-memory broker, suitable for registering with a RustStream.

Source

fn publish( &self, name: &str, payload: &[u8], ) -> impl Future<Output = Result<(), Self::Error>> + Send

Publishes a message to the in-memory broker as if from an external producer.

§Errors

Returns Self::Error when the in-memory broker rejects the publish.

Source

fn subscribe( &self, name: &str, ) -> impl Future<Output = Result<Self::Subscriber, Self::Error>> + Send

Opens a subscription against the in-memory broker. Used by integration tests that need to verify handler-level behaviour like ack / nack and redelivery.

§Errors

Returns Self::Error when the in-memory broker cannot register a new subscription.

Source

fn publisher( &self, ) -> impl Future<Output = Result<Self::Publisher, Self::Error>> + Send

Returns a publisher bound to the in-memory broker. Useful when the test needs to set headers or publish in a tight loop without allocating per-call closures.

§Errors

Returns Self::Error when the in-memory broker cannot produce a publisher.

Source

fn expect_published( &self, name: &str, count: usize, timeout: Duration, ) -> impl Future<Output = Result<Vec<RawMessage>, Self::Error>> + Send

Waits until at least count messages have been published to name, returning all observed messages. Fails after timeout.

§Errors

Returns Self::Error when fewer than count messages arrive before the timeout, or when the in-memory broker is shut down before the assertion completes.

Source

fn shutdown(self) -> impl Future<Output = Result<(), Self::Error>> + Send

Cleanly shuts down the in-memory broker.

§Errors

Returns Self::Error when background tasks fail to terminate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§