pub struct OperatorTestHarness<T: FFIOperator> { /* private fields */ }Expand description
Test harness for FFI operators
This harness provides a complete testing environment for FFI operators with:
- Mock FFI context with test-specific callbacks
- State management via TestContext
- Version tracking
- Log capture (to stderr for now)
- Full support for apply() and pull() driven through the zero-copy ABI
Implementations§
Source§impl<T: FFIOperator> OperatorTestHarness<T>
impl<T: FFIOperator> OperatorTestHarness<T>
Sourcepub fn builder() -> TestHarnessBuilder<T>
pub fn builder() -> TestHarnessBuilder<T>
Create a new test harness builder
Sourcepub fn apply(&mut self, input: Change) -> Result<Change>
pub fn apply(&mut self, input: Change) -> Result<Change>
Apply a flow change to the operator via the zero-copy ABI.
Marshals the input as a ChangeFFI borrow, drives the operator,
and assembles an output Change from whatever the operator emitted
via ctx.builder(). The result is also appended to the harness
history so it can be inspected via harness[i], last_change(),
or history_len().
Sourcepub fn insert(&mut self, row: Row) -> &mut Self
pub fn insert(&mut self, row: Row) -> &mut Self
Chainable Insert: applies immediately, records output in history, panics on error.
Use for seeding state and/or inspecting emissions:
harness.insert(row1).insert(row2);
assert_eq!(harness[0].diffs.len(), 1);Sourcepub fn update(&mut self, pre: Row, post: Row) -> &mut Self
pub fn update(&mut self, pre: Row, post: Row) -> &mut Self
Chainable Update: applies immediately, records output in history, panics on error.
Sourcepub fn remove(&mut self, row: Row) -> &mut Self
pub fn remove(&mut self, row: Row) -> &mut Self
Chainable Remove: applies immediately, records output in history, panics on error.
Sourcepub fn history_len(&self) -> usize
pub fn history_len(&self) -> usize
Number of changes recorded in the history so far.
Sourcepub fn last_change(&self) -> Option<&Change>
pub fn last_change(&self) -> Option<&Change>
Reference to the most recent change, or None if the history is empty.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear the recorded history without affecting operator state.
Sourcepub fn pull(&mut self, row_numbers: &[RowNumber]) -> Result<Columns>
pub fn pull(&mut self, row_numbers: &[RowNumber]) -> Result<Columns>
Pull rows by their row numbers. The operator emits its result via
ctx.builder() as a single Insert-shaped diff; we read its post
columns as the return value.
Sourcepub fn version(&self) -> CommitVersion
pub fn version(&self) -> CommitVersion
Get the current version
Sourcepub fn set_version(&mut self, version: CommitVersion)
pub fn set_version(&mut self, version: CommitVersion)
Set the current version
Sourcepub fn state(&self) -> TestStateStore
pub fn state(&self) -> TestStateStore
Get access to the state store for assertions
Sourcepub fn assert_state<K>(&self, key: K, expected: Value)where
K: EncodableKey,
pub fn assert_state<K>(&self, key: K, expected: Value)where
K: EncodableKey,
Assert that a state key exists with the given value
Sourcepub fn clear_logs(&self)
pub fn clear_logs(&self)
Clear captured log messages
Sourcepub fn snapshot_state(&self) -> HashMap<EncodedKey, EncodedRow>
pub fn snapshot_state(&self) -> HashMap<EncodedKey, EncodedRow>
Take a snapshot of the current state
Sourcepub fn restore_state(&mut self, snapshot: HashMap<EncodedKey, EncodedRow>)
pub fn restore_state(&mut self, snapshot: HashMap<EncodedKey, EncodedRow>)
Restore state from a snapshot
Sourcepub fn create_operator_context(&mut self) -> OperatorContext
pub fn create_operator_context(&mut self) -> OperatorContext
Create an operator context for direct access
This is useful for testing components that need an OperatorContext without going through the apply() or pull() methods.
§Example
let mut harness = TestHarnessBuilder::<MyOperator>::new().build()?;
let mut ctx = harness.create_operator_context();
let (row_num, is_new) = ctx.get_or_create_row_number(harness.operator(), &key)?;Sourcepub fn operator_mut(&mut self) -> &mut T
pub fn operator_mut(&mut self) -> &mut T
Get a mutable reference to the operator
Sourcepub fn node_id(&self) -> FlowNodeId
pub fn node_id(&self) -> FlowNodeId
Get the node ID
Trait Implementations§
Source§impl<T: FFIOperator> Index<usize> for OperatorTestHarness<T>
Index into the harness history - harness[i] returns the i-th recorded Change.
impl<T: FFIOperator> Index<usize> for OperatorTestHarness<T>
Index into the harness history - harness[i] returns the i-th recorded Change.
Panics if i is out of bounds.
Auto Trait Implementations§
impl<T> !Freeze for OperatorTestHarness<T>
impl<T> !RefUnwindSafe for OperatorTestHarness<T>
impl<T> !Send for OperatorTestHarness<T>
impl<T> !Sync for OperatorTestHarness<T>
impl<T> Unpin for OperatorTestHarness<T>where
T: Unpin,
impl<T> UnsafeUnpin for OperatorTestHarness<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for OperatorTestHarness<T>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more