diff --git a/compatibility/src/lib.rs b/compatibility/src/lib.rs index 44963047..96fde3f5 100644 --- a/compatibility/src/lib.rs +++ b/compatibility/src/lib.rs @@ -3,6 +3,7 @@ use ::rand::Rng; use bincode_1::Options; +mod membership; mod misc; mod rand; mod sway; diff --git a/compatibility/src/membership.rs b/compatibility/src/membership.rs new file mode 100644 index 00000000..57801b04 --- /dev/null +++ b/compatibility/src/membership.rs @@ -0,0 +1,52 @@ +// Added by [ppamorim](https://github.com/ppamorim) +// Taken from https://github.com/datafuselabs/openraft/blob/209ae677ade5b624fea9f6630e9ff191963f5d74/openraft/src/membership/membership.rs#L21 +// License: Openraft is licensed under the terms of the MIT License or the Apache License 2.0, at your choosing. + +use rand::{prelude::ThreadRng, Rng}; +use std::collections::BTreeSet; + +type NodeId = u64; + +#[derive( + bincode_2::Encode, bincode_2::Decode, serde::Serialize, serde::Deserialize, Debug, PartialEq, +)] +#[bincode(crate = "bincode_2")] +pub struct Membership { + /// learners set + learners: BTreeSet, + + /// Multi configs. + configs: Vec>, + + /// Cache of all node ids. + all_members: BTreeSet, +} + +#[test] +pub fn test() { + let mut rng = rand::thread_rng(); + for _ in 0..1000 { + crate::test_same(Membership { + learners: random_btreeset(&mut rng), + configs: vec_random_btreeset(&mut rng), + all_members: random_btreeset(&mut rng), + }); + } +} + +fn vec_random_btreeset(rng: &mut ThreadRng) -> Vec> { + let mut vec = Vec::with_capacity(10); + for _ in 0..rng.gen_range(0..10) { + vec.push(random_btreeset(rng)); + } + vec +} + +fn random_btreeset(rng: &mut ThreadRng) -> BTreeSet { + let mut set = BTreeSet::new(); + for _ in 0..rng.gen_range(0..100) { + let v = rng.gen(); + set.insert(v); + } + set +}