예제 #1
0
def test__retry_read_rows_exception_deadline_exceeded_wrapped_in_grpc():
    from google.api_core.exceptions import DeadlineExceeded
    from google.cloud.bigtable.row_data import _retry_read_rows_exception

    wrapped = DeadlineExceeded("testing")
    exception = _make_grpc_call_error(wrapped)
    assert _retry_read_rows_exception(exception)
    def test_create_task_raises_exception_on_non_transient_error(self):
        mock_create_task = MagicMock()
        mock_create_task.side_effect = DeadlineExceeded("test")
        self.cloud_task_publisher._client.create_task = mock_create_task

        with self.assertRaises(CloudTaskCreationFailed):
            self.cloud_task_publisher.create_task(
                body=self.body,
                queue_name=self.queue_name,
                function_name=self.function_name,
                fulfilment_request_transaction_id=self.transaction_id,
            )
def _pull_and_handle_message(subscriber, subscription_path, message_handler):
    """Pulls one message and calls the message handler, Return whether this subscription is currently doing work"""
    response = subscriber.pull(subscription=subscription_path,
                               max_messages=1,
                               timeout=2)
    if not response or len(response.received_messages) == 0:
        raise DeadlineExceeded(
            'Raising DeadlineExceeded to emulate cloud pubsub behaviour '
            'from local pubsub emulator')
    received_message = response.received_messages[0]
    # creating the ack callback with ack_id as a function scoped variable
    ack_callback = _create_message_ack_fn(subscriber, subscription_path,
                                          received_message.ack_id)
    message_handler(received_message.message, ack_callback)
예제 #4
0
def test_create_task_raises_exception_on_non_transient_error(
        mocker, cloud_task_publisher):
    mock_create_task = mocker.Mock()
    mock_create_task.side_effect = DeadlineExceeded("test")
    cloud_task_publisher._client.create_task = (  # pylint: disable=protected-access
        mock_create_task)

    with pytest.raises(CloudTaskCreationFailed):
        cloud_task_publisher.create_task(
            body=BODY,
            queue_name=QUEUE_NAME,
            function_name=FUNCTION_NAME,
            fulfilment_request_transaction_id=TRANSACTION_ID,
        )
예제 #5
0
  def test_insert_rows_sets_metric_on_failure(self):
    MetricsEnvironment.process_wide_container().reset()
    client = mock.Mock()
    client.insert_rows_json = mock.Mock(
        # Fail a few times, then succeed.
        side_effect=[
            DeadlineExceeded("Deadline Exceeded"),
            InternalServerError("Internal Error"),
            [],
        ])
    wrapper = beam.io.gcp.bigquery_tools.BigQueryWrapper(client)
    wrapper.insert_rows("my_project", "my_dataset", "my_table", [])

    # Expect two failing calls, then a success (i.e. two retries).
    self.verify_write_call_metric(
        "my_project", "my_dataset", "my_table", "deadline_exceeded", 1)
    self.verify_write_call_metric(
        "my_project", "my_dataset", "my_table", "internal", 1)
    self.verify_write_call_metric(
        "my_project", "my_dataset", "my_table", "ok", 1)
예제 #6
0
    def test_w_deadline_exceeded_wrapped_in_grpc(self):
        from google.api_core.exceptions import DeadlineExceeded

        wrapped = DeadlineExceeded("testing")
        exception = self._make_grpc_call_error(wrapped)
        self.assertTrue(self._call_fut(exception))
예제 #7
0
    def test_w_deadline_exceeded(self):
        from google.api_core.exceptions import DeadlineExceeded

        exception = DeadlineExceeded("testing")
        self.assertTrue(self._call_fut(exception))
예제 #8
0
 def next(self):
     raise DeadlineExceeded("Failed to read from server")
예제 #9
0
def test__retry_read_rows_exception_deadline_exceeded():
    from google.api_core.exceptions import DeadlineExceeded
    from google.cloud.bigtable.row_data import _retry_read_rows_exception

    exception = DeadlineExceeded("testing")
    assert _retry_read_rows_exception(exception)
예제 #10
0
    def next(self):
        from google.api_core.exceptions import DeadlineExceeded

        raise DeadlineExceeded("Failed to read from server")