Exemplo n.º 1
0
    def _(self, message, channel):
        """Handle request from out-of-sync replica""" 

        LOG.debug("RECEIVED message {0}".format(message))
        proposals = self._ledger.get_range(message.proposal)[:Learner.SYNC_SIZE]
        is_finished = proposals[-1] == self.state.read(Role.ACCEPTED)

        channel.unicast(Synced.create(receiver=message.sender,
                                      sender=message.receiver,
                                      proposal=proposals,
                                      finished=is_finished))
Exemplo n.º 2
0
    def test_learner_receives_synced(self):
        proposals = [LedgerEntry(number=1, value="v_1"),
                     LedgerEntry(number=2, value="v_2"),
                     LedgerEntry(number=3, value="v_3")]

        self.role.receive(Synced.create(proposal=proposals, sender='A'), self.channel)

        def get_entry(line):
            return LedgerEntry(*line.split(LedgerEntry.SEPARATOR))

        self.assert_equal(get_entry(self.ledger_storage[0]), LedgerEntry(number=1, value="v_1"))
        self.assert_equal(get_entry(self.ledger_storage[1]), LedgerEntry(number=2, value="v_2"))
        self.assert_equal(get_entry(self.ledger_storage[2]), LedgerEntry(number=3, value="v_3"))