Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testSendMsgP2PPY(self):
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(p2pRecvMsgBehav("p2ppy"),t)
self.a.addBehaviour(p2pSendMsgBehav("p2ppy"),None)
counter = 0
while self.b.msg == None and counter < 10:
time.sleep(1)
counter += 1
self.assertNotEqual(self.b.msg,None)
self.assertEqual(self.b.msg.getContent(),"testSendMsg")
self.assertEqual(self.b.msg.getSender(), self.Aaid)
self.assertEqual(len(self.b.msg.getReceivers()),1)
self.assertEqual(self.b.msg.getReceivers()[0], self.Baid)
self.assertEqual(self.b.msg._attrs["method"],"p2ppy")
def testSendAndRecvMsgP2PPY(self):
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(p2pAnswerMsgBehav("p2ppy"),t)
template.setSender(self.Baid)
t = spade.Behaviour.MessageTemplate(template)
self.a.addBehaviour(p2pSendAndRecvMsgBehav("p2ppy"),t)
counter = 0
while self.a.msg == None and counter < 20:
time.sleep(1)
counter += 1
self.assertNotEqual(self.a.msg,None)
self.assertEqual(self.a.msg.getContent(),"testSendAndRecvMsg")
self.assertEqual(self.a.msg._attrs["method"],"p2ppy")
def testSendMultiMsgP2P(self):
nmsg=100
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(p2pRecvMultiMsgBehav("p2p",nmsg),t)
self.a.addBehaviour(p2pSendMultiMsgBehav("p2p",nmsg),None)
counter = 0
while self.b.msg == None and counter < 10:
time.sleep(1)
counter += 1
self.assertEqual(self.b.receivedmsg,nmsg)
self.assertNotEqual(self.b.msg,None)
self.assertEqual(self.b.msg._attrs["method"],"p2p")
self.assertEqual(self.b.errorTag,[])
self.assertEqual(self.a.routeTag,[])
def testSendMultiMsgP2PPY(self):
nmsg=100
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(p2pRecvMultiMsgBehav("p2ppy",nmsg),t)
self.a.addBehaviour(p2pSendMultiMsgBehav("p2ppy",nmsg),None)
counter = 0
while self.b.msg == None and counter < 10:
time.sleep(1)
counter += 1
self.assertNotEqual(self.b.msg,None)
self.assertEqual(self.b.msg._attrs["method"],"p2ppy")
self.assertEqual(self.b.receivedmsg,nmsg)
self.assertEqual(self.b.errorTag,[])
self.assertEqual(self.a.routeTag,[])
def testSendAndRecvMsg(self):
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(AnswerMsgBehav(),t)
template.setSender(self.Baid)
t = spade.Behaviour.MessageTemplate(template)
self.a.addBehaviour(SendAndRecvMsgBehav(),t)
counter = 0
while self.a.msg == None and counter < 20:
time.sleep(1)
counter += 1
self.assertNotEqual(self.a.msg,None)
self.assertEqual(self.a.msg.getContent(),"testSendAndRecvMsg")
def testSendAndRecvMsgP2P(self):
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(p2pAnswerMsgBehav("p2p"),t)
template.setSender(self.Baid)
t = spade.Behaviour.MessageTemplate(template)
self.a.addBehaviour(p2pSendAndRecvMsgBehav("p2p"),t)
counter = 0
while self.a.msg == None and counter < 20:
time.sleep(1)
counter += 1
self.assertNotEqual(self.a.msg,None)
self.assertEqual(self.a.msg.getContent(),"testSendAndRecvMsg")
self.assertEqual(self.a.msg._attrs["method"],"p2p")
def testSendMsg(self):
template = spade.Behaviour.ACLTemplate()
template.setSender(self.Aaid)
t = spade.Behaviour.MessageTemplate(template)
self.b.addBehaviour(RecvMsgBehav(),t)
self.a.addBehaviour(SendMsgBehav(),None)
counter = 0
while self.b.msg == None and counter < 10:
time.sleep(1)
counter += 1
self.assertNotEqual(self.b.msg,None)
self.assertEqual(self.b.msg.getContent(),"testSendMsg")
self.assertEqual(self.b.msg.getSender(), self.Aaid)
self.assertEqual(len(self.b.msg.getReceivers()),1)
self.assertEqual(self.b.msg.getReceivers()[0], self.Baid)
def _setup(self):
self.crearBaraja()
self.revolucion = False
# Preparamos la plantilla para el comportamiento inicial
template = spade.Behaviour.ACLTemplate()
template.setOntology("Dalmuti")
template.setPerformative("request")
template.setConversationId("Inicio")
mt = spade.Behaviour.MessageTemplate(template)
insBhv = self.inscripcionBehav()
self.addBehaviour(insBhv, mt)
# Preparamos la plantilla para asignar roles
template.setConversationId("Carta")
mt = spade.Behaviour.MessageTemplate(template)
rolBhv = self.rolInicialBehav()
self.addBehaviour(rolBhv, mt)