def test_endRoute(self): "Test the msg_endRoute method" sourceLink = Tracer() for payerLink, payeeLink in ((None, sourceLink), (sourceLink, None)): self.makeNewTransaction(payerLink=payerLink, payeeLink=payeeLink) #First try a route: self.transaction.msg_makeRoute() #Then end it: self.routingContext.links[0].trace = [] self.routingContext.links[1].trace = [] sourceLink.trace = [] self.transaction.msg_endRoute() self.assertEqual(self.routingContext.links[0].trace, [('msg_endRoute', (self.transaction,), {})] ) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(sourceLink.trace, []) #Then end it again (should be a NOP): self.routingContext.links[0].trace = [] self.transaction.msg_endRoute() self.assertEqual(self.routingContext.links[0].trace, []) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(sourceLink.trace, [])
def test_lock(self): "Test the msg_lock method" payerLink = Tracer() payeeLink = Tracer() self.makeNewTransaction(payerLink=payerLink, payeeLink=None) self.transaction.msg_haveRoute(payeeLink, 123, 456) payerLink.trace = [] payeeLink.trace = [] self.transaction.msg_lock() self.assertEqual(payerLink.trace, []) self.assertEqual(payeeLink.trace, [('msg_lock', (self.transaction,), {})] )
def test_requestCommit(self): "Test the msg_requestCommit method" payerLink = Tracer() payeeLink = Tracer() self.makeNewTransaction(payerLink=payerLink, payeeLink=None) self.transaction.msg_haveRoute(payeeLink, 123, 456) payerLink.trace = [] payeeLink.trace = [] self.transaction.msg_requestCommit("token") self.assertEqual(self.transaction.token, "token") self.assertEqual(payeeLink.trace, []) self.assertEqual(payerLink.trace, [('msg_requestCommit', (self.transaction,), {})] )
def test_makeRoute(self): "Test the msg_makeRoute method" sourceLink = Tracer() for payerLink, payeeLink in ((None, sourceLink), (sourceLink, None)): self.routingContext.links[0].trace = [] self.routingContext.links[1].trace = [] sourceLink.trace = [] self.routingContext.meetingPoints = \ [DummyMeetingPoint("NoMeetingPoint"), DummyMeetingPoint("meetingPoint")] self.makeNewTransaction(payerLink=payerLink, payeeLink=payeeLink) #Routed to meeting point: self.transaction.msg_makeRoute() self.assertEqual(self.routingContext.meetingPoints[0].trace, []) self.assertEqual(self.routingContext.meetingPoints[1].trace, [('msg_makeRoute', (self.transaction,), {})] ) self.assertEqual(self.routingContext.links[0].trace, []) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(sourceLink.trace, []) self.routingContext.meetingPoints = [] self.makeNewTransaction(payerLink=payerLink, payeeLink=payeeLink) #Routed to first link: self.transaction.msg_makeRoute() self.assertEqual(self.routingContext.links[0].trace, [('msg_makeRoute', (self.transaction,), {})] ) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(sourceLink.trace, []) self.routingContext.links[0].trace = [] #Skip route to second link: self.transaction.msg_makeRoute(sourceLinkID="link2") self.assertEqual(self.routingContext.links[0].trace, []) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(self.routingContext.links[2].trace, [('msg_makeRoute', (self.transaction,), {})] ) self.assertEqual(sourceLink.trace, []) self.routingContext.links[2].trace = [] #Remove the last link: lastlink = self.routingContext.links[-1] del self.routingContext.links[-1] #No more route: self.transaction.msg_makeRoute() self.assertEqual(self.routingContext.links[0].trace, []) self.assertEqual(self.routingContext.links[1].trace, []) self.assertEqual(sourceLink.trace, [ ('msg_haveNoRoute', (self.transaction,), {}) ] ) #Place the last Link back: self.routingContext.links.append(lastlink)