| 
									
										
										
										
											2010-10-06 19:16:40 +08:00
										 |  |  | import unittest | 
					
						
							|  |  |  | import stomp | 
					
						
							|  |  |  | import base | 
					
						
							|  |  |  | import time | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestLifecycle(base.BaseTest): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  |     def test_unsubscribe_exchange_destination(self): | 
					
						
							|  |  |  |         ''' Test UNSUBSCRIBE command with exchange''' | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         d = "/exchange/amq.fanout" | 
					
						
							|  |  |  |         self.unsub_test(d, self.sub_and_send(d)) | 
					
						
							| 
									
										
										
										
											2010-10-06 22:25:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  |     def test_unsubscribe_exchange_destination_with_receipt(self): | 
					
						
							|  |  |  |         ''' Test receipted UNSUBSCRIBE command with exchange''' | 
					
						
							|  |  |  |         d = "/exchange/amq.fanout" | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         self.unsub_test(d, self.sub_and_send(d, receipt="unsub.rct"), numRcts=1) | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  |     def test_unsubscribe_queue_destination(self): | 
					
						
							|  |  |  |         ''' Test UNSUBSCRIBE command with queue''' | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         d = "/queue/unsub01" | 
					
						
							|  |  |  |         self.unsub_test(d, self.sub_and_send(d)) | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  |     def test_unsubscribe_queue_destination_with_receipt(self): | 
					
						
							|  |  |  |         ''' Test receipted UNSUBSCRIBE command with queue''' | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         d = "/queue/unsub02" | 
					
						
							|  |  |  |         self.unsub_test(d, self.sub_and_send(d, receipt="unsub.rct"), numRcts=1) | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  |     def test_unsubscribe_exchange_id(self): | 
					
						
							|  |  |  |         ''' Test UNSUBSCRIBE command with exchange by id''' | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         d = "/exchange/amq.fanout" | 
					
						
							|  |  |  |         self.unsub_test(d, self.sub_and_send(d, subid="exchid")) | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  |     def test_unsubscribe_exchange_id_with_receipt(self): | 
					
						
							|  |  |  |         ''' Test receipted UNSUBSCRIBE command with exchange by id''' | 
					
						
							|  |  |  |         d = "/exchange/amq.fanout" | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         self.unsub_test(d, self.sub_and_send(d, subid="exchid", receipt="unsub.rct"), numRcts=1) | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 23:24:25 +08:00
										 |  |  |     def test_unsubscribe_queue_id(self): | 
					
						
							|  |  |  |         ''' Test UNSUBSCRIBE command with queue by id''' | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         d = "/queue/unsub03" | 
					
						
							|  |  |  |         self.unsub_test(d, self.sub_and_send(d, subid="queid")) | 
					
						
							| 
									
										
										
										
											2010-10-06 19:16:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  |     def test_unsubscribe_queue_id_with_receipt(self): | 
					
						
							|  |  |  |         ''' Test receipted UNSUBSCRIBE command with queue by id''' | 
					
						
							|  |  |  |         d = "/queue/unsub04" | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         self.unsub_test(d, self.sub_and_send(d, subid="queid", receipt="unsub.rct"), numRcts=1) | 
					
						
							| 
									
										
										
										
											2011-01-15 01:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 19:16:40 +08:00
										 |  |  |     def test_disconnect(self): | 
					
						
							|  |  |  |         ''' Run DISCONNECT command ''' | 
					
						
							|  |  |  |         self.conn.disconnect() | 
					
						
							|  |  |  |         self.assertFalse(self.conn.is_connected()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |     def unsub_test(self, dest, verbs, numRcts=0): | 
					
						
							|  |  |  |         def afterfun(): | 
					
						
							|  |  |  |             self.conn.send("after-test", destination=dest) | 
					
						
							| 
									
										
										
										
											2011-01-18 01:55:27 +08:00
										 |  |  |         subverb, unsubverb = verbs | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |         self.assertListenerAfter(subverb, numMsgs=1, | 
					
						
							|  |  |  |                            errMsg="FAILED to subscribe and send") | 
					
						
							|  |  |  |         self.assertListenerAfter(unsubverb, numRcts=numRcts,  | 
					
						
							|  |  |  |                            errMsg="Incorrect responses from UNSUBSCRIBE") | 
					
						
							|  |  |  |         self.assertListenerAfter(afterfun, | 
					
						
							| 
									
										
										
										
											2011-01-18 01:55:27 +08:00
										 |  |  |                            errMsg="Still receiving messages") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |     def sub_and_send(self, dest, subid="", receipt=""): | 
					
						
							| 
									
										
										
										
											2011-01-18 01:55:27 +08:00
										 |  |  |         def subfun(): | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |             if subid=="": | 
					
						
							|  |  |  |                 self.conn.subscribe(destination=dest) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 self.conn.subscribe(destination=dest, id=subid) | 
					
						
							| 
									
										
										
										
											2011-01-18 01:55:27 +08:00
										 |  |  |             self.conn.send("test", destination=dest) | 
					
						
							|  |  |  |         def unsubfun(): | 
					
						
							| 
									
										
										
										
											2011-01-18 20:46:28 +08:00
										 |  |  |             if subid=="" and receipt=="": | 
					
						
							|  |  |  |                 self.conn.unsubscribe(destination=dest) | 
					
						
							|  |  |  |             elif receipt=="": | 
					
						
							|  |  |  |                 self.conn.unsubscribe(id=subid) | 
					
						
							|  |  |  |             elif subid=="": | 
					
						
							|  |  |  |                 self.conn.unsubscribe(destination=dest, receipt=receipt) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 self.conn.unsubscribe(id=subid, receipt=receipt) | 
					
						
							| 
									
										
										
										
											2011-01-18 01:55:27 +08:00
										 |  |  |         return subfun, unsubfun |