Skip to content

Commit

Permalink
*: Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear committed May 10, 2018
1 parent 4142d89 commit bb3b73a
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 67 deletions.
12 changes: 8 additions & 4 deletions examples/single_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@

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;

type ProposeCallback = Box<Fn() + Send>;

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.
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -110,8 +110,8 @@ pub type Result<T> = result::Result<T, Error>;

#[cfg(test)]
mod tests {
use std::io;
use super::*;
use std::io;

#[test]
fn test_error_equal() {
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -382,7 +382,7 @@ mod test {
inflight.add(i);
}

let wantin = Inflights{
let wantin = Inflights {
start: 0,
count: 5,
buffer: vec![0, 1, 2, 3, 4],
Expand Down Expand Up @@ -454,7 +454,7 @@ mod test {
inflight.free_to(8);

let wantin2 = Inflights {
start: 9,
start: 9,
count: 1,
buffer: vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
};
Expand Down Expand Up @@ -504,4 +504,3 @@ mod test {
assert_eq!(inflight, wantin);
}
}

6 changes: 3 additions & 3 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -430,11 +430,11 @@ impl<T: Storage> RaftLog<T> {
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<MemStorage> {
RaftLog::new(s, String::from(""))
Expand Down
8 changes: 4 additions & 4 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

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::Status;
use super::Storage;
use super::errors::{Error, Result};
use super::raft::{Config, Raft, SoftState, INVALID_ID};
use super::Status;
use super::read_only::ReadState;

#[derive(Debug, Default)]
Expand Down Expand Up @@ -454,8 +454,8 @@ impl<T: Storage> RawNode<T> {

#[cfg(test)]
mod test {
use eraftpb::MessageType;
use super::is_local_msg;
use eraftpb::MessageType;

#[test]
fn test_is_local_msg() {
Expand Down
2 changes: 1 addition & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
34 changes: 10 additions & 24 deletions tests/cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
// 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};
use raft::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message,
MessageType, Snapshot};
use rand;

use raft::*;
use raft::storage::MemStorage;
use raft::*;

pub fn ltoa(raft_log: &RaftLog<MemStorage>) -> String {
let mut s = format!("committed: {}\n", raft_log.committed);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/cases/test_raft_paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions tests/cases/test_raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bb3b73a

Please sign in to comment.