Skip to main content

SendFaultyStore

Struct SendFaultyStore 

pub struct SendFaultyStore<S: SendEventStore> { /* private fields */ }
Expand description

Wraps a store so it can be made to fail on demand — the Send flavour.

FaultyStore’s sibling, and everything on that page applies here: the same arming, the same injected conflicting_position: None, the same wrong caller rejected. What this one adds is that the wrapper is Send + Sync and its read stream stays Send, so it can be held across an await inside a spawned task.

Rejects: a retry loop that branches on conflicting_position being Some.

§Examples

use happenstance_core::{Event, MemoryEventStore, SendEventStore};
use happenstance_testkit::{SendFaultyStore, block_on};

let store = SendFaultyStore::new(MemoryEventStore::new());
let seat = Event::new("Seated", &b"{}"[..])?;

let landed = block_on(SendEventStore::append(&store, &[seat], None));
assert!(landed.is_ok());

Implementations§

§

impl<S: SendEventStore> SendFaultyStore<S>

pub fn new(inner: S) -> Self

Wraps inner with nothing armed.

See FaultyStore::new; this flavour differs only in the bound.

pub fn violate_next(self, n: u32) -> Self

Fails the next n appends with a violated condition naming no conflicting event.

See FaultyStore::violate_next. n = 0 arms nothing and is legal.

pub fn fail_next_read(self, n: u32) -> Self

Fails the next n reads at their first polled item.

See FaultyStore::fail_next_read. n = 0 arms nothing and is legal.

pub fn contend_next(self, n: u32) -> Self

Refuses the next n appends as busy, through AppendError::Busy.

The inner store is never called for a refused append, so nothing is written, no position is allocated and the head does not move. Each refusal consumes one; when the count reaches zero the wrapper delegates again, which is what makes the refusal transient rather than a poisoned fixture. n = 0 arms nothing and is legal.

The refusal arrives as AppendError::Busy(FaultyStoreError::Contended), which keeps every promise ES-43 makes of that variant: nothing was written, and re-running the decision is safe. Read that variant’s page before using this: the channel is not an implementation detail, it is the entire instrument.

§Why this exists

Every in-process store in this workspace is always available: no reference store, and no wrapper before this one, can produce a busy append. So the question what does a rule do when a conformant store is merely contended? had no executable answer, and both remedies proposed for it were gated on an instrument that did not exist.

Rejects: a conformance rule that treats a transient refusal as non-conformance. Before ES-43, two of the concurrency family’s rules required every contender to commit, so one refusal reddened them. Every rule of that family now reads a Busy contender as neither a win nor a failure, over a structural floor of at least one commit. tests/contended_store_instruments.rs drives each rule against this arming and requires it to pass, and it drives the floor to fail against an arming that refuses everybody.

§It is exact under a race, not approximate

The count is consumed with a checked try_update, so when m racing callers meet an arming of n, exactly min(n, m) are refused however the threads interleave. Which callers lose is nondeterministic and how many is not, which is what lets a rule assert on the count without reading a clock — the thing CF-33 forbids.

§Examples
use happenstance_core::{AppendError, Event, MemoryEventStore, SendEventStore};
use happenstance_testkit::{FaultyStoreError, SendFaultyStore, block_on};

let store = SendFaultyStore::new(MemoryEventStore::new()).contend_next(1);
let seat = Event::new("Seated", &b"{}"[..])?;

// The first caller is refused as busy, not as a violation.
let refused = block_on(SendEventStore::append(&store, &[seat.clone()], None));
assert!(matches!(
    refused,
    Err(AppendError::Busy(FaultyStoreError::Contended))
));
// And a busy store is not a conflicted one.
let refused = refused.unwrap_err();
assert!(refused.is_busy());
assert!(!refused.is_condition_violated());

// The arming is spent, so the retry lands.
assert!(block_on(SendEventStore::append(&store, &[seat], None)).is_ok());

Trait Implementations§

§

impl<S: Clone + SendEventStore> Clone for SendFaultyStore<S>

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<S: Debug + SendEventStore> Debug for SendFaultyStore<S>

§

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

Formats the value using the given formatter. Read more
§

impl<S: SendEventStore + Sync> SendEventStore for SendFaultyStore<S>

§

type Error = FaultyStoreError<<S as SendEventStore>::Error>

How this adapter fails for its own reasons. Read more
§

fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send

Reads the events matching query, in the order options asks for. Read more
§

async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<Self::Error>>

Atomically appends events, rejecting the write if condition matches. Read more
§

async fn head(&self) -> Result<Option<SequencePosition>, Self::Error>

The highest position currently visible in the store, or None when it holds nothing. Read more
§

async fn contains_event_id(&self, id: EventId) -> Result<bool, Self::Error>

Whether this store holds an event with id. Read more

Auto Trait Implementations§

§

impl<S> Freeze for SendFaultyStore<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for SendFaultyStore<S>
where S: RefUnwindSafe,

§

impl<S> Send for SendFaultyStore<S>

§

impl<S> Sync for SendFaultyStore<S>
where S: Sync,

§

impl<S> Unpin for SendFaultyStore<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SendFaultyStore<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for SendFaultyStore<S>
where S: 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketType
where TraitVariantBlanketType: SendEventStore,

Source§

type Error = <TraitVariantBlanketType as SendEventStore>::Error

How this adapter fails for its own reasons. Read more
Source§

fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>

Reads the events matching query, in the order options asks for. Read more
Source§

async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>

Atomically appends events, rejecting the write if condition matches. Read more
Source§

async fn head( &self, ) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>

The highest position currently visible in the store, or None when it holds nothing. Read more
Source§

async fn contains_event_id( &self, id: EventId, ) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>

Whether this store holds an event with id. 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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V