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
impl MockCluster
Sourcepub fn new(node_ids: &[&str]) -> Self
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.
Sourcepub fn network(&self) -> &MockNetwork
pub fn network(&self) -> &MockNetwork
Get the network for fault injection.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the cluster.
Sourcepub fn crash_node(&mut self, id: &str)
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.
Sourcepub fn restart_node(&mut self, id: &str)
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.
Sourcepub fn freeze_node(&mut self, id: &str) -> Option<MockNode>
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.
Sourcepub fn unfreeze_node(&mut self, node: MockNode)
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.
Sourcepub fn watch<W>(
&self,
watcher_node: &str,
watcher: &TestActorRef<W>,
target_id: ActorId,
)
pub fn watch<W>( &self, watcher_node: &str, watcher: &TestActorRef<W>, target_id: ActorId, )
Watch an actor from a watcher on the same node. Both watcher and target must be on nodes in this cluster.
Sourcepub fn unwatch(&self, node_id: &str, watcher_id: &ActorId, target_id: &ActorId)
pub fn unwatch(&self, node_id: &str, watcher_id: &ActorId, target_id: &ActorId)
Unwatch an actor.
Sourcepub fn state_for(&self, local_node: &str) -> Option<ClusterState>
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.
Sourcepub fn state(&self) -> Option<ClusterState>
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.
Sourcepub fn remote_watch(
&mut self,
target_node: &str,
target: ActorId,
watcher: ActorId,
)
pub fn remote_watch( &mut self, target_node: &str, target: ActorId, watcher: ActorId, )
Register a remote watch via the target node’s WatchManager.
Sourcepub fn remote_unwatch(
&mut self,
target_node: &str,
target: &ActorId,
watcher: &ActorId,
)
pub fn remote_unwatch( &mut self, target_node: &str, target: &ActorId, watcher: &ActorId, )
Remove a remote watch via the target node’s WatchManager.
Sourcepub fn notify_terminated(
&mut self,
node_id: &str,
terminated: &ActorId,
) -> Vec<WatchNotification>
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.
Sourcepub fn register_cancel(
&mut self,
node_id: &str,
request_id: String,
token: CancellationToken,
)
pub fn register_cancel( &mut self, node_id: &str, request_id: String, token: CancellationToken, )
Register a cancellation token on a node’s CancelManager.
Sourcepub fn cancel_request(
&mut self,
node_id: &str,
request_id: &str,
) -> CancelResponse
pub fn cancel_request( &mut self, node_id: &str, request_id: &str, ) -> CancelResponse
Cancel a request on a node’s CancelManager.