diff --git a/openraft/src/engine/testing.rs b/openraft/src/engine/testing.rs index d14128894..8e7162832 100644 --- a/openraft/src/engine/testing.rs +++ b/openraft/src/engine/testing.rs @@ -6,12 +6,20 @@ use crate::RaftTypeConfig; /// Trivial Raft type config for Engine related unit tests, /// with an optional custom node type `N` for Node type. -#[derive(Debug, Default, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct UTConfig { _p: std::marker::PhantomData, } +impl Default for UTConfig { + fn default() -> Self { + Self { + _p: std::marker::PhantomData, + } + } +} + impl Clone for UTConfig { fn clone(&self) -> Self { *self diff --git a/openraft/src/membership/membership.rs b/openraft/src/membership/membership.rs index 51ddc2b57..7ae6384a3 100644 --- a/openraft/src/membership/membership.rs +++ b/openraft/src/membership/membership.rs @@ -19,7 +19,7 @@ use crate::RaftTypeConfig; /// /// It could be a joint of one, two or more configs, i.e., a quorum is a node set that is superset /// of a majority of every config. -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))] pub struct Membership where C: RaftTypeConfig @@ -35,6 +35,17 @@ where C: RaftTypeConfig pub(crate) nodes: BTreeMap, } +impl Default for Membership +where C: RaftTypeConfig +{ + fn default() -> Self { + Membership { + configs: vec![], + nodes: BTreeMap::new(), + } + } +} + impl From> for Membership where C: RaftTypeConfig { diff --git a/openraft/src/metrics/wait_test.rs b/openraft/src/metrics/wait_test.rs index b2a52b081..b1f1647fc 100644 --- a/openraft/src/metrics/wait_test.rs +++ b/openraft/src/metrics/wait_test.rs @@ -262,10 +262,7 @@ where C: RaftTypeConfig { current_leader: None, millis_since_quorum_ack: None, last_quorum_acked: None, - membership_config: Arc::new(StoredMembership::new( - None, - Membership::new_with_defaults(vec![btreeset! {}], []), - )), + membership_config: Arc::new(StoredMembership::new(None, Membership::default())), heartbeat: None, snapshot: None, diff --git a/openraft/src/node.rs b/openraft/src/node.rs index ef3b16696..e4bed9a62 100644 --- a/openraft/src/node.rs +++ b/openraft/src/node.rs @@ -46,11 +46,11 @@ impl NodeId for T where T: Sized /// network address, but the used [`Node`] implementation can be customized to include additional /// information. pub trait Node -where Self: Sized + OptionalFeatures + Eq + PartialEq + Debug + Clone + Default + 'static +where Self: Sized + OptionalFeatures + Eq + PartialEq + Debug + Clone + 'static { } -impl Node for T where T: Sized + OptionalFeatures + Eq + PartialEq + Debug + Clone + Default + 'static {} +impl Node for T where T: Sized + OptionalFeatures + Eq + PartialEq + Debug + Clone + 'static {} /// EmptyNode is an implementation of trait [`Node`] that contains nothing. /// diff --git a/openraft/src/testing/common.rs b/openraft/src/testing/common.rs index 8aa7cf139..8047b11a5 100644 --- a/openraft/src/testing/common.rs +++ b/openraft/src/testing/common.rs @@ -26,7 +26,10 @@ pub fn membership_ent( node_id: C::NodeId, index: u64, config: Vec>, -) -> crate::Entry { +) -> crate::Entry +where + C::Node: Default, +{ crate::Entry::new_membership( LogId::new(CommittedLeaderId::new(term, node_id), index), crate::Membership::new_with_defaults(config, []), diff --git a/openraft/src/testing/log/suite.rs b/openraft/src/testing/log/suite.rs index 674468b51..fcfee9de1 100644 --- a/openraft/src/testing/log/suite.rs +++ b/openraft/src/testing/log/suite.rs @@ -113,6 +113,7 @@ where C::D: Debug, C::R: Debug, C::NodeId: From, + C::Node: Default, LS: RaftLogStorage, SM: RaftStateMachine, B: StoreBuilder, @@ -1391,7 +1392,10 @@ where C::NodeId: From { /// Create a membership entry with node_id 0 for test. fn membership_ent_0(term: u64, index: u64, bs: BTreeSet) -> C::Entry -where C::NodeId: From { +where + C::NodeId: From, + C::Node: Default, +{ C::Entry::new_membership(log_id_0(term, index), Membership::new_with_defaults(vec![bs], [])) }