Skip to main content

RepTestBase

Struct RepTestBase 

Source
pub struct RepTestBase { /* private fields */ }
Expand description

JE-style replication group test fixture.

Mirrors JE’s RepTestBase (com.sleepycat.je.rep.impl.RepTestBase). Encapsulates a group of N nodes that share a group name, port range, and election policy, and provides the lifecycle / replication / assertion helpers that the JE rep TCK uses.

Use RepTestBase::builder to construct one; call RepTestBase::create_group to bring up all nodes; call RepTestBase::shutdown_all (or rely on Drop) to tear them down.

Implementations§

Source§

impl RepTestBase

Source

pub fn builder(group_name: impl Into<String>) -> RepTestBaseBuilder

Start building a new group with the given group name.

Source

pub fn group_size(&self) -> usize

Number of nodes in the group.

Source

pub fn node(&self, idx: usize) -> &RepEnvInfo

Borrow node at index idx (0-based — JE’s repEnvInfo[i]).

Source

pub fn node_mut(&mut self, idx: usize) -> &mut RepEnvInfo

Borrow node at index idx mutably.

Source

pub fn nodes(&self) -> &[RepEnvInfo]

Borrow all nodes.

Source

pub fn nodes_mut(&mut self) -> &mut [RepEnvInfo]

Borrow all nodes mutably.

Source

pub fn group_name(&self) -> &str

Returns the group name.

Source

pub fn create_group(&mut self, term: u64) -> Result<()>

Open every node’s env, elect node 0 as master with term, and join nodes 1..N as replicas pointing at node 0.

Mirrors JE’s RepTestBase.createGroup (which opens N nodes and expects the first to become master, the rest replicas).

Source

pub fn create_group_of_size(&mut self, first_n: usize, term: u64) -> Result<()>

Same as Self::create_group but only brings up the first first_n nodes — JE’s createGroup(int firstn) overload.

Source

pub fn shutdown_all(&mut self)

Close every node’s env (master last, to avoid spurious elections — matches JE’s closeNodes).

Source

pub fn find_master(&self) -> Option<&RepEnvInfo>

Find the unique master, or None if no node is currently master. Mirrors JE’s RepTestBase.findMaster.

Source

pub fn find_master_mut(&mut self) -> Option<&mut RepEnvInfo>

Find the master, or None — mutable variant.

Source

pub fn find_master_idx(&self) -> Option<usize>

Index of the unique master, or None.

Source

pub fn replicas(&self) -> Vec<&RepEnvInfo>

All replica nodes.

Source

pub fn await_master(&self, timeout: Duration) -> Result<usize>

Wait up to timeout for some node to be master, polling at Duration::from_millis(20) intervals. Returns the master’s index on success. Mirrors JE’s findMasterWait.

Source

pub fn await_state( &self, idx: usize, target: NodeState, timeout: Duration, ) -> Result<()>

Wait up to timeout for node idx to enter target state.

Source

pub fn await_vlsn_at_least( &self, idx: usize, vlsn: u64, timeout: Duration, ) -> Result<()>

Wait up to timeout for node idx’s VLSN to reach at least vlsn.

Source

pub fn replicate_one( &self, vlsn: u64, file: u32, offset: u32, entry_type: u8, ) -> Result<()>

Register a single VLSN on the master and apply it to every other node (acting as replicas). This is the in-process moral equivalent of “the master commits the txn, and the feeder streams it”.

entry_type is the replica-side apply_entry discriminator (a u8 that on the JE side selects between LN / commit / abort entries).

Source

pub fn populate_db(&self, start_vlsn: u64, count: u64) -> Result<()>

Replicate count VLSN entries starting at start_vlsn. Mirrors JE’s populateDB(rep, dbName, start, n) for the harness layer: the master records each VLSN and replicas apply it in order.

Source

pub fn populate_master_only(&self, start_vlsn: u64, count: u64) -> Result<()>

Same as Self::populate_db but only writes to the master and leaves replicas in the dust — useful for partition / catch-up tests.

Source

pub fn catch_up_replica( &self, replica_idx: usize, start_vlsn: u64, count: u64, ) -> Result<()>

Replay start_vlsn..start_vlsn+count on a single replica — used to simulate a replica catching up after a partition.

Source

pub fn close_master(&mut self) -> Result<usize>

Close the current master; mirrors JE’s leaveGroupAllButMaster’s inverse — kill the master, leaving replicas in NodeState::Replica until a Self::failover_to call drives a new election.

Returns the index of the closed master.

Source

pub fn failover_to(&mut self, replica_idx: usize) -> Result<()>

Drive replica replica_idx through Replica → Unknown → Master using a fresh term, then point all other live replicas at the new master. Mirrors JE’s transferMaster for the in-process harness.

Source

pub fn assert_all_at_vlsn(&self, vlsn: u64)

Assert every node currently in NodeState::Master or NodeState::Replica reports vlsn as its current_vlsn. Panics on mismatch.

Source

pub fn assert_state(&self, idx: usize, state: NodeState)

Assert node idx is in state.

Trait Implementations§

Source§

impl Drop for RepTestBase

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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, 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,