File tree 3 files changed +57
-0
lines changed
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,11 @@ where C: RaftTypeConfig
274
274
RuntimeConfigHandle :: new ( self . inner . as_ref ( ) )
275
275
}
276
276
277
+ /// Return the config of this Raft node.
278
+ pub fn config ( & self ) -> & Arc < Config > {
279
+ & self . inner . config
280
+ }
281
+
277
282
/// Enable or disable raft internal ticker.
278
283
#[ deprecated( since = "0.8.4" , note = "use `Raft::runtime_config().tick()` instead" ) ]
279
284
pub fn enable_tick ( & self , enabled : bool ) {
Original file line number Diff line number Diff line change
1
+ #![ cfg_attr( feature = "bt" , feature( error_generic_member_access) ) ]
2
+
3
+ #[ macro_use]
4
+ #[ path = "../fixtures/mod.rs" ]
5
+ mod fixtures;
6
+
7
+ // The number indicate the preferred running order for these case.
8
+ // The later tests may depend on the earlier ones.
9
+
10
+ mod t10_raft_config;
Original file line number Diff line number Diff line change
1
+ use std:: sync:: Arc ;
2
+
3
+ use anyhow:: Result ;
4
+ use maplit:: btreeset;
5
+ use openraft:: Config ;
6
+
7
+ use crate :: fixtures:: init_default_ut_tracing;
8
+ use crate :: fixtures:: RaftRouter ;
9
+
10
+ /// Get config via [`Raft::config`](openraft::Raft::config)
11
+ #[ async_entry:: test( worker_threads = 4 , init = "init_default_ut_tracing()" , tracing_span = "debug" ) ]
12
+ async fn raft_config ( ) -> Result < ( ) > {
13
+ let config = Arc :: new (
14
+ Config {
15
+ enable_tick : false ,
16
+ election_timeout_min : 123 ,
17
+ election_timeout_max : 124 ,
18
+ ..Default :: default ( )
19
+ }
20
+ . validate ( ) ?,
21
+ ) ;
22
+
23
+ let mut router = RaftRouter :: new ( config. clone ( ) ) ;
24
+
25
+ tracing:: info!( "--- initializing cluster" ) ;
26
+ let log_index = router. new_cluster ( btreeset ! { 0 } , btreeset ! { } ) . await ?;
27
+
28
+ tracing:: info!( log_index, "--- get config" ) ;
29
+ {
30
+ let n0 = router. get_raft_handle ( & 0 ) ?;
31
+ let c = n0. config ( ) ;
32
+
33
+ #[ allow( clippy:: bool_assert_comparison) ]
34
+ {
35
+ assert_eq ! ( c. enable_tick, false ) ;
36
+ }
37
+ assert_eq ! ( c. election_timeout_min, 123 ) ;
38
+ assert_eq ! ( c. election_timeout_max, 124 ) ;
39
+ }
40
+
41
+ Ok ( ( ) )
42
+ }
You can’t perform that action at this time.
0 commit comments