diff --git a/examples/single_mem_node/main.rs b/examples/single_mem_node/main.rs index f78bbec95..9a5b0f003 100644 --- a/examples/single_mem_node/main.rs +++ b/examples/single_mem_node/main.rs @@ -13,10 +13,10 @@ extern crate raft; +use std::collections::HashMap; use std::sync::mpsc::{self, RecvTimeoutError}; -use std::time::{Duration, Instant}; use std::thread; -use std::collections::HashMap; +use std::time::{Duration, Instant}; use raft::prelude::*; use raft::storage::MemStorage; @@ -24,10 +24,14 @@ use raft::storage::MemStorage; type ProposeCallback = Box; enum Msg { - Propose { id: u8, cb: ProposeCallback }, + Propose { + id: u8, + cb: ProposeCallback, + }, // Here we don't use Raft Message, so use dead_code to // avoid the compiler warning. - #[allow(dead_code)] Raft(Message), + #[allow(dead_code)] + Raft(Message), } // A simple example about how to use the Raft library in Rust. diff --git a/src/errors.rs b/src/errors.rs index ca6c0b15a..51b2b1dfb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{cmp, io, result}; use std::error; +use std::{cmp, io, result}; use protobuf::ProtobufError; @@ -110,8 +110,8 @@ pub type Result = result::Result; #[cfg(test)] mod tests { - use std::io; use super::*; + use std::io; #[test] fn test_error_equal() { diff --git a/src/lib.rs b/src/lib.rs index 2343eb807..8dd00fa6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,27 +38,27 @@ extern crate quick_error; extern crate rand; pub mod eraftpb; -mod raft_log; -pub mod storage; -mod raft; -mod progress; mod errors; mod log_unstable; -mod status; +mod progress; +mod raft; +mod raft_log; pub mod raw_node; mod read_only; +mod status; +pub mod storage; pub mod util; -pub use self::storage::{RaftState, Storage}; pub use self::errors::{Error, Result, StorageError}; +pub use self::log_unstable::Unstable; +pub use self::progress::{Inflights, Progress, ProgressSet, ProgressState}; pub use self::raft::{quorum, vote_resp_msg_type, Config, Raft, SoftState, StateRole, INVALID_ID, INVALID_INDEX}; pub use self::raft_log::{RaftLog, NO_LIMIT}; pub use self::raw_node::{is_empty_snap, Peer, RawNode, Ready, SnapshotStatus}; -pub use self::status::Status; -pub use self::log_unstable::Unstable; -pub use self::progress::{Inflights, Progress, ProgressSet, ProgressState}; pub use self::read_only::{ReadOnlyOption, ReadState}; +pub use self::status::Status; +pub use self::storage::{RaftState, Storage}; pub mod prelude { //! A "prelude" for crates using the `raft` crate. diff --git a/src/progress.rs b/src/progress.rs index 676c46369..9a97348e9 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -25,10 +25,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +use fxhash::FxHashMap; use std::cmp; -use std::iter::Chain; use std::collections::hash_map::{HashMap, Iter, IterMut}; -use fxhash::FxHashMap; +use std::iter::Chain; #[derive(Debug, PartialEq, Clone, Copy)] pub enum ProgressState { diff --git a/src/raft.rs b/src/raft.rs index c695ddb83..623db0708 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -27,16 +27,16 @@ use std::cmp; -use rand::{self, Rng}; use eraftpb::{Entry, EntryType, HardState, Message, MessageType, Snapshot}; use fxhash::FxHashMap; use protobuf::repeated::RepeatedField; +use rand::{self, Rng}; -use super::storage::Storage; -use super::progress::{Inflights, Progress, ProgressSet, ProgressState}; use super::errors::{Error, Result, StorageError}; +use super::progress::{Inflights, Progress, ProgressSet, ProgressState}; use super::raft_log::{self, RaftLog}; use super::read_only::{ReadOnly, ReadOnlyOption, ReadState}; +use super::storage::Storage; // CAMPAIGN_PRE_ELECTION represents the first phase of a normal election when // Config.pre_vote is true. diff --git a/src/raft_log.rs b/src/raft_log.rs index a5a619c3b..bb154bfe9 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -29,9 +29,9 @@ use std::cmp; use eraftpb::{Entry, Snapshot}; -use storage::Storage; -use log_unstable::Unstable; use errors::{Error, Result, StorageError}; +use log_unstable::Unstable; +use storage::Storage; use util; pub use util::NO_LIMIT; @@ -430,11 +430,11 @@ impl RaftLog { mod test { use std::panic::{self, AssertUnwindSafe}; - use raft_log::{self, RaftLog}; - use storage::MemStorage; use eraftpb; use errors::{Error, StorageError}; use protobuf; + use raft_log::{self, RaftLog}; + use storage::MemStorage; fn new_raft_log(s: MemStorage) -> RaftLog { RaftLog::new(s, String::from("")) diff --git a/src/raw_node.rs b/src/raw_node.rs index 4a8275041..9cab78bd0 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -27,15 +27,15 @@ use std::mem; -use protobuf::{self, RepeatedField}; use eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot}; +use protobuf::{self, RepeatedField}; use super::errors::{Error, Result}; -use super::Storage; use super::raft::{Config, Raft, SoftState, INVALID_ID}; -use super::Status; use super::read_only::ReadState; +use super::Status; +use super::Storage; #[derive(Debug, Default)] pub struct Peer { @@ -454,8 +454,8 @@ impl RawNode { #[cfg(test)] mod test { - use eraftpb::MessageType; use super::is_local_msg; + use eraftpb::MessageType; #[test] fn test_is_local_msg() { diff --git a/src/status.rs b/src/status.rs index 301bf8552..fef9d7662 100644 --- a/src/status.rs +++ b/src/status.rs @@ -28,9 +28,9 @@ use eraftpb::HardState; use fxhash::FxHashMap; +use progress::Progress; use raft::{Raft, SoftState, StateRole}; use storage::Storage; -use progress::Progress; #[derive(Default)] pub struct Status { diff --git a/src/storage.rs b/src/storage.rs index e27238188..0ae14908d 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -303,8 +303,8 @@ impl Storage for MemStorage { #[cfg(test)] mod test { - use protobuf; use eraftpb::{ConfState, Entry, Snapshot}; + use protobuf; use errors::{Error as RaftError, StorageError}; use storage::{MemStorage, Storage}; diff --git a/tests/cases/mod.rs b/tests/cases/mod.rs index 09f02209b..1bed08b3f 100644 --- a/tests/cases/mod.rs +++ b/tests/cases/mod.rs @@ -12,7 +12,7 @@ // limitations under the License. mod test_raft; -mod test_raft_snap; -mod test_raft_paper; mod test_raft_flow_control; +mod test_raft_paper; +mod test_raft_snap; mod test_raw_node; diff --git a/tests/cases/test_raft.rs b/tests/cases/test_raft.rs index 0cf4b74a8..8d8262d75 100644 --- a/tests/cases/test_raft.rs +++ b/tests/cases/test_raft.rs @@ -25,10 +25,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::cmp; use std::collections::HashMap; use std::ops::Deref; use std::ops::DerefMut; -use std::cmp; use std::panic::{self, AssertUnwindSafe}; use protobuf::{self, RepeatedField}; @@ -36,8 +36,8 @@ use raft::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, EntryType, Har MessageType, Snapshot}; use rand; -use raft::*; use raft::storage::MemStorage; +use raft::*; pub fn ltoa(raft_log: &RaftLog) -> String { let mut s = format!("committed: {}\n", raft_log.committed); @@ -897,34 +897,22 @@ fn test_vote_from_any_state_for_type(vt: MessageType) { StateRole::Follower ); assert_eq!( - r.term, - new_term, + r.term, new_term, "{:?},{:?}, term {}, want {}", - vt, - state, - r.term, - new_term + vt, state, r.term, new_term ); assert_eq!(r.vote, 2, "{:?},{:?}, vote {}, want 2", vt, state, r.vote); } else { // In a pre-vote, nothing changes. assert_eq!( - r.state, - state, + r.state, state, "{:?},{:?}, state {:?}, want {:?}", - vt, - state, - r.state, - state + vt, state, r.state, state ); assert_eq!( - r.term, - orig_term, + r.term, orig_term, "{:?},{:?}, term {}, want {}", - vt, - state, - r.term, - orig_term + vt, state, r.term, orig_term ); // If state == Follower or PreCandidate, r hasn't voted yet. // In Candidate or Leader, it's voted for itself. @@ -2030,11 +2018,9 @@ fn test_candidate_reset_term(message_type: MessageType) { // follower c term is reset with leader's assert_eq!( - nt.peers[&3].term, - nt.peers[&1].term, + nt.peers[&3].term, nt.peers[&1].term, "follower term expected same term as leader's {}, got {}", - nt.peers[&1].term, - nt.peers[&3].term, + nt.peers[&1].term, nt.peers[&3].term, ) } diff --git a/tests/cases/test_raft_paper.rs b/tests/cases/test_raft_paper.rs index 273fee44a..f8325b257 100644 --- a/tests/cases/test_raft_paper.rs +++ b/tests/cases/test_raft_paper.rs @@ -26,10 +26,10 @@ // limitations under the License. use super::test_raft::*; +use protobuf::RepeatedField; use raft::eraftpb::*; -use raft::*; use raft::storage::MemStorage; -use protobuf::RepeatedField; +use raft::*; pub fn hard_state(t: u64, c: u64, v: u64) -> HardState { let mut hs = HardState::new(); diff --git a/tests/cases/test_raw_node.rs b/tests/cases/test_raw_node.rs index b8185dbee..aa16bef13 100644 --- a/tests/cases/test_raw_node.rs +++ b/tests/cases/test_raw_node.rs @@ -25,14 +25,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::cell::RefCell; -use std::rc::Rc; -use raft::eraftpb::*; -use protobuf::{self, ProtobufEnum}; -use raft::*; -use raft::storage::MemStorage; use super::test_raft::*; use super::test_raft_paper::*; +use protobuf::{self, ProtobufEnum}; +use raft::eraftpb::*; +use raft::storage::MemStorage; +use raft::*; +use std::cell::RefCell; +use std::rc::Rc; fn new_peer(id: u64) -> Peer { Peer {