Esempio n. 1
0
    def test_lose_leader(self):
        self.test_gain_leader()

        self.assertEquals(self.l.leader_proposal_id, PID(1, 'A'))

        self.l.recv_heartbeat('B', PID(5, 'B'))

        self.assertEquals(self.l.leader_proposal_id, PID(5, 'B'))
        self.assertEquals(self.tleader, 'lost')
Esempio n. 2
0
    def test_lose_leader(self):
        self.test_gain_leader()

        self.assertEquals(self.l.leader_proposal_id, PID(1, 'A'))

        self.l.recv_leadership_proclamation('B', PID(5, 'B'))

        self.assertEquals(self.l.leader_proposal_id, PID(5, 'B'))
        self.assertEquals(self.tleader, 'lost')
Esempio n. 3
0
    def test_gain_leader_nack(self):
        self.pre_acq('foo')

        self.p()

        self.am('prepare', PID(1, 'A'))

        self.l.recv_promise('A', PID(1, 'A'), None, None)

        self.l.recv_prepare_nack('B', PID(1, 'A'), PID(2, 'C'))

        self.am('prepare', PID(3, 'A'))
Esempio n. 4
0
    def test_initial_leader(self):
        self.l.leader_proposal_id = PID(1, 'B')

        self.pre_acq()

        # test_initial_wait() shows that the next call to p() will
        # result in the node attempting to assume leadership by
        # generating a new proposal_id. Reception of this heartbeat
        # should reset the liveness timer and suppress the coup attempt.
        self.l.recv_heartbeat('B', PID(1, 'B'))

        self.p()
        self.assertEquals(self.l.proposal_id, None)
Esempio n. 5
0
    def test_regain_leader(self):
        self.test_lose_leader()

        self.l.prepare()

        self.am('prepare', PID(6, 'A'))

        self.l.recv_promise('B', PID(6, 'A'), None, None)
        self.l.recv_promise('C', PID(6, 'A'), None, None)
        self.an()
        self.l.recv_promise('D', PID(6, 'A'), None, None)
        self.am('accept', PID(6, 'A'), 'foo')

        self.assertEquals(self.tleader, 'gained')
Esempio n. 6
0
    def test_gain_leader_abort(self):
        self.pre_acq('foo')

        self.p()

        self.am('prepare', PID(1, 'A'))

        self.l.recv_promise('A', PID(1, 'A'), None, None)
        self.l.recv_promise('B', PID(1, 'A'), None, None)

        self.at(self.l._acquiring)
        self.l.recv_heartbeat('B', PID(5, 'B'))
        self.at(not self.l._acquiring)
        self.l.acquire_leadership()
        self.an()
Esempio n. 7
0
    def test_gain_leader(self):
        self.pre_acq('foo')

        self.p()

        self.am('prepare', PID(1, 'A'))

        self.l.recv_promise('A', PID(1, 'A'), None, None)
        self.l.recv_promise('B', PID(1, 'A'), None, None)

        self.an()

        self.l.recv_promise('C', PID(1, 'A'), None, None)

        self.am('accept', PID(1, 'A'), 'foo')

        self.assertEquals(self.tleader, 'gained')
Esempio n. 8
0
    def test_pulse(self):
        self.test_gain_leader()

        for i in range(0, 8):
            self.tadvance()

        self.assertEquals(self.hbcount, 5)
        self.assertEquals(self.l.leader_proposal_id, PID(1, 'A'))
        self.assertTrue(self.l.leader_is_alive())
Esempio n. 9
0
    def test_regain_leader(self):
        self.test_lose_leader()

        for i in range(1, 7):
            self.p()
            self.an()

        self.p()

        # The 6 here comes from using PID(5,'B') as the heartbeat proposal
        # id the caused the loss of leadership
        #
        self.am('prepare', PID(6, 'A'))

        self.l.recv_promise('B', PID(6, 'A'), None, None)
        self.l.recv_promise('C', PID(6, 'A'), None, None)
        self.an()
        self.l.recv_promise('D', PID(6, 'A'), None, None)
        self.am('accept', PID(6, 'A'), 'foo')

        self.assertEquals(self.tleader, 'gained')
Esempio n. 10
0
    def test_lose_leader_via_nacks(self):
        self.test_gain_leader()

        self.assertEquals(self.l.leader_proposal_id, PID(1, 'A'))

        self.l.recv_accept_nack('B', PID(1, 'A'), PID(2, 'B'))
        self.l.recv_accept_nack('C', PID(1, 'A'), PID(2, 'B'))

        self.assertEquals(self.tleader, 'gained')
        self.assertEquals(self.l.leader_proposal_id, PID(1, 'A'))

        self.l.recv_accept_nack('D', PID(1, 'A'), PID(2, 'B'))

        self.assertEquals(self.l.leader_proposal_id, None)
        self.assertEquals(self.tleader, 'lost')
Esempio n. 11
0
    def test_proposal_id_increment(self):
        self.l.set_proposal('foo')

        self.l.prepare()

        self.am('prepare', PID(1, 'A'))

        self.l.recv_promise('A', PID(1, 'A'), None, None)
        self.l.recv_promise('B', PID(1, 'A'), None, None)
        self.an()

        self.l.prepare()
        self.am('prepare', PID(2, 'A'))

        self.l.recv_promise('A', PID(2, 'A'), None, None)
        self.l.recv_promise('B', PID(2, 'A'), None, None)
        self.l.recv_promise('C', PID(2, 'A'), None, None)

        self.am('accept', PID(2, 'A'), 'foo')

        self.assertEquals(self.tleader, 'gained')
Esempio n. 12
0
    def test_initial_wait(self):
        self.pre_acq()

        self.p()

        self.assertEquals(self.l.proposal_id, PID(1, 'A'))
Esempio n. 13
0
    def test_ignore_old_leader_heartbeat(self):
        self.test_lose_leader()

        self.l.recv_heartbeat('A', PID(1, 'A'))

        self.assertEquals(self.l.leader_proposal_id, PID(5, 'B'))
Esempio n. 14
0
    def test_ignore_old_leader_proclamation(self):
        self.test_lose_leader()

        self.l.recv_leadership_proclamation('A', PID(1, 'A'))

        self.assertEquals(self.l.leader_proposal_id, PID(5, 'B'))