Struct RecordingProjectionStore
pub struct RecordingProjectionStore { /* private fields */ }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
impl RecordingProjectionStore
pub fn new() -> Self
pub fn new() -> Self
An empty store that fails nothing.
pub fn failing_begin(nth: usize) -> Self
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
pub fn failing_commits_under(id: ProjectionId) -> Self
An empty store whose every commit under id fails.
Trait Implementations§
§impl Clone for RecordingProjectionStore
impl Clone for RecordingProjectionStore
§impl Debug for RecordingProjectionStore
impl Debug for RecordingProjectionStore
§impl Default for RecordingProjectionStore
impl Default for RecordingProjectionStore
§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.
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
const READS_THROUGH_BATCH: bool = true
true, as for the memory store this wraps: it applies on write.