Skip to main content

OperatorTestHarness

Struct OperatorTestHarness 

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

Source

pub fn builder() -> TestHarnessBuilder<T>

Create a new test harness builder

Source

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().

Source

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);
Source

pub fn update(&mut self, pre: Row, post: Row) -> &mut Self

Chainable Update: applies immediately, records output in history, panics on error.

Source

pub fn remove(&mut self, row: Row) -> &mut Self

Chainable Remove: applies immediately, records output in history, panics on error.

Source

pub fn history_len(&self) -> usize

Number of changes recorded in the history so far.

Source

pub fn last_change(&self) -> Option<&Change>

Reference to the most recent change, or None if the history is empty.

Source

pub fn clear_history(&mut self)

Clear the recorded history without affecting operator state.

Source

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.

Source

pub fn version(&self) -> CommitVersion

Get the current version

Source

pub fn set_version(&mut self, version: CommitVersion)

Set the current version

Source

pub fn state(&self) -> TestStateStore

Get access to the state store for assertions

Source

pub fn assert_state<K>(&self, key: K, expected: Value)
where K: EncodableKey,

Assert that a state key exists with the given value

Source

pub fn logs(&self) -> Vec<String>

Get captured log messages

Source

pub fn clear_logs(&self)

Clear captured log messages

Source

pub fn snapshot_state(&self) -> HashMap<EncodedKey, EncodedRow>

Take a snapshot of the current state

Source

pub fn restore_state(&mut self, snapshot: HashMap<EncodedKey, EncodedRow>)

Restore state from a snapshot

Source

pub fn reset(&mut self) -> Result<()>

Reset the harness to initial state

Source

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)?;
Source

pub fn operator(&self) -> &T

Get a reference to the operator

Source

pub fn operator_mut(&mut self) -> &mut T

Get a mutable reference to the operator

Source

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.

Panics if i is out of bounds.

Source§

type Output = Change

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more