Ejemplo n.º 1
0
                                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,
                                # 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:":
Ejemplo n.º 2
0
								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,
								# 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
Ejemplo n.º 3
0
 def test_Post(self):
     global proposer
     blogpost = "test"
     proposal = {'senderID': 3, 'proposalID': 13}
     self.assertEqual(proposal, proposer.prepare(blogpost))
Ejemplo n.º 4
0
	def test_Post(self):
		global proposer
		blogpost = "test"
		proposal = {'senderID': 3, 'proposalID' : 13}
		self.assertEqual(proposal, proposer.prepare(blogpost))