def test_08a_test_strip_message_annotations_no_add_trace(self): addr = "amqp:/strip_message_annotations_no_add_trace/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[1] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[1] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address( "strip_message_annotations_no_add_trace/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## ## Pre-existing ingress and trace ## #ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1']} ingress_message_annotations = {'x-opt-qd.trace': ['0/QDR.1']} ingress_message.annotations = ingress_message_annotations ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR.A') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.1', '0/QDR.A', '0/QDR.B']) M1.stop() M2.stop()
def test_custom_annotations_match(self): """ The linkRoute on Routers C and B is set to org.apache. Creates a receiver listening on the address 'org.apache' and a sender that sends to address 'org.apache'. Sends a message with custom annotations to org.apache via router QDR.C and makes sure that the message was successfully routed (using full address matching) and received using pre-created links that were created as a result of specifying addresses in the linkRoute attribute('org.apache.'). Make sure custom annotations arrived as well. """ hello_world_3 = "Hello World_3!" # Connects to listener #2 on QDR.C addr = self.routers[2].addresses[0] blocking_connection = BlockingConnection(addr) # Receive on org.apache blocking_receiver = blocking_connection.create_receiver(address="org.apache") apply_options = AtMostOnce() # Sender to to org.apache blocking_sender = blocking_connection.create_sender(address="org.apache", options=apply_options) msg = Message(body=hello_world_3) annotations = {'custom-annotation': '1/Custom_Annotation'} msg.annotations = annotations # Send a message blocking_sender.send(msg) received_message = blocking_receiver.receive() self.assertEqual(hello_world_3, received_message.body) self.assertEqual(received_message.annotations, annotations) blocking_connection.close()
def test_13_to_override(self): addr = self.address+"/toov/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() tm.address = addr ## ## Pre-existing TO ## tm.annotations = {'x-opt-qd.to': 'toov/1'} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.to'], 'toov/1') M1.stop() M2.stop()
def test_13_to_override(self): addr = self.address + "/toov/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() tm.address = addr ## ## Pre-existing TO ## tm.annotations = {'x-opt-qd.to': 'toov/1'} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.to'], 'toov/1') M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_both_custom(self): addr = self.router.addresses[2] + "/strip_message_annotations_both/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # Only annotations with prefix "x-opt-qd." will be stripped ingress_message_annotations = {'stay': 'humble', 'x-opt-qd': 'work'} ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) self.assertEqual(egress_message.annotations, ingress_message_annotations) M1.stop() M2.stop()
def test_16_delivery_annotations(self): addr = "amqp:/delivery_annotations.1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[0]+"/$1") M2.route("amqp:/*", self.routers[1].addresses[0]+"/$1") M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() self.routers[0].wait_address("delivery_annotations.1", 0, 1) tm.annotations = {'a1': 'a1', 'b1': 'b2'} tm.address = addr tm.instructions = {'work': 'hard', 'stay': 'humble'} tm.body = {'number': 38} M1.put(tm) M1.send() M2.recv(1) M2.get(rm) self.assertEqual(38, rm.body['number']) M1.stop() M2.stop()
def on_sendable(self, event): if self.msg_not_sent: msg = Message(body={'number': 0}) ingress_message_annotations = {'work': 'hard', 'stay': 'humble'} msg.annotations = ingress_message_annotations event.sender.send(msg) self.msg_not_sent = False
def on_sendable(self, event): if self.msg_not_sent: msg = Message(body={'number': 0}) ingress_message_annotations = {'x-opt-qd.trace': ['0/QDR.1']} msg.annotations = ingress_message_annotations event.sender.send(msg) self.msg_not_sent = False
def test_16_delivery_annotations(self): addr = "amqp:/delivery_annotations.1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[0] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[0] + "/$1") M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() self.routers[0].wait_address("delivery_annotations.1", 0, 1) tm.annotations = {'a1': 'a1', 'b1': 'b2'} tm.address = addr tm.instructions = {'work': 'hard', 'stay': 'humble'} tm.body = {'number': 38} M1.put(tm) M1.send() M2.recv(1) M2.get(rm) self.assertEqual(38, rm.body['number']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_both_custom(self): addr = self.router.addresses[2]+"/strip_message_annotations_both/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # Only annotations with prefix "x-opt-qd." will be stripped ingress_message_annotations = {'stay': 'humble', 'x-opt-qd': 'work'} ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) self.assertEqual(egress_message.annotations, ingress_message_annotations) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_out_timeout(self): addr = self.router.addresses[3]+"/strip_message_annotations_out_timeout/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.timeout = 0.5 M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = {'x-opt-qd.ingress': '0/QDR', 'x-opt-qd.trace': ['0/QDR']} ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() timed_out = False try: # Receive the message, this should timeout because the router thinks that this message has looped. M2.recv(1) except Timeout: timed_out = True self.assertTrue(timed_out) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_no_add_trace(self): addr = "amqp:/strip_message_annotations_no_add_trace/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[1]+"/$1") M2.route("amqp:/*", self.routers[1].addresses[1]+"/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_no_add_trace/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## ## Pre-existing ingress and trace ## #ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1']} ingress_message_annotations = {'x-opt-qd.trace': ['0/QDR.1']} ingress_message.annotations = ingress_message_annotations ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR.A') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.1', '0/QDR.A', '0/QDR.B']) M1.stop() M2.stop()
def on_sendable(self, event): if self.msg_not_sent: msg = Message(body={'number': 0}) # # Pre-existing ingress and trace # ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['X/QDR']} msg.annotations = ingress_message_annotations event.sender.send(msg) self.msg_not_sent = False
def on_sendable(self, event): if self.msg_not_sent: msg = Message(body={'number': 0}) ingress_message_annotations = {'work': 'hard', 'x-opt-qd': 'humble', 'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.A']} msg.annotations = ingress_message_annotations event.sender.send(msg) self.msg_not_sent = False
def test_08a_test_strip_message_annotations_both_add_ingress_trace(self): addr = "amqp:/strip_message_annotations_both_add_ingress_trace/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[2] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[2] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address( "strip_message_annotations_both_add_ingress_trace/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## # Pre-existing ingress and trace. Intentionally populate the trace with the 0/QDR.A which is the trace # of the first router. If the inbound annotations were not stripped, the router would drop this message # since it would consider this message as being looped. # ingress_message_annotations = { 'work': 'hard', 'x-opt-qd': 'humble', 'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.A'] } ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Router specific annotations (annotations with prefix "x-opt-qd.") will be stripped. User defined annotations will not be stripped. self.assertEqual(egress_message.annotations, { 'work': 'hard', 'x-opt-qd': 'humble' }) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_no_add_trace(self): addr = self.router.addresses[ 1] + "/strip_message_annotations_no_add_trace/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # # Pre-existing ingress and trace # ingress_message_annotations = { 'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1'], 'work': 'hard' } ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], 'ingress-router') # Make sure the user defined annotation also makes it out. self.assertEqual(egress_message_annotations['work'], 'hard') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.1', '0/QDR']) M1.stop() M2.stop()
def test_08a_strip_message_annotations_custom(self): addr = "amqp:/message_annotations_strip_no_custom/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[1] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[1] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("message_annotations_strip_no_custom/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = {} ingress_message_annotations[ 'custom-annotation'] = '1/Custom_Annotation' ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['custom-annotation'], '1/Custom_Annotation') self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR.A') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.A', '0/QDR.B']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_in(self): addr = self.router.addresses[4] + "/strip_message_annotations_in/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## ## Pre-existing ingress and trace ## ingress_message_annotations = { 'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1'] } ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_out_custom(self): addr = "amqp:/strip_message_annotations_out/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[3] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[3] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_out/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # Annotations with prefix "x-opt-qd." will be skipped ingress_message_annotations = { 'work': 'hard', "x-opt-qd": "custom", "x-opt-qd.": "custom" } ingress_message.annotations = ingress_message_annotations # Put and send the message M1.put(ingress_message) M1.send() # Receive the message egress_message = Message() M2.recv(1) M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) self.assertEqual(egress_message.annotations, { 'work': 'hard', "x-opt-qd": "custom" }) M1.stop() M2.stop()
def notest_08a_test_strip_message_annotations_no_custom_not_implemented(self): addr = "amqp:/message_annotations_strip_no_custom/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[1]+"/$1") M2.route("amqp:/*", self.routers[1].addresses[1]+"/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("message_annotations_strip_no_custom/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = {} ingress_message_annotations['custom-annotation'] = '1/Custom_Annotation' ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['custom-annotation'], '1/Custom_Annotation') self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR.A') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.A', '0/QDR.B']) M1.stop() M2.stop()
def notest_08a_test_strip_message_annotations_no_custom_not_implemented( self): addr = self.router.addresses[ 1] + "/strip_message_annotations_no_custom/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = {} ingress_message_annotations[ 'custom-annotation'] = '1/Custom_Annotation' ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['custom-annotation'], '1/Custom_Annotation') self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_both_add_ingress_trace(self): addr = "amqp:/strip_message_annotations_both_add_ingress_trace/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[2]+"/$1") M2.route("amqp:/*", self.routers[1].addresses[2]+"/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_both_add_ingress_trace/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## # Pre-existing ingress and trace. Intentionally populate the trace with the 0/QDR.A which is the trace # of the first router. If the inbound annotations were not stripped, the router would drop this message # since it would consider this message as being looped. # ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.A'], 'work': 'hard', 'x-opt-qd': 'humble'} ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Router specific annotations (annotations with prefix "x-opt-qd.") will be stripped. User defined annotations will not be stripped. self.assertEqual(egress_message.annotations, {'work': 'hard', 'x-opt-qd': 'humble'}) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_in(self): addr = "amqp:/strip_message_annotations_in/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[4] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[4] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_in/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {"message": "Hello World!"} ## ## Pre-existing ingress and trace ## ingress_message_annotations = {"x-opt-qd.ingress": "ingress-router", "x-opt-qd.trace": ["X/QDR"]} ingress_message.annotations = ingress_message_annotations # Put and send the message M1.put(ingress_message) M1.send() # Receive the message egress_message = Message() M2.recv(1) M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual("Hello World!", egress_message.body["message"]) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations["x-opt-qd.ingress"], "0/QDR.A") self.assertEqual(egress_message_annotations["x-opt-qd.trace"], ["0/QDR.A", "0/QDR.B"]) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_no_add_trace(self): addr = self.router.addresses[1]+"/strip_message_annotations_no_add_trace/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # # Pre-existing ingress and trace # ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1'], 'work': 'hard'} ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], 'ingress-router') # Make sure the user defined annotation also makes it out. self.assertEqual(egress_message_annotations['work'], 'hard') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR.1', '0/QDR']) M1.stop() M2.stop()
def notest_08a_test_strip_message_annotations_no_custom_not_implemented(self): addr = "amqp:/message_annotations_strip_no_custom/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[1] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[1] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("message_annotations_strip_no_custom/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {"message": "Hello World!"} ingress_message_annotations = {} ingress_message_annotations["custom-annotation"] = "1/Custom_Annotation" ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual("Hello World!", egress_message.body["message"]) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations["custom-annotation"], "1/Custom_Annotation") self.assertEqual(egress_message_annotations["x-opt-qd.ingress"], "0/QDR.A") self.assertEqual(egress_message_annotations["x-opt-qd.trace"], ["0/QDR.A", "0/QDR.B"]) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_in(self): addr = self.router.addresses[4]+"/strip_message_annotations_in/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ## ## Pre-existing ingress and trace ## ingress_message_annotations = {'x-opt-qd.ingress': 'ingress-router', 'x-opt-qd.trace': ['0/QDR.1']} ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) #Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_both_add_ingress_trace(self): addr = "amqp:/strip_message_annotations_both_add_ingress_trace/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[2] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[2] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_both_add_ingress_trace/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {"message": "Hello World!"} ## ## Pre-existing ingress and trace. Intentionally populate the trace with the 0/QDR.A which is the trace of the first router. ## If the inbound annotations were not stripped, the router would drop this message since it would consider this message as being looped. ## ingress_message_annotations = {"x-opt-qd.ingress": "ingress-router", "x-opt-qd.trace": ["0/QDR.A"]} ingress_message.annotations = ingress_message_annotations # Put and send the message M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) self.assertEqual(egress_message.annotations, None) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_out_custom(self): addr = "amqp:/strip_message_annotations_out/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[3]+"/$1") M2.route("amqp:/*", self.routers[1].addresses[3]+"/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("strip_message_annotations_out/1", 0, 1) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} # Annotations with prefix "x-opt-qd." will be skipped ingress_message_annotations = {'work': 'hard', "x-opt-qd": "custom", "x-opt-qd.": "custom"} ingress_message.annotations = ingress_message_annotations # Put and send the message M1.put(ingress_message) M1.send() # Receive the message egress_message = Message() M2.recv(1) M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) self.assertEqual(egress_message.annotations, {'work': 'hard', "x-opt-qd": "custom"}) M1.stop() M2.stop()
def test_08a_strip_message_annotations_custom(self): addr = self.router.addresses[1]+"/strip_message_annotations_no_custom/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = {} ingress_message_annotations['custom-annotation'] = '1/Custom_Annotation' ingress_message.annotations = ingress_message_annotations M1.put(ingress_message) M1.send() # Receive the message M2.recv(1) egress_message = Message() M2.get(egress_message) # Make sure 'Hello World!' is in the message body dict self.assertEqual('Hello World!', egress_message.body['message']) egress_message_annotations = egress_message.annotations self.assertEqual(egress_message_annotations.__class__, dict) self.assertEqual(egress_message_annotations['custom-annotation'], '1/Custom_Annotation') self.assertEqual(egress_message_annotations['x-opt-qd.ingress'], '0/QDR') self.assertEqual(egress_message_annotations['x-opt-qd.trace'], ['0/QDR']) M1.stop() M2.stop()
def test_08a_test_strip_message_annotations_out_timeout(self): addr = self.router.addresses[ 3] + "/strip_message_annotations_out_timeout/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.timeout = 0.5 M2.subscribe(addr) ingress_message = Message() ingress_message.address = addr ingress_message.body = {'message': 'Hello World!'} ingress_message_annotations = { 'x-opt-qd.ingress': '0/QDR', 'x-opt-qd.trace': ['0/QDR'] } ingress_message.annotations = ingress_message_annotations #Put and send the message M1.put(ingress_message) M1.send() timed_out = False try: # Receive the message, this should timeout because the router thinks that this message has looped. M2.recv(1) except Timeout: timed_out = True self.assertTrue(timed_out) M1.stop() M2.stop()
def test_13_to_override(self): addr = "amqp:/toov/1" M1 = self.messenger() M2 = self.messenger() M1.route("amqp:/*", self.routers[0].addresses[0] + "/$1") M2.route("amqp:/*", self.routers[1].addresses[0] + "/$1") M1.start() M2.start() M2.subscribe(addr) self.routers[0].wait_address("toov/1", 0, 1) tm = Message() rm = Message() tm.address = addr ## ## Pre-existing TO ## tm.annotations = {"x-opt-qd.to": "toov/1"} for i in range(10): tm.body = {"number": i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body["number"]) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma["x-opt-qd.to"], "toov/1") M1.stop() M2.stop()
def do_send(self, sender): for i in range(self.msg_count): msg = Message(body=" %s -> %s:%s" % (sender.name, i, self.body)) msg.annotations = self._huge_ma dlv = sender.send(msg) self.n_sent += 1
def test_08_message_annotations(self): addr = self.address+"/ma/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() tm.address = addr # # No inbound delivery annotations # for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Pre-existing ingress # tm.annotations = {'x-opt-qd.ingress': 'ingress-router'} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], 'ingress-router') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Invalid trace type # tm.annotations = {'x-opt-qd.trace' : 45} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Empty trace # tm.annotations = {'x-opt-qd.trace' : []} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Non-empty trace # tm.annotations = {'x-opt-qd.trace' : ['0/first.hop']} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/first.hop', '0/QDR']) M1.stop() M2.stop()
def test_08_message_annotations(self): addr = self.address + "/ma/1" M1 = self.messenger() M2 = self.messenger() M1.start() M2.start() M2.subscribe(addr) tm = Message() rm = Message() tm.address = addr # # No inbound delivery annotations # for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Pre-existing ingress # tm.annotations = {'x-opt-qd.ingress': 'ingress-router'} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], 'ingress-router') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Invalid trace type # tm.annotations = {'x-opt-qd.trace': 45} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Empty trace # tm.annotations = {'x-opt-qd.trace': []} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/QDR']) # # Non-empty trace # tm.annotations = {'x-opt-qd.trace': ['0/first.hop']} for i in range(10): tm.body = {'number': i} M1.put(tm) M1.send() for i in range(10): M2.recv(1) M2.get(rm) self.assertEqual(i, rm.body['number']) ma = rm.annotations self.assertEqual(ma.__class__, dict) self.assertEqual(ma['x-opt-qd.ingress'], '0/QDR') self.assertEqual(ma['x-opt-qd.trace'], ['0/first.hop', '0/QDR']) M1.stop() M2.stop()
def on_sendable(self, event): if self.msg_not_sent: msg = Message(body={'number': 0}) msg.annotations = {'x-opt-qd.to': 'toov/1'} event.sender.send(msg) self.msg_not_sent = False