예제 #1
0
    def test_fill_resource_items_queue(self):
        bridge = EdgeDataBridge(self.config)
        db_dict_list = [{
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }, {
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }]
        with patch('__builtin__.True', AlmostAlwaysTrue(1)):
            bridge.fill_resource_items_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(), 0)

        bridge.workers_config['historical'] = True
        with patch('__builtin__.True', AlmostAlwaysTrue(1)):
            bridge.fill_resource_items_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(), 0)
        bridge.workers_config['historical'] = False

        for item in db_dict_list:
            bridge.input_queue.put({
                'id':
                item['id'],
                'dateModified':
                datetime.datetime.utcnow().isoformat()
            })
        view_return_list = [
            munchify({
                'id': db_dict_list[0]['id'],
                'key': db_dict_list[0]['dateModified']
            })
        ]
        bridge.db.view = MagicMock(return_value=view_return_list)
        with patch('__builtin__.True', AlmostAlwaysTrue(1)):
            bridge.fill_resource_items_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(), 1)

        bridge.input_queue = Queue()
        bridge.resource_items_queue = Queue()
        bridge.workers_config['historical'] = True
        for item in db_dict_list:
            bridge.input_queue.put({'id': item['id'], 'rev': randint(10, 99)})
예제 #2
0
    def test_fill_input_queue(self):
        bridge = EdgeDataBridge(self.config)
        bridge.workers_config['historical'] = True
        mock_api_client = MagicMock()
        client_dict = {
            'id': uuid.uuid4().hex,
            'request_interval': 0.02,
            'client': mock_api_client
        }
        bridge.api_clients_queue.put(client_dict)
        return_value = [{
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }]
        resource_item_return_value = {
            'id': return_value[0]['id'],
            'x_revision_n': randint(10, 99)
        }

        mock_api_client.get_resource_item_historical.return_value = resource_item_return_value
        bridge.feeder.get_resource_items = MagicMock(return_value=return_value)
        self.assertEqual(bridge.input_queue.qsize(), 0)
        bridge.fill_input_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(),
                         resource_item_return_value['x_revision_n'])

        bridge.resource_items_queue = Queue()
        mock_api_client.get_resource_item_historical.side_effect = RequestFailed(
            munchify({'status_code': 429}))
        bridge.fill_input_queue()
        self.assertEqual(bridge.resource_items_queue.qsize(), 0)

        bridge = EdgeDataBridge(self.config)
        return_value = [{
            'id': uuid.uuid4().hex,
            'dateModified': datetime.datetime.utcnow().isoformat()
        }]
        bridge.feeder.get_resource_items = MagicMock(return_value=return_value)
        self.assertEqual(bridge.input_queue.qsize(), 0)
        bridge.fill_input_queue()
        self.assertEqual(bridge.input_queue.qsize(), 1)
        self.assertEqual(bridge.input_queue.get(), return_value[0])
예제 #3
0
    def test_queues_controller(self, mock_riw_spawn, mock_APIClient):
        bridge = EdgeDataBridge(self.config)
        bridge.resource_items_queue_size = 10
        bridge.resource_items_queue = Queue(10)
        for i in xrange(0, 10):
            bridge.resource_items_queue.put('a')
        self.assertEqual(len(bridge.workers_pool), 0)
        self.assertEqual(bridge.resource_items_queue.qsize(), 10)
        with patch('__builtin__.True', AlmostAlwaysTrue()):
            bridge.queues_controller()
        self.assertEqual(len(bridge.workers_pool), 1)
        bridge.workers_pool.add(mock_riw_spawn)
        self.assertEqual(len(bridge.workers_pool), 2)

        for i in xrange(0, 10):
            bridge.resource_items_queue.get()
        with patch('__builtin__.True', AlmostAlwaysTrue()):
            bridge.queues_controller()
        self.assertEqual(len(bridge.workers_pool), 1)
        self.assertEqual(bridge.resource_items_queue.qsize(), 0)