瀏覽代碼

Move NO_SNAPSHOT to tests.

Jing Yang 4 年之前
父節點
當前提交
522aeeb27d
共有 4 個文件被更改,包括 7 次插入9 次删除
  1. 0 6
      src/lib.rs
  2. 2 2
      test_configs/src/raft/config.rs
  3. 1 1
      test_configs/src/rpcs.rs
  4. 4 0
      test_configs/src/utils.rs

+ 0 - 6
src/lib.rs

@@ -298,9 +298,3 @@ where
 }
 
 pub(crate) const HEARTBEAT_INTERVAL_MILLIS: u64 = 150;
-
-impl<C> Raft<C> {
-    /// Pass this function to [`Raft::new`] if the application will not accept
-    /// any request for taking snapshots.
-    pub const NO_SNAPSHOT: fn(Index) = |_| {};
-}

+ 2 - 2
test_configs/src/raft/config.rs

@@ -10,7 +10,7 @@ use parking_lot::Mutex;
 use rand::{thread_rng, Rng};
 
 use crate::register_server;
-use crate::utils::sleep_millis;
+use crate::utils::{sleep_millis, NO_SNAPSHOT};
 use ruaft::{ApplyCommandMessage, Persister, Raft, Term};
 
 struct ConfigState {
@@ -319,7 +319,7 @@ impl Config {
                 Self::apply_command(log_clone.clone(), index, message)
             },
             None,
-            Raft::<i32>::NO_SNAPSHOT,
+            NO_SNAPSHOT,
         );
         self.state.lock().rafts[index].replace(raft.clone());
 

+ 1 - 1
test_configs/src/rpcs.rs

@@ -224,7 +224,7 @@ mod tests {
                 Arc::new(DoNothingPersister),
                 |_: ApplyCommandMessage<i32>| {},
                 None,
-                Raft::<i32>::NO_SNAPSHOT,
+                crate::utils::NO_SNAPSHOT,
             ));
             register_server(raft, name, network.as_ref())?;
 

+ 4 - 0
test_configs/src/utils.rs

@@ -8,3 +8,7 @@ pub const LONG_ELECTION_TIMEOUT_MILLIS: u64 = 1000;
 pub fn sleep_election_timeouts(count: u64) {
     sleep_millis(LONG_ELECTION_TIMEOUT_MILLIS * count)
 }
+
+/// Pass this function to [`Raft::new`] if the application will not accept
+/// any request for taking snapshots.
+pub const NO_SNAPSHOT: fn(ruaft::Index) = |_| {};