@@ -2409,6 +2409,58 @@ int full_consensus_test() {
2409
2409
return 0 ;
2410
2410
}
2411
2411
2412
+
2413
+ int flip_learner_flag_test () {
2414
+ reset_log_files ();
2415
+
2416
+ std::string s1_addr = " tcp://127.0.0.1:20010" ;
2417
+ std::string s2_addr = " tcp://127.0.0.1:20020" ;
2418
+ std::string s3_addr = " tcp://127.0.0.1:20030" ;
2419
+
2420
+ RaftAsioPkg s1 (1 , s1_addr);
2421
+ RaftAsioPkg s2 (2 , s2_addr);
2422
+ RaftAsioPkg s3 (3 , s3_addr);
2423
+ std::vector<RaftAsioPkg*> pkgs = {&s1, &s2, &s3};
2424
+
2425
+ _msg (" launching asio-raft servers\n " );
2426
+ CHK_Z ( launch_servers (pkgs, false ) );
2427
+ _msg (" organizing raft group\n " );
2428
+ CHK_Z ( make_group (pkgs) );
2429
+ // Set async.
2430
+ for (auto & entry: pkgs) {
2431
+ RaftAsioPkg* pp = entry;
2432
+ raft_params param = pp->raftServer ->get_current_params ();
2433
+ param.return_method_ = raft_params::async_handler;
2434
+ pp->raftServer ->update_params (param);
2435
+ }
2436
+ // Set to learner.
2437
+ ptr<cmd_result<ptr<buffer>>> result = s1.raftServer ->flip_learner_flag (s3.myId , true );
2438
+ CHK_EQ (cmd_result_code::OK, result->get_result_code ());
2439
+ TestSuite::sleep_ms (RaftAsioPkg::HEARTBEAT_MS * 5 , " wait for replication" );
2440
+ for (auto & entry: pkgs) {
2441
+ RaftAsioPkg* pp = entry;
2442
+ ptr<cluster_config> conf = pp->raftServer ->get_config ();
2443
+ CHK_TRUE (conf->get_server (s3.myId )->is_learner ());
2444
+ }
2445
+ // Clear leaner.
2446
+ result = s1.raftServer ->flip_learner_flag (s3.myId , false );
2447
+ CHK_EQ (cmd_result_code::OK, result->get_result_code ());
2448
+ TestSuite::sleep_ms (RaftAsioPkg::HEARTBEAT_MS * 5 , " wait for replication" );
2449
+ for (auto & entry: pkgs) {
2450
+ RaftAsioPkg* pp = entry;
2451
+ ptr<cluster_config> conf = pp->raftServer ->get_config ();
2452
+ CHK_FALSE (conf->get_server (s3.myId )->is_learner ());
2453
+ }
2454
+
2455
+ s1.raftServer ->shutdown ();
2456
+ s2.raftServer ->shutdown ();
2457
+ s3.raftServer ->shutdown ();
2458
+ TestSuite::sleep_sec (1 , " shutting down" );
2459
+
2460
+ SimpleLogger::shutdown ();
2461
+ return 0 ;
2462
+ }
2463
+
2412
2464
int custom_commit_condition_test () {
2413
2465
reset_log_files ();
2414
2466
@@ -2916,6 +2968,9 @@ int main(int argc, char** argv) {
2916
2968
ts.doTest ( " full consensus test" ,
2917
2969
full_consensus_test );
2918
2970
2971
+ ts.doTest (" flip learner flag test" ,
2972
+ flip_learner_flag_test);
2973
+
2919
2974
ts.doTest ( " custom commit condition test" ,
2920
2975
custom_commit_condition_test );
2921
2976
0 commit comments