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>
impl<S: SendEventStore> SendFaultyStore<S>
pub fn new(inner: S) -> Self
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
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
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
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>
impl<S: Clone + SendEventStore> Clone for SendFaultyStore<S>
§impl<S: Debug + SendEventStore> Debug for SendFaultyStore<S>
impl<S: Debug + SendEventStore> Debug for SendFaultyStore<S>
§impl<S: SendEventStore + Sync> SendEventStore for SendFaultyStore<S>
impl<S: SendEventStore + Sync> SendEventStore for SendFaultyStore<S>
§type Error = FaultyStoreError<<S as SendEventStore>::Error>
type Error = FaultyStoreError<<S as SendEventStore>::Error>
§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<Self::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<Self::Error>>
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
Source§type Error = <TraitVariantBlanketType as SendEventStore>::Error
type Error = <TraitVariantBlanketType as SendEventStore>::Error
Source§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
Source§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
Source§async fn head(
&self,
) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
async fn head( &self, ) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
None when it
holds nothing. Read moreSource§async fn contains_event_id(
&self,
id: EventId,
) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
async fn contains_event_id( &self, id: EventId, ) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
id. Read more