Skip to main content

MockCluster

Struct MockCluster 

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

A simulated multi-node cluster for testing.

Each node has its own runtime and system actors (SpawnManager, WatchManager, CancelManager, NodeDirectory). Cross-node messaging goes through the MockNetwork which can simulate failures.

Implementations§

Source§

impl MockCluster

Source

pub fn new(node_ids: &[&str]) -> Self

Create a cluster with the given node IDs.

All nodes are connected to each other in the NodeDirectory.

Source

pub fn node(&self, id: &str) -> &MockNode

Get a reference to a node.

Source

pub fn node_mut(&mut self, id: &str) -> &mut MockNode

Get a mutable reference to a node.

Source

pub fn network(&self) -> &MockNetwork

Get the network for fault injection.

Source

pub fn node_count(&self) -> usize

Number of nodes in the cluster.

Source

pub fn node_ids(&self) -> Vec<NodeId>

All node IDs.

Source

pub fn crash_node(&mut self, id: &str)

Remove a node from the cluster.

Updates all surviving nodes’ NodeDirectory to mark the crashed node as Disconnected.

Source

pub fn restart_node(&mut self, id: &str)

Restart a node — creates a fresh node with same ID. Reconnects it to all existing peers and updates their directories.

Source

pub fn freeze_node(&mut self, id: &str) -> Option<MockNode>

Freeze a node — removes it from the cluster temporarily. The returned MockNode retains its runtime and actors. Use unfreeze_node to restore it.

Source

pub fn unfreeze_node(&mut self, node: MockNode)

Unfreeze a node — restore it to the cluster. The node is re-inserted using its original node_id.

Source

pub fn watch<W>( &self, watcher_node: &str, watcher: &TestActorRef<W>, target_id: ActorId, )
where W: Actor + Handler<ChildTerminated> + 'static,

Watch an actor from a watcher on the same node. Both watcher and target must be on nodes in this cluster.

Source

pub fn unwatch(&self, node_id: &str, watcher_id: &ActorId, target_id: &ActorId)

Unwatch an actor.

Source

pub fn state_for(&self, local_node: &str) -> Option<ClusterState>

Get a ClusterState snapshot from the perspective of a specific node.

The local_node parameter determines which node is treated as local (excluded from peer_versions). Returns None if the cluster is empty or the node is not in the cluster.

Source

pub fn state(&self) -> Option<ClusterState>

Get a ClusterState snapshot. Returns None if the cluster is empty.

Uses the first node (sorted by ID) as the local node perspective. For deterministic results, prefer state_for.

Source

pub fn remote_watch( &mut self, target_node: &str, target: ActorId, watcher: ActorId, )

Register a remote watch via the target node’s WatchManager.

Source

pub fn remote_unwatch( &mut self, target_node: &str, target: &ActorId, watcher: &ActorId, )

Remove a remote watch via the target node’s WatchManager.

Source

pub fn notify_terminated( &mut self, node_id: &str, terminated: &ActorId, ) -> Vec<WatchNotification>

Notify the target node’s WatchManager that an actor has terminated. Returns notifications for all remote watchers of this actor.

Source

pub fn register_cancel( &mut self, node_id: &str, request_id: String, token: CancellationToken, )

Register a cancellation token on a node’s CancelManager.

Source

pub fn cancel_request( &mut self, node_id: &str, request_id: &str, ) -> CancelResponse

Cancel a request on a node’s CancelManager.

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