Esempio n. 1
0
        public void LastPersistedInfoWorks()
        {
            var test = new MemoryLog();
            test.Initialize();

            test.Term = 1;
            test.CreateData(null, new[] { (byte)5 });

            Assert.AreEqual(1u, test.GetLastTerm());
            Assert.AreEqual(1u, test.GetLastIndex());
        }
Esempio n. 2
0
        public void AppendEntriesDataValid()
        {
            var test = new MemoryLog();
            test.Initialize();

            test.Term = 1;
            test.CreateData(null, new[] { (byte)5 });

            var index = test[1];
            var data = test.GetData(index);
            Assert.AreEqual((byte)5, data[0]);
        }
Esempio n. 3
0
        public void TermChangeResetsVoteFor()
        {
            var test = new MemoryLog();
            test.Initialize();

            test.Term = 1;
            test.VotedFor = new IPEndPoint(IPAddress.Loopback, 123);

            test.Term = 2;
            Assert.AreEqual(2u, test.Term);
            Assert.AreEqual(null, test.VotedFor);
        }
Esempio n. 4
0
        public void LogIsBetter()
        {
            var test = new MemoryLog();
            test.Initialize();
            test.Term = 1;

            Assert.AreEqual(false, test.LogIsBetter(0, 1));

            test.CreateData(null, new[] { (byte)5 });

            Assert.AreEqual(true, test.LogIsBetter(0, 1));
            Assert.AreEqual(false, test.LogIsBetter(1, 1));
        }
Esempio n. 5
0
        public override Server CreateServer()
        {
            var sid = ++id;
            var port = sid + 7000;
            var log = new MemoryLog();
            var server = new Server(sid, new IPEndPoint(IPAddress.Loopback, port), log, transport);
            transport.Start(server.ID);
            log.Initialize();
            server.ChangeState(new FollowerState(server));


            servers.Add(server);

            return server;
        }
Esempio n. 6
0
        public void CanAppendLog()
        {
            var test = new MemoryLog();
            test.Initialize();

            test.Term = 1;
            test.CreateData(null, new[] { (byte)5 });

            test.Term = 2;
            test.CreateData(null, new[] { (byte)6 });

            Assert.AreEqual(2u, test.Length);
            Assert.AreEqual(1u, test[1].Term);
            Assert.AreEqual(2u, test[2].Term);
        }