Skip to main content

Faulty

Struct Faulty 

Source
pub struct Faulty<T> { /* private fields */ }
Expand description

Wraps a [Transport] and fails a configurable number of upcoming sends.

This simulates an intermittent link so offline-first behavior can be proven rather than assumed: pair it with a store-and-forward drain and assert that every record still arrives, in order, once the link recovers.

§Examples

use pamoja_core::Transport;
use pamoja_loopback::{Faulty, LoopbackBroker, LoopbackTransport};

let broker = LoopbackBroker::new();
let mut node = Faulty::new(LoopbackTransport::new(broker), 1);
node.connect().await?;

// The first send fails, simulating a dropped link; the next succeeds.
assert!(node.send("t", b"x").await.is_err());
node.send("t", b"x").await?;

Implementations§

Source§

impl<T> Faulty<T>

Source

pub fn new(inner: T, failures: usize) -> Self

Wraps inner, failing its next failures sends before passing through.

§Arguments
  • inner - the transport to decorate.
  • failures - how many of the next send calls fail.
§Returns

A decorator that injects the requested failures, then delegates to inner.

Source

pub fn fail_next(&mut self, count: usize)

Arms the decorator to fail the next count sends.

§Arguments
  • count - the number of upcoming sends to fail, simulating another link outage.

Trait Implementations§

Source§

impl<T: Transport + Send> Transport for Faulty<T>

Source§

async fn connect(&mut self) -> Result<()>

Establishes the connection to the broker, peer, or bus. Read more
Source§

async fn send(&mut self, topic: &str, payload: &[u8]) -> Result<()>

Publishes a payload to a topic. Read more
Source§

async fn subscribe(&mut self, topic: &str) -> Result<()>

Subscribes to a topic so that matching payloads are routed to this transport. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Faulty<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Faulty<T>
where T: RefUnwindSafe,

§

impl<T> Send for Faulty<T>
where T: Send,

§

impl<T> Sync for Faulty<T>
where T: Sync,

§

impl<T> Unpin for Faulty<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Faulty<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Faulty<T>
where T: UnwindSafe,

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.

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