Example #1
0
    def test_proposerReceiveAccepted(self):
        proposer.myValue = "Kine er kul"
        acc = {'proposalID': 12, 'value': "BestestePost"}
        acc2 = {'proposalID': 2, 'value': "blogtest"}
        acc3 = {'proposalID': 5, 'value': "bestPost"}
        acc4 = {'proposalID': 13, 'value': "bestPost"}
        proposer.receiveAccepted(acc)
        proposer.receiveAccepted(acc2)

        # Returns its own value when none other has higher ProposalID
        self.assertEqual(proposer.myValue, proposer.receiveAccepted(acc3))

        # Returns None when other receival has highet ProposalID
        self.assertEqual(None, proposer.receiveAccepted(acc4))
Example #2
0
	def test_proposerReceiveAccepted(self):
		proposer.myValue = "Kine er kul"
		acc = {'proposalID' : 12, 'value' : "BestestePost"}
		acc2 = {'proposalID' : 2, 'value' : "blogtest"}
		acc3 = {'proposalID' : 5, 'value' : "bestPost"}
		acc4 = {'proposalID' : 13, 'value' : "bestPost"}
		proposer.receiveAccepted(acc)
		proposer.receiveAccepted(acc2)
		
		# Returns its own value when none other has higher ProposalID
		self.assertEqual(proposer.myValue, proposer.receiveAccepted(acc3))

		# Returns None when other receival has highet ProposalID
		self.assertEqual(None, proposer.receiveAccepted(acc4))
Example #3
0
                            # 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
                                elif reply != None:
                                    broadcast("DECIDE:" + json.dumps(
                                        {'value': reply}))  #reply is a string

                                    if not posts:
                                        paxosRunning = False
                                    else:
                                        post = posts.pop(0)
                                        proposemessage = json.dumps(
Example #4
0
							# 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
								elif reply != None:
									broadcast("DECIDE:"+json.dumps({'value': reply}))  #reply is a string

									if not posts:
										paxosRunning = False
									else:
										post = posts.pop(0)
										proposemessage = json.dumps(proposer.prepare(post))
										broadcast("PROPOSE:"+proposemessage)