コード例 #1
0
ファイル: tests.py プロジェクト: christiandt/paxos-project
	def test_acceptorReceiveAccept(self):
		acceptor.minProposal = 12
		acceptor.accepted = {'proposalID' : 12, 'value' : "I am previously accepted"}
		acc1 = {'proposalID' : 11, 'value' : "EnPost"}
		acc2 = {'proposalID' : 12, 'value' : "ToPost"}
		acc3 = {'proposalID' : 13, 'value' : "TrePost"}

		# When received proposalID is lower then minProposal
		self.assertEqual(acceptor.minProposal, acceptor.receiveAccept(acc1)['proposalID'])

		# When received proposalID is equal to minProposal
		self.assertEqual(acc2['proposalID'], acceptor.receiveAccept(acc2)['proposalID'])
		
		# When received proposalID is greater then minProposal
		self.assertEqual(acc3['proposalID'], acceptor.receiveAccept(acc3)['proposalID'])
コード例 #2
0
ファイル: tests.py プロジェクト: christiandt/paxos-project
    def test_acceptorReceiveAccept(self):
        acceptor.minProposal = 12
        acceptor.accepted = {
            'proposalID': 12,
            'value': "I am previously accepted"
        }
        acc1 = {'proposalID': 11, 'value': "EnPost"}
        acc2 = {'proposalID': 12, 'value': "ToPost"}
        acc3 = {'proposalID': 13, 'value': "TrePost"}

        # When received proposalID is lower then minProposal
        self.assertEqual(acceptor.minProposal,
                         acceptor.receiveAccept(acc1)['proposalID'])

        # When received proposalID is equal to minProposal
        self.assertEqual(acc2['proposalID'],
                         acceptor.receiveAccept(acc2)['proposalID'])

        # When received proposalID is greater then minProposal
        self.assertEqual(acc3['proposalID'],
                         acceptor.receiveAccept(acc3)['proposalID'])
コード例 #3
0
ファイル: server.py プロジェクト: christiandt/paxos-project
                                # but not decided), if so, insert post first in queue.
                                elif reply != None:
                                    if reply['conflict'] != None:
                                        post = reply['conflict']
                                        posts.insert(0, post)
                                        # Conflict occured, add post to begining of posts, continue as normal
                                    del reply['conflict']
                                    reply = json.dumps(reply)
                                    broadcast("ACCEPT:" + reply)

                            # Else if we have received an accept-message, forward this to the acceptor
                            # which in turn responds an accepted-message if it accepted the value
                            elif data[0:7] == "ACCEPT:":
                                result = data[7:]
                                result = json.loads(result)
                                reply = acceptor.receiveAccept(result)
                                s.send("ACCEPTED:" + json.dumps(reply))

                            # Else if we have received an accepted-message, forward this to the proposer
                            # which in turn broadcasts the decided value if all acceprors have accepted
                            # the value
                            elif data[0:9] == "ACCEPTED:":
                                result = data[9:]
                                result = json.loads(result)
                                reply = proposer.receiveAccepted(result)
                                if reply == "RESTART":
                                    proposemessage = json.dumps(
                                        proposer.prepare(proposer.myValue))
                                    broadcast("PROPOSE:" + proposemessage)

                                # Reply is None until majority is reached, reply is the value as a string
コード例 #4
0
ファイル: server.py プロジェクト: christiandt/paxos-project
								elif reply != None:
									if reply['conflict'] != None:
										post = reply['conflict']
										posts.insert(0, post)
										# Conflict occured, add post to begining of posts, continue as normal
									del reply['conflict']
									reply = json.dumps(reply)
									broadcast("ACCEPT:"+reply)


							# Else if we have received an accept-message, forward this to the acceptor
							# which in turn responds an accepted-message if it accepted the value
							elif data[0:7] == "ACCEPT:":
								result = data[7:]
								result = json.loads(result)
								reply = acceptor.receiveAccept(result)
								s.send("ACCEPTED:"+json.dumps(reply))


							# Else if we have received an accepted-message, forward this to the proposer
							# which in turn broadcasts the decided value if all acceprors have accepted 
							# the value
							elif data[0:9] == "ACCEPTED:":
								result = data[9:]
								result = json.loads(result)
								reply = proposer.receiveAccepted(result)
								if reply == "RESTART":
									proposemessage = json.dumps(proposer.prepare(proposer.myValue))
									broadcast("PROPOSE:"+proposemessage)

								# Reply is None until majority is reached, reply is the value as a string