Example #1
0
        public void AddServer_ReplyNotLeaderIfNotLeader()
        {
            using (var mock = new T())
            using (var s1 = mock.CreateServer())
            using (var s2 = mock.CreateServer())
            {

                s1.Initialize();
                s2.Initialize();
                //s1.ChangeState(new CandidateState(s1)); // will push s1 to term 2

                //s1.Advance();

                var testState = new TestState(s2);
                s2.ChangeState(testState);

                var request = new AddServerRequest()
                {
                    From = s2.ID
                };

                s2.Transport.SendMessage(new Client(s2, s1.ID), request);
                s1.Advance();
                s2.Advance();

                //s2.Transport.SendMessage(new Client())

                Assert.AreEqual(typeof(AddServerReply), testState.LastMessage.GetType());
                Assert.AreEqual(AddServerStatus.NotLeader, ((AddServerReply)testState.LastMessage).Status);
            }
        }
Example #2
0
        public void AddServer_Timesout()
        {
            using (var mock = new T())
            using (var s1 = mock.CreateServer())
            using (var s2 = mock.CreateServer())
            {

                s1.Initialize();
                s2.Initialize();

                s1.ChangeState(new LeaderState(s1)); // will push s1 to term 2
                s1.PersistedStore.AddServer(s1, s1.ID);

                // applies its own entry and advances commit
                s1.Advance();

                // this sends out an add request
                s2.ChangeState(new JoinState(s2, new Client(s2, s1.ID)));

                // reads add request and sends its self as the first entry
                s1.Advance();

                var testState = new TestState(s2);
                s2.ChangeState(testState);

                s1.Advance(s1.PersistedStore.ELECTION_TIMEOUT);

                s2.Advance();

                Assert.AreEqual(typeof(AddServerReply), testState.LastMessage.GetType());
                Assert.AreEqual(AddServerStatus.TimedOut, ((AddServerReply)testState.LastMessage).Status);
            }
        }