MockMembership

Struct MockMembership 

Source
pub struct MockMembership<T>
where T: TypeConfig,
{ /* private fields */ }

Implementations§

Source§

impl<T> MockMembership<T>
where T: TypeConfig,

Source

pub fn checkpoint(&mut self)

Validate that all current expectations for all methods have been satisfied, and discard them.

Source

pub fn new() -> Self

Create a new mock object with no expectations.

This method will not be generated if the real struct already has a new method. However, it will be generated if the struct implements a trait with a new method. The trait’s new method can still be called like <MockX as TraitY>::new

Source§

impl<T> MockMembership<T>
where T: TypeConfig,

Source

pub fn expect_members(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the members method

Source

pub fn expect_replication_peers(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the replication_peers method

Source

pub fn expect_voters(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the voters method

Source

pub fn expect_initial_cluster_size(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the initial_cluster_size method

Source

pub fn expect_is_single_node_cluster(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the is_single_node_cluster method

Source

pub fn expect_nodes_with_status(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the nodes_with_status method

Source

pub fn expect_get_node_status(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_node_status method

Source

pub fn expect_check_cluster_is_ready(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the check_cluster_is_ready method

Source

pub fn expect_get_peers_id_with_condition(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_peers_id_with_condition method

Source

pub fn expect_retrieve_cluster_membership_config( &mut self, ) -> &mut Expectation<T>

Create an Expectation for mocking the retrieve_cluster_membership_config method

Source

pub fn expect_update_cluster_conf_from_leader(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the update_cluster_conf_from_leader method

Source

pub fn expect_get_cluster_conf_version(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_cluster_conf_version method

Source

pub fn expect_update_conf_version(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the update_conf_version method

Source

pub fn expect_incr_conf_version(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the incr_conf_version method

Source

pub fn expect_add_learner(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the add_learner method

Source

pub fn expect_activate_node(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the activate_node method

Source

pub fn expect_update_node_status(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the update_node_status method

Source

pub fn expect_contains_node(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the contains_node method

Source

pub fn expect_retrieve_node_meta(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the retrieve_node_meta method

Source

pub fn expect_remove_node(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the remove_node method

Source

pub fn expect_force_remove_node(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the force_remove_node method

Source

pub fn expect_get_all_nodes(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_all_nodes method

Source

pub fn expect_pre_warm_connections(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the pre_warm_connections method

Source

pub fn expect_get_peer_channel(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_peer_channel method

Source

pub fn expect_get_address(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_address method

Source

pub fn expect_apply_config_change(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the apply_config_change method

Source

pub fn expect_notify_config_applied(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the notify_config_applied method

Source

pub fn expect_get_zombie_candidates(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the get_zombie_candidates method

Source

pub fn expect_can_rejoin(&mut self) -> &mut Expectation<T>

Create an Expectation for mocking the can_rejoin method

Trait Implementations§

Source§

impl<T> Debug for MockMembership<T>
where T: TypeConfig,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for MockMembership<T>
where T: TypeConfig,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Membership<T> for MockMembership<T>
where T: TypeConfig,

Source§

fn members<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

All nodes (including itself)

Source§

fn replication_peers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

All non-self nodes (including Syncing and Active) Note: Joining node has not start its Raft event processing engine yet.

Source§

fn voters<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

All non-self nodes in Active state

Source§

fn initial_cluster_size<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the initial cluster size from configuration

This value is determined at node startup from the initial_cluster configuration and remains constant throughout the node’s lifetime. It represents the designed cluster size, not the current runtime membership state.

Used for:

  • Quorum calculations
  • Cluster topology decisions
§Safety

This method is safe to use for cluster topology decisions as it’s based on immutable configuration rather than runtime state that could be affected by network partitions or bugs.

Source§

fn is_single_node_cluster<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if this is a single-node cluster

Returns true if the initial cluster size is 1, indicating this node was configured to run in standalone mode without any peers.

This is a convenience method equivalent to initial_cluster_size() == 1.

§Use Cases
  • Skip Raft election in single-node mode (no peers to vote)
  • Skip log replication in single-node mode (no peers to replicate to)
  • Optimize performance by avoiding unnecessary network operations
§Safety

Safe for all cluster topology decisions as it’s based on immutable configuration.

Source§

fn nodes_with_status<'life0, 'async_trait>( &'life0 self, status: NodeStatus, ) -> Pin<Box<dyn Future<Output = Vec<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

All pending active nodes in Active state

Source§

fn retrieve_cluster_membership_config<'life0, 'async_trait>( &'life0 self, current_leader_id: Option<u32>, ) -> Pin<Box<dyn Future<Output = ClusterMembership> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

retrieve latest cluster membership with current leader ID

§Parameters
  • current_leader_id: Optional current leader ID from runtime state
Source§

fn update_cluster_conf_from_leader<'life0, 'life1, 'async_trait>( &'life0 self, my_id: u32, my_current_term: u64, current_conf_version: u64, current_leader_id: Option<u32>, cluster_conf_change_req: &'life1 ClusterConfChangeRequest, ) -> Pin<Box<dyn Future<Output = Result<ClusterConfUpdateResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

invoked when receive requests from Leader

Source§

fn add_learner<'life0, 'async_trait>( &'life0 self, node_id: u32, address: String, status: NodeStatus, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add a new node as a learner

Source§

fn activate_node<'life0, 'async_trait>( &'life0 mut self, new_node_id: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Activate node

Source§

fn update_node_status<'life0, 'async_trait>( &'life0 self, node_id: u32, status: NodeStatus, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update status of a node

Source§

fn contains_node<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if the node already exists

Source§

fn remove_node<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Elegantly remove nodes

Source§

fn force_remove_node<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Forcefully remove faulty nodes

Source§

fn get_all_nodes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all node status

Source§

fn pre_warm_connections<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Pre-warms connection cache for all replication peers

Source§

fn apply_config_change<'life0, 'async_trait>( &'life0 self, change: MembershipChange, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Apply committed configuration change

Source§

fn can_rejoin<'life0, 'async_trait>( &'life0 self, node_id: u32, role: i32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

If new node could rejoin the cluster again

Source§

fn get_node_status<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = Option<NodeStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn check_cluster_is_ready<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_peers_id_with_condition<'life0, 'async_trait, F>( &'life0 self, condition: F, ) -> Pin<Box<dyn Future<Output = Vec<u32>> + Send + 'async_trait>>
where F: Fn(i32) -> bool + Send + Sync + 'static + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_cluster_conf_version<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = u64> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn update_conf_version<'life0, 'async_trait>( &'life0 self, version: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn incr_conf_version<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn retrieve_node_meta<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = Option<NodeMeta>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_peer_channel<'life0, 'async_trait>( &'life0 self, node_id: u32, conn_type: ConnectionType, ) -> Pin<Box<dyn Future<Output = Option<Channel>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_address<'life0, 'async_trait>( &'life0 self, node_id: u32, ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn notify_config_applied<'life0, 'async_trait>( &'life0 self, index: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_zombie_candidates<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<u32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

§

impl<T> Freeze for MockMembership<T>

§

impl<T> RefUnwindSafe for MockMembership<T>
where T: RefUnwindSafe,

§

impl<T> Send for MockMembership<T>

§

impl<T> Sync for MockMembership<T>

§

impl<T> Unpin for MockMembership<T>
where T: Unpin,

§

impl<T> UnwindSafe for MockMembership<T>
where T: UnwindSafe,

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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