pub struct KafkaTestBroker { /* private fields */ }Expand description
In-process broker for application tests: same descriptors, no Kafka cluster.
Clones share one router, so a publisher and a subscriber cloned from the same broker see
each other; separate new calls are fully isolated.
§Examples
use ruststream::{Broker, OutgoingMessage, Publisher, Subscriber};
use ruststream_rdkafka::testing::KafkaTestBroker;
let broker = KafkaTestBroker::new();
let mut subscriber = broker.subscribe("orders").await?;
broker.publisher().publish(OutgoingMessage::new("orders", b"{}")).await?;Implementations§
Source§impl KafkaTestBroker
impl KafkaTestBroker
Sourcepub async fn subscribe(
&self,
topic: impl Into<String>,
) -> Result<KafkaTestSubscriber, KafkaError>
pub async fn subscribe( &self, topic: impl Into<String>, ) -> Result<KafkaTestSubscriber, KafkaError>
Subscribes to topic (exact-name routing; no groups or partitions in-process).
§Errors
Returns KafkaError::InvalidOptions when topic is empty or a ^ pattern.
Sourcepub async fn subscribe_topics(
&self,
topics: &[String],
) -> Result<KafkaTestSubscriber, KafkaError>
pub async fn subscribe_topics( &self, topics: &[String], ) -> Result<KafkaTestSubscriber, KafkaError>
Subscribes to several topics as one subscription, mirroring
KafkaTopic::and_topic: every name routes exactly.
§Errors
Returns KafkaError::InvalidOptions when a name is empty, or when a name is a ^
pattern: the in-process broker routes by exact topic name, so pattern subscriptions
need a real cluster.
Sourcepub fn publisher(&self) -> KafkaTestPublisher
pub fn publisher(&self) -> KafkaTestPublisher
A publisher into this broker’s router.
Trait Implementations§
Source§impl Broker for KafkaTestBroker
impl Broker for KafkaTestBroker
Source§impl Clone for KafkaTestBroker
impl Clone for KafkaTestBroker
Source§fn clone(&self) -> KafkaTestBroker
fn clone(&self) -> KafkaTestBroker
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KafkaTestBroker
impl Debug for KafkaTestBroker
Source§impl Default for KafkaTestBroker
impl Default for KafkaTestBroker
Source§fn default() -> KafkaTestBroker
fn default() -> KafkaTestBroker
Returns the “default value” for a type. Read more
Source§impl DescribeServer for KafkaTestBroker
impl DescribeServer for KafkaTestBroker
Source§fn describe_server(&self) -> ServerSpec
fn describe_server(&self) -> ServerSpec
Returns the server coordinates for this broker.
Source§impl Subscribe for KafkaTestBroker
impl Subscribe for KafkaTestBroker
Source§type Subscriber = KafkaTestSubscriber
type Subscriber = KafkaTestSubscriber
The subscriber type opened by a by-name subscription.
Source§impl SubscriptionSource<KafkaTestBroker> for KafkaTopic
Available on crate feature testing only.
impl SubscriptionSource<KafkaTestBroker> for KafkaTopic
Available on crate feature
testing only.Source§type Subscriber = KafkaTestSubscriber
type Subscriber = KafkaTestSubscriber
The subscriber type this source opens.
Source§async fn subscribe(
self,
broker: &KafkaTestBroker,
) -> Result<Self::Subscriber, KafkaError>
async fn subscribe( self, broker: &KafkaTestBroker, ) -> Result<Self::Subscriber, KafkaError>
Source§impl TestableBroker for KafkaTestBroker
impl TestableBroker for KafkaTestBroker
Source§fn install_coordinator(&self, coordinator: Coordinator)
fn install_coordinator(&self, coordinator: Coordinator)
Installs the harness coordinator into this broker’s bus for a test run. Idempotent: a second
install on the same broker is ignored.
Source§fn inject(&self, message: OutgoingMessage<'_>)
fn inject(&self, message: OutgoingMessage<'_>)
Injects a message onto the bus as an external producer would, synchronously (no awaiting).
Routes through the broker’s normal fanout, so it is recorded and counted like any publish.
Source§fn published(&self, name: &str) -> Vec<RawMessage>
fn published(&self, name: &str) -> Vec<RawMessage>
Returns every message published to
name on this broker, in publish order. Backs the
harness’s published::<T>(name) assertions and expect_published.Auto Trait Implementations§
impl Freeze for KafkaTestBroker
impl RefUnwindSafe for KafkaTestBroker
impl Send for KafkaTestBroker
impl Sync for KafkaTestBroker
impl Unpin for KafkaTestBroker
impl UnsafeUnpin for KafkaTestBroker
impl UnwindSafe for KafkaTestBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more