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); } }
public IDisposable Start() { engine.Start(); return(new DisposableAction(() => engine.Stop())); }