Skip to main content

RecordingProjectionStore

Struct RecordingProjectionStore 

pub struct RecordingProjectionStore { /* private fields */ }
Available on crate feature memory only.
Expand description

A MemoryProjectionStore that logs every begin, commit, reset, rollback and bare drop of its write sets, in call order.

Read the log with calls, and the rows with get and snapshot. The log is never trimmed, which suits a test’s few dozen calls and nothing longer.

§Injected failures

failing_begin fails one begin, counted across every caller, and failing_commits_under fails every commit under one checkpoint id. A failed begin opens no write set and logs nothing. A failed commit is logged as BatchCall::Commit and discards its write set, as a store whose commit failed would.

§Handles

A clone is a second handle onto the same rows, checkpoints and log, as two connections onto one database are, with the same injected failures. That is what lets the projection suite run over it, unarmed (tests/recording_store_conformance.rs).

§Example

use happenstance_core::{Authority, ProjectionId, ProjectionStore};
use happenstance_core::SequencePosition;
use happenstance_testkit::{BatchCall, RecordingProjectionStore};
use happenstance_testkit::block_on;

let store = RecordingProjectionStore::new();
let id = ProjectionId::from_static("tally");
let at = SequencePosition::new(1).ok_or("one is a position")?;
block_on(async {
    let mut kept = store.begin().await?;
    kept.write("tally", 1);
    store.commit(kept, &id, at, Authority::Live).await?;
    let dropped = store.begin().await?;
    drop(dropped);
    Ok::<_, Box<dyn std::error::Error>>(())
})?;

assert_eq!(store.get("tally"), Some(1));
assert_eq!(
    store.calls(),
    [
        BatchCall::Begin(0),
        BatchCall::Commit(0),
        BatchCall::Begin(1),
        BatchCall::Dropped(1),
    ]
);

Implementations§

§

impl RecordingProjectionStore

pub fn new() -> Self

An empty store that fails nothing.

pub fn failing_begin(nth: usize) -> Self

An empty store whose zero-based nth begin fails, counted across every caller.

pub fn failing_commits_under(id: ProjectionId) -> Self

An empty store whose every commit under id fails.

pub fn calls(&self) -> Vec<BatchCall>

Every call so far, in order.

A copy rather than a borrow: the log sits behind a RefCell that every open write set appends to, and a borrow handed out here would make the next append panic.

pub fn get(&self, key: &str) -> Option<u64>

The committed value under key, if any.

pub fn snapshot(&self) -> BTreeMap<String, u64>

Every committed row.

pub fn is_empty(&self) -> bool

Whether no row is committed.

Trait Implementations§

§

impl Clone for RecordingProjectionStore

§

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 Debug for RecordingProjectionStore

§

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

Formats the value using the given formatter. Read more
§

impl Default for RecordingProjectionStore

§

fn default() -> Self

Returns the “default value” for a type. Read more
§

impl ProjectionProbe for RecordingProjectionStore

The probe the projection suite drives, delegated to the memory store beneath, so the suite can run over an unarmed recording store.

§

const READS_THROUGH_BATCH: bool = true

true, as for the memory store this wraps: it applies on write.

§

async fn probe_write( &self, batch: &mut RecordingBatch, key: &str, value: u64, ) -> Result<(), RecordingStoreError>

Writes one probe row into an open batch. Read more
§

async fn probe_delete_all( &self, batch: &mut RecordingBatch, ) -> Result<(), RecordingStoreError>

Queues deletion of every probe row into an open batch. Read more
§

async fn probe_read( &self, key: &str, ) -> Result<Option<u64>, RecordingStoreError>

Reads one probe row from the committed read model. Read more
§

async fn probe_read_through( &self, batch: &mut RecordingBatch, key: &str, ) -> Result<Option<u64>, RecordingStoreError>

Reads one probe row through an open batch, committed state included. Read more
§

impl ProjectionStore for RecordingProjectionStore

§

type Error = RecordingStoreError

How this adapter fails.
§

type Batch = RecordingBatch

The adapter’s write set. Read more
§

async fn begin(&self) -> Result<RecordingBatch, RecordingStoreError>

Opens a write set. Read more
§

async fn checkpoint( &self, id: &ProjectionId, ) -> Result<Checkpoint, RecordingStoreError>

How far this projection has been brought, and whether its rows are authoritative. Read more
§

async fn commit( &self, batch: RecordingBatch, id: &ProjectionId, position: SequencePosition, authority: Authority, ) -> Result<(), CommitError<RecordingStoreError>>

Applies batch and moves id’s checkpoint to position, as one unit. Read more
§

async fn reset( &self, batch: RecordingBatch, id: &ProjectionId, ) -> Result<(), ResetError<RecordingStoreError>>

Applies batch and returns id to Checkpoint::NeverRun, as one unit. Read more
§

async fn rollback( &self, batch: RecordingBatch, ) -> Result<(), RecordingStoreError>

Discards the batch without committing. Read more

Auto Trait Implementations§

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