Ejemplo n.º 1
0
        public RaftNode(Config cfg, IRpcSender sender = null)
        {
            this.sender   = sender ?? new HttpRpcClient();
            Configuration = cfg;
            var stateMachine = new T();

            engine = new RaftEngine(Configuration, stateMachine, this);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 private static void Dump(RaftEngine node)
 {
     Console.WriteLine($"State machine for {node} ---------------");
     node.GetStateMachineManager <TestStateMachine>().Dump();
 }