public RaftNode(Config cfg, IRpcSender sender = null) { this.sender = sender ?? new HttpRpcClient(); Configuration = cfg; var stateMachine = new T(); engine = new RaftEngine(Configuration, stateMachine, this); }
private static void TestCluster() { CreateLogsDirectory(); for (int i = 1; i <= NUM_PEERS; i++) { Config cfg = new Config(i) .WithLogDir(logDirs[i - 1]) .WithClusterName("TEST"); for (int j = 0; j < NUM_PEERS; j++) { cfg.AddPeer(j + 1); } RaftEngine raft = new RaftEngine(cfg, new TestStateMachine(), new RPC(rafts)); Dump(raft); rafts.Add(i, raft); } Task.Run(async() => { foreach (var raft in rafts.Values) { raft.Start(); } await Task.Delay(3000); while (true) { await Task.Delay(1000 + rnd.Next(10) * 500); foreach (var r in rafts.Values) { r.ExecuteCommand(MakeNewCommand(), null); } } }); Console.ReadKey(); foreach (var r in rafts.Values) { r.Stop(); Dump(r); } }
private static void Dump(RaftEngine node) { Console.WriteLine($"State machine for {node} ---------------"); node.GetStateMachineManager <TestStateMachine>().Dump(); }