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 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)
connection = None broker = None try: logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) # setup broker connection connection = Connection.establish('127.0.0.1') broker = BrokerAgent(connection) # add test service busname busname = 'test-lofarbus-%s' % (uuid.uuid1()) broker.addExchange('topic', busname) # the system under test is the service and the rpc, not the RADatabase # so, patch (mock) the RADatabase class during these tests. # when the service instantiates an RADatabase it will get the mocked class. with patch('lofar.sas.resourceassignment.database.radb.RADatabase', autospec=True) as MockRADatabase: mock = MockRADatabase.return_value # modify the return values of the various RADatabase methods with pre-cooked answers mock.getTaskStatuses.return_value = [{ 'id': 1, 'name': 'opened' }, { 'id': 2, 'name': 'scheduled' }]
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()
exit(3) connection = None broker = None try: logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) # setup broker connection connection = Connection.establish('127.0.0.1') broker = BrokerAgent(connection) # add test service busname busname = 'test-lofarbus-%s' % (uuid.uuid1()) broker.addExchange('topic', busname) # the system under test is the service and the rpc, not the RADatabase # so, patch (mock) the RADatabase class during these tests. # when the service instantiates an RADatabase it will get the mocked class. with patch('lofar.sas.resourceassignment.database.radb.RADatabase', autospec=True) as MockRADatabase: mock = MockRADatabase.return_value # modify the return values of the various RADatabase methods with pre-cooked answers mock.getTaskStatuses.return_value = [{'id': 1, 'name': 'opened'}, {'id': 2, 'name': 'scheduled'}] mock.getTaskTypes.return_value = [{'id': 0, 'name': 'OBSERVATION'}, {'id': 1, 'name': 'PIPELINE'}] mock.getResourceClaimStatuses.return_value = [{'id': 0, 'name': 'CLAIMED'},{'id': 1, 'name': 'ALLOCATED'},{'id': 2, 'name': 'CONFLICT'}] mock.getUnits.return_value = [{'units': 'rsp_channel_bit', 'id': 0},{'units': 'bytes', 'id': 1},{'units': 'rcu_board', 'id': 2},{'units': 'bytes/second', 'id': 3},{'units': 'cores', 'id': 4}] mock.getResourceTypes.return_value = [{'unit_id': 0, 'id': 0, 'unit': 'rsp_channel_bit', 'name': 'rsp'},{'unit_id': 1, 'id': 1, 'unit': 'bytes', 'name': 'tbb'},{'unit_id': 2, 'id': 2, 'unit': 'rcu_board', 'name': 'rcu'},{'unit_id': 3, 'id': 3, 'unit': 'bytes/second', 'name': 'bandwidth'},{'unit_id': 4, 'id': 4, 'unit': 'cores', 'name': 'processor'},{'unit_id': 1, 'id': 5, 'unit': 'bytes', 'name': 'storage'}] mock.getResourceGroupTypes.return_value = [{'id': 0, 'name': 'instrument'},{'id': 1, 'name': 'cluster'},{'id': 2, 'name': 'station_group'},{'id': 3, 'name': 'station'},{'id': 4, 'name': 'node_group'},{'id': 5, 'name': 'node'}] mock.getResources.return_value = [{'type_id': 0, 'type': 'rsp', 'id': 0, 'unit': 'rsp_channel_bit', 'name': 'rsp'},{'type_id': 1, 'type': 'tbb', 'id': 1, 'unit': 'bytes', 'name': 'tbb'},{'type_id': 2, 'type': 'rcu', 'id': 2, 'unit': 'rcu_board', 'name': 'rcu'},{'type_id': 3, 'type': 'bandwidth', 'id': 3, 'unit': 'bytes/second', 'name': 'bandwidth'}] mock.getResourceGroups.return_value = [{'type_id': 0, 'type': 'instrument', 'id': 0, 'name': 'LOFAR'},{'type_id': 1, 'type': 'cluster', 'id': 1, 'name': 'CEP2'}]