Exemplo n.º 1
0
                        connections.remove(s)

                if debug:
                    print receivedData

                if "}" in receivedData:

                    for data in receivedData.split("}"):
                        if data != "":
                            data += "}"

                            # Else if we have received a propose-message, forward it to an acceptor
                            if data[0:8] == "PROPOSE:":
                                result = data[8:]
                                proposed = json.loads(result)
                                reply = acceptor.receivePropose(proposed)
                                s.send("ACK:" + json.dumps(reply))

                            # Else if we have received an ACK-message, an acceptor has accepted our proposal,
                            # forwards this to the proposer, which in turn broadcasts an accept-message if
                            # it has the majority of the acceptors accept its proposal
                            elif data[0:4] == "ACK:":
                                result = data[4:]
                                result = json.loads(result)
                                reply = proposer.receivePromise(result)
                                if reply == "RESTART":
                                    # In this case, propose your own value again, before others in queue
                                    proposemessage = json.dumps(
                                        proposer.prepare(proposer.myValue))
                                    broadcast("PROPOSE:" + proposemessage)
                                # When majority is received, check if conflict has occured (previous proposal accepted,
Exemplo n.º 2
0
 def test_acceptorReceivePropose_withPreviousValues(self):
     acceptor.minProposal = 19
     acceptor.accepted = {'proposalID': 19, 'value': "I am previous"}
     prop = {'proposalID': 20}
     self.assertEqual(acceptor.accepted, acceptor.receivePropose(prop))
Exemplo n.º 3
0
 def test_acceptorReceivePropose_withLowID(self):
     acceptor.minProposal = 19
     acceptor.accepted = {'proposalID': 19, 'value': "I am previous"}
     prop = {'proposalID': 17}
     self.assertEqual("NACK", acceptor.receivePropose(prop)['type'])
Exemplo n.º 4
0
 def test_acceptorReceivePropose_withNonePrevious(self):
     acceptor.minProposal = 5
     acceptor.accepted = {'proposalID': None, 'value': None}
     prop = {'proposalID': 17}
     self.assertEqual(acceptor.accepted, acceptor.receivePropose(prop))
Exemplo n.º 5
0
						connections.remove(s)

				if debug:
					print receivedData

				if "}" in receivedData:

					for data in receivedData.split("}"):
						if data != "":
							data += "}"

							# Else if we have received a propose-message, forward it to an acceptor 
							if data[0:8] == "PROPOSE:":
								result = data[8:]
								proposed = json.loads(result)
								reply = acceptor.receivePropose(proposed)
								s.send("ACK:"+json.dumps(reply))


							# Else if we have received an ACK-message, an acceptor has accepted our proposal,
							# forwards this to the proposer, which in turn broadcasts an accept-message if
							# it has the majority of the acceptors accept its proposal
							elif data[0:4] == "ACK:":
								result = data[4:]
								result = json.loads(result)
								reply = proposer.receivePromise(result)
								if reply == "RESTART":
									# In this case, propose your own value again, before others in queue
									proposemessage = json.dumps(proposer.prepare(proposer.myValue))
									broadcast("PROPOSE:"+proposemessage)
								# When majority is received, check if conflict has occured (previous proposal accepted,
Exemplo n.º 6
0
	def test_acceptorReceivePropose_withLowID(self):
		acceptor.minProposal = 19
		acceptor.accepted = {'proposalID' : 19, 'value' : "I am previous"}
		prop = {'proposalID' : 17}
		self.assertEqual("NACK", acceptor.receivePropose(prop)['type'])
Exemplo n.º 7
0
	def test_acceptorReceivePropose_withPreviousValues(self):
		acceptor.minProposal = 19
		acceptor.accepted = {'proposalID' : 19, 'value' : "I am previous"}
		prop = {'proposalID' : 20}
		self.assertEqual(acceptor.accepted, acceptor.receivePropose(prop))
Exemplo n.º 8
0
	def test_acceptorReceivePropose_withNonePrevious(self):
		acceptor.minProposal = 5
		acceptor.accepted = {'proposalID' : None, 'value' : None}
		prop = {'proposalID' : 17}
		self.assertEqual(acceptor.accepted, acceptor.receivePropose(prop))