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§
Sourcetype Subscriber: Subscriber
type Subscriber: Subscriber
The subscriber type opened by subscribe.
Required Methods§
Sourcefn start() -> impl Future<Output = Result<Self, Self::Error>> + Sendwhere
Self: Sized,
fn start() -> impl Future<Output = Result<Self, Self::Error>> + Sendwhere
Self: Sized,
Starts a fresh in-memory broker instance.
§Errors
Returns Self::Error when the test client cannot allocate the required resources.
Sourcefn broker(&self) -> &Self::Broker
fn broker(&self) -> &Self::Broker
Returns a handle to the in-memory broker, suitable for registering with a RustStream.
Sourcefn publish(
&self,
name: &str,
payload: &[u8],
) -> impl Future<Output = Result<(), Self::Error>> + Send
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.
Sourcefn subscribe(
&self,
name: &str,
) -> impl Future<Output = Result<Self::Subscriber, Self::Error>> + Send
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.
Sourcefn publisher(
&self,
) -> impl Future<Output = Result<Self::Publisher, Self::Error>> + Send
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.
Sourcefn expect_published(
&self,
name: &str,
count: usize,
timeout: Duration,
) -> impl Future<Output = Result<Vec<RawMessage>, Self::Error>> + Send
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".