def test_product_data_producer_func_one_return_multiple_fis_multiple_results( test_context): # Given return_data1 = [ dict(AccountNumber="99999", test_value="test"), dict(AccountNumber="5431", test_value="test2"), dict(AccountNumber="99999", test_value="test3"), dict(AccountNumber="5431", test_value="test4") ] producer = ProductDataProducer(test_context) producer.client.set_access_token = MagicMock() producer.client.fetch_product_data = MagicMock(side_effect=[(return_data1, False)]) test_queue = get_queue_interface('memory')() expected1 = dict(job_type=QueueKeys.PRODUCT_DATA, payload=dict( fi_id="99999", product_data=[return_data1[0], return_data1[2]])) expected2 = dict(job_type=QueueKeys.PRODUCT_DATA, payload=dict( fi_id="5431", product_data=[return_data1[1], return_data1[3]])) # When producer.producer_func(test_queue) actual1 = test_queue.get() actual2 = test_queue.get() # Then assert actual1 == expected1 assert actual2 == expected2
def test_product_data_producer_func(test_context): # Given return_data = [dict(AccountNumber="99999", test_value="test")] producer = ProductDataProducer(test_context) producer.client.set_access_token = MagicMock() producer.client.fetch_product_data = MagicMock(side_effect=[(return_data, False)]) test_queue = get_queue_interface('memory')() expected = dict(job_type=QueueKeys.PRODUCT_DATA, payload=dict(fi_id="99999", product_data=return_data)) # When producer.producer_func(test_queue) actual = test_queue.get() # Then assert actual == expected
def __init__(self, context: ProducerConsumerContext = ProducerConsumerContext()): """ :param context: Context object with defined configurations for ProducerConsumer and it's work queue """ self.event_manager = EventManager() self._work_queue_class = get_queue_interface(context.QUEUE_TYPE) if self._work_queue_class is None: raise ValueError("Received invalid queue_type") self._work_queue = self._work_queue_class(**context.QUEUE_KWARGS) self.max_consumers = context.MAX_CONSUMERS self._producers = dict() self._consumers = dict() self.threads: List[threading.Thread] = [] self._thread_list_lock = threading.Lock() self.thread_exception_list = [] self._exception_list_lock = threading.Lock()