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
impl RepTestBase
Sourcepub fn builder(group_name: impl Into<String>) -> RepTestBaseBuilder
pub fn builder(group_name: impl Into<String>) -> RepTestBaseBuilder
Start building a new group with the given group name.
Sourcepub fn group_size(&self) -> usize
pub fn group_size(&self) -> usize
Number of nodes in the group.
Sourcepub fn node(&self, idx: usize) -> &RepEnvInfo
pub fn node(&self, idx: usize) -> &RepEnvInfo
Borrow node at index idx (0-based — JE’s repEnvInfo[i]).
Sourcepub fn node_mut(&mut self, idx: usize) -> &mut RepEnvInfo
pub fn node_mut(&mut self, idx: usize) -> &mut RepEnvInfo
Borrow node at index idx mutably.
Sourcepub fn nodes(&self) -> &[RepEnvInfo]
pub fn nodes(&self) -> &[RepEnvInfo]
Borrow all nodes.
Sourcepub fn nodes_mut(&mut self) -> &mut [RepEnvInfo]
pub fn nodes_mut(&mut self) -> &mut [RepEnvInfo]
Borrow all nodes mutably.
Sourcepub fn group_name(&self) -> &str
pub fn group_name(&self) -> &str
Returns the group name.
Sourcepub fn create_group(&mut self, term: u64) -> Result<()>
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).
Sourcepub fn create_group_of_size(&mut self, first_n: usize, term: u64) -> Result<()>
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.
Sourcepub fn shutdown_all(&mut self)
pub fn shutdown_all(&mut self)
Close every node’s env (master last, to avoid spurious elections —
matches JE’s closeNodes).
Sourcepub fn find_master(&self) -> Option<&RepEnvInfo>
pub fn find_master(&self) -> Option<&RepEnvInfo>
Find the unique master, or None if no node is currently master.
Mirrors JE’s RepTestBase.findMaster.
Sourcepub fn find_master_mut(&mut self) -> Option<&mut RepEnvInfo>
pub fn find_master_mut(&mut self) -> Option<&mut RepEnvInfo>
Find the master, or None — mutable variant.
Sourcepub fn find_master_idx(&self) -> Option<usize>
pub fn find_master_idx(&self) -> Option<usize>
Index of the unique master, or None.
Sourcepub fn replicas(&self) -> Vec<&RepEnvInfo>
pub fn replicas(&self) -> Vec<&RepEnvInfo>
All replica nodes.
Sourcepub fn await_master(&self, timeout: Duration) -> Result<usize>
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.
Sourcepub fn await_state(
&self,
idx: usize,
target: NodeState,
timeout: Duration,
) -> Result<()>
pub fn await_state( &self, idx: usize, target: NodeState, timeout: Duration, ) -> Result<()>
Wait up to timeout for node idx to enter target state.
Sourcepub fn await_vlsn_at_least(
&self,
idx: usize,
vlsn: u64,
timeout: Duration,
) -> Result<()>
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.
Sourcepub fn replicate_one(
&self,
vlsn: u64,
file: u32,
offset: u32,
entry_type: u8,
) -> Result<()>
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).
Sourcepub fn populate_db(&self, start_vlsn: u64, count: u64) -> Result<()>
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.
Sourcepub fn populate_master_only(&self, start_vlsn: u64, count: u64) -> Result<()>
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.
Sourcepub fn catch_up_replica(
&self,
replica_idx: usize,
start_vlsn: u64,
count: u64,
) -> Result<()>
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.
Sourcepub fn close_master(&mut self) -> Result<usize>
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.
Sourcepub fn failover_to(&mut self, replica_idx: usize) -> Result<()>
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.
Sourcepub fn assert_all_at_vlsn(&self, vlsn: u64)
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.
Sourcepub fn assert_state(&self, idx: usize, state: NodeState)
pub fn assert_state(&self, idx: usize, state: NodeState)
Assert node idx is in state.
Trait Implementations§
Source§impl Drop for RepTestBase
impl Drop for RepTestBase
Auto Trait Implementations§
impl !Freeze for RepTestBase
impl !RefUnwindSafe for RepTestBase
impl !Sync for RepTestBase
impl !UnwindSafe for RepTestBase
impl Send for RepTestBase
impl Unpin for RepTestBase
impl UnsafeUnpin for RepTestBase
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> 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