def _node_disambiguation_precreated(self, ambiguous_send): agent = BrokerAgent(self.conn) agent.addExchange("fanout", "ambiguous") agent.addQueue("ambiguous") try: r1 = self.ssn.receiver("ambiguous; {node:{type:topic}}") r2 = self.ssn.receiver("ambiguous; {node:{type:queue}}") self._node_disambiguation_test(r1, r2, ambiguous_send=ambiguous_send) finally: agent.delExchange("ambiguous") agent.delQueue("ambiguous", False, False)
def test_ambiguous_delete_2(self): agent = BrokerAgent(self.conn) agent.addExchange("fanout", "ambiguous") agent.addQueue("ambiguous") self.ssn.receiver("ambiguous; {delete:receiver, node:{type:queue}}").close() exchange = agent.getExchange("ambiguous") queue = agent.getQueue("ambiguous") try: assert(exchange) assert(not queue) finally: if exchange: agent.delExchange("ambiguous") if queue: agent.delQueue("ambiguous", False, False)
def _node_disambiguation_precreated(self, ambiguous_send): agent = BrokerAgent(self.conn) agent.addExchange("fanout", "ambiguous") agent.addQueue("ambiguous") try: r1 = self.ssn.receiver("ambiguous; {node:{type:topic}}") r2 = self.ssn.receiver("ambiguous; {node:{type:queue}}") self._node_disambiguation_test(r1, r2, ambiguous_send=ambiguous_send) finally: agent.delExchange("ambiguous") agent.delQueue("ambiguous", False, False)
def test_ambiguous_create_2(self): #create exchange first, then queue r1 = self.ssn.receiver("ambiguous; {create:receiver, node:{type:topic}}") r2 = self.ssn.receiver("ambiguous; {create:receiver, node:{type:queue}}") agent = BrokerAgent(self.conn) exchange = agent.getExchange("ambiguous") queue = agent.getQueue("ambiguous") try: assert(exchange) assert(queue) self._node_disambiguation_test(r1, r2) finally: if exchange: agent.delExchange("ambiguous") if queue: agent.delQueue("ambiguous", False, False)
def test_ambiguous_delete_2(self): agent = BrokerAgent(self.conn) agent.addExchange("fanout", "ambiguous") agent.addQueue("ambiguous") self.ssn.receiver( "ambiguous; {delete:receiver, node:{type:queue}}").close() exchange = agent.getExchange("ambiguous") queue = agent.getQueue("ambiguous") try: assert (exchange) assert (not queue) finally: if exchange: agent.delExchange("ambiguous") if queue: agent.delQueue("ambiguous", False, False)
def test_ambiguous_create_2(self): #create exchange first, then queue r1 = self.ssn.receiver( "ambiguous; {create:receiver, node:{type:topic}}") r2 = self.ssn.receiver( "ambiguous; {create:receiver, node:{type:queue}}") agent = BrokerAgent(self.conn) exchange = agent.getExchange("ambiguous") queue = agent.getQueue("ambiguous") try: assert (exchange) assert (queue) self._node_disambiguation_test(r1, r2) finally: if exchange: agent.delExchange("ambiguous") if queue: agent.delQueue("ambiguous", False, False)
#self.assertEqual(mock.getTask.return_value, rpc.getTask(5)) # test non existing service method, should timeout with self.assertRaises(ValueError) as cm: rpc.rpc('foo', timeout=1) self.assertEqual( cm.exception.message, "{'backtrace': '', 'state': 'TIMEOUT', 'errmsg': 'RPC Timed out'}" ) ## test method with wrong args #with self.assertRaises(TypeError) as cm: #rpc.rpc('GetTasks', timeout=1, fooarg='bar') #self.assertTrue('got an unexpected keyword argument \'fooarg\'' in cm.exception.message) # create and run the service with createService(busname=busname): # and run all tests unittest.main(verbosity=2) except ConnectError as ce: logger.error(ce) exit(3) finally: # cleanup test bus and exit if broker: broker.delExchange(busname) if connection: connection.close()
def test_08_integration_test_with_messagebus(self): """ Full blown integration test listening for notifications on the bus, and checking which dir is up for a visit next. Needs a working local qpid broker. Test is skipped if qpid not available. """ try: broker = None connection = None import uuid from threading import Event from qpid.messaging import Connection, ConnectError from qpidtoollibs import BrokerAgent from lofar.messaging.messagebus import ToBus from lofar.messaging.messages import EventMessage from lofar.lta.ingest.common.config import DEFAULT_INGEST_NOTIFICATION_PREFIX # setup broker connection connection = Connection.establish('127.0.0.1') broker = BrokerAgent(connection) # add test service bus busname = 'test-LTASOIngestEventHandler-%s' % (uuid.uuid1()) broker.addExchange('topic', busname) sync_event = Event() class SyncedLTASOIngestEventHandler(LTASOIngestEventHandler): """This derived LTASOIngestEventHandler behaves exactly like the normal object under test LTASOIngestEventHandler, but it also sets a sync_event to sync between the listener thread and this main test thread""" def _handleMessage(self, msg): super(SyncedLTASOIngestEventHandler, self)._handleMessage(msg) sync_event.set() with SyncedLTASOIngestEventHandler(self.dbcreds, busname=busname): for site in self.db.sites(): for root_dir in self.db.rootDirectoriesForSite(site['id']): self._markAllDirectoriesRecentlyVisited() # create the subdir surl sub_dir_name = '/foo' sub_dir_path = root_dir['dir_name'] + sub_dir_name surl = site['url'] + sub_dir_path with ToBus(busname) as sender: msg = EventMessage( subject=DEFAULT_INGEST_NOTIFICATION_PREFIX + "TaskFinished", content={'srm_url': surl}) sender.send(msg) # wait for the handler to have processed the message self.assertTrue(sync_event.wait(2)) sync_event.clear() # surl should have been scheduled for a visit, all other dir's were marked as visited already... # so there should be a new dir for this surl, and it should be the least_recent_visited_dir site_visit_stats = self.db.visitStats( datetime.utcnow())[site['name']] least_recent_visited_dir_id = site_visit_stats.get( 'least_recent_visited_dir_id') self.assertIsNotNone(least_recent_visited_dir_id) least_recent_visited_dir = self.db.directory( least_recent_visited_dir_id) self.assertEqual(sub_dir_path, least_recent_visited_dir['dir_name']) except ImportError as e: logger.warning("skipping test due to: %s", e) except ConnectError as e: logger.warning("skipping test due to: %s", e) finally: # cleanup test bus and exit if broker: broker.delExchange(busname) if connection: connection.close()
#TODO: fix this test #self.assertEqual(None, rpc.getTask(1)) #self.assertEqual(mock.getTask.return_value, rpc.getTask(5)) # test non existing service method, should timeout with self.assertRaises(ValueError) as cm: rpc.rpc('foo', timeout=1) self.assertEqual(cm.exception.message, "{'backtrace': '', 'state': 'TIMEOUT', 'errmsg': 'RPC Timed out'}") ## test method with wrong args #with self.assertRaises(TypeError) as cm: #rpc.rpc('GetTasks', timeout=1, fooarg='bar') #self.assertTrue('got an unexpected keyword argument \'fooarg\'' in cm.exception.message) # create and run the service with createService(busname=busname): # and run all tests unittest.main(verbosity=2) except ConnectError as ce: logger.error(ce) exit(3) finally: # cleanup test bus and exit if broker: broker.delExchange(busname) if connection: connection.close()