def test_stage_parent_pipeline_assignment(self, mocked_init, l, i, b): s = Stage() data_type = [l, i, b] for data in data_type: with self.assertRaises(TypeError): s.parent_pipeline = data s = Stage() data = {'test': 'pipeline.0000'} s.parent_pipeline = data self.assertEqual(s._p_pipeline, {'test': 'pipeline.0000'})
def test_stage_parent_pipeline_assignment(l, i, b): s = Stage() data_type = [l, i, b] for data in data_type: with pytest.raises(TypeError): s.parent_pipeline = data
def test_sync_with_master(self, mocked_init, mocked_Logger, mocked_Profiler): # -------------------------------------------------------------------------- # def component_execution(packets, conn_params, queue): tmgr = BaseTmgr(None, None, None, None, None, None) tmgr._log = mocked_Logger tmgr._prof = mocked_Profiler mq_connection2 = pika.BlockingConnection(rmq_conn_params) mq_channel2 = mq_connection2.channel() for obj_type, obj, in packets: tmgr._sync_with_master(obj, obj_type, mq_channel2, conn_params, queue) if mq_channel2.is_open: mq_channel2.close() task = Task() task.parent_stage = {'uid':'stage.0000', 'name': 'stage.0000'} packets = [('Task', task)] stage = Stage() stage.parent_pipeline = {'uid':'pipe.0000', 'name': 'pipe.0000'} packets.append(('Stage', stage)) hostname = os.environ.get('RMQ_HOSTNAME', 'localhost') port = int(os.environ.get('RMQ_PORT', '5672')) username = os.environ.get('RMQ_USERNAME','guest') password = os.environ.get('RMQ_PASSWORD','guest') credentials = pika.PlainCredentials(username, password) rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port, credentials=credentials) mq_connection = pika.BlockingConnection(rmq_conn_params) mq_channel = mq_connection.channel() mq_channel.queue_declare(queue='master') master_thread = mt.Thread(target=component_execution, name='tmgr_sync', args=(packets, rmq_conn_params, 'master')) master_thread.start() time.sleep(1) try: while packets: packet = packets.pop(0) _, _, body = mq_channel.basic_get(queue='master') msg = json.loads(body) self.assertEqual(msg['object'], packet[1].to_dict()) self.assertEqual(msg['type'], packet[0]) except Exception as ex: print(ex) print(json.loads(body)) master_thread.join() mq_channel.queue_delete(queue='master') mq_channel.close() mq_connection.close() raise ex else: master_thread.join() mq_channel.queue_delete(queue='master') mq_channel.close() mq_connection.close()