pabloem commented on code in PR #17589:
URL: https://github.com/apache/beam/pull/17589#discussion_r872055795
##########
sdks/python/apache_beam/io/gcp/bigquery_test.py:
##########
@@ -482,6 +486,109 @@ def test_temp_dataset_is_configurable(
delete_table.assert_called_with(
temp_dataset.projectId, temp_dataset.datasetId, mock.ANY)
+ @parameterized.expand([
+ param(exception_type=exceptions.Conflict, error_message='duplicate'),
+ param(
+ exception_type=exceptions.InternalServerError,
+ error_message='internalError'),
+ param(exception_type=exceptions.Forbidden, error_message='accessDenied'),
+ param(
+ exception_type=exceptions.ServiceUnavailable,
+ error_message='backendError'),
+ ])
+ @mock.patch('time.sleep')
+ def test_create_temp_dataset_exception(
+ self,
+ unused_mock,
+ exception_type,
+ error_message):
+
+ with mock.patch.object(bigquery_v2_client.BigqueryV2.JobsService,
'Insert') as a,\
+ mock.patch.object(bigquery_v2_client.BigqueryV2.DatasetsService,
'Insert') as mock_insert,\
+ self.assertRaises(Exception) as exc,\
+ beam.Pipeline() as p:
+
+ mock_insert.side_effect = exception_type(error_message)
+
+ _ = p | ReadFromBigQuery(
+ project='apache-beam-testing',
+ query='SELECT * FROM `project.dataset.table`',
+ gcs_location='gs://temp_location')
+
+ self.assertEqual(16, mock_insert.call_count)
+ self.assertIn(error_message, exc.exception.args[0])
+
+ @parameterized.expand([
+ param(exception_type=exceptions.BadRequest,
error_message='invalidQuery'),
+ param(exception_type=exceptions.NotFound, error_message='notFound'),
+ param(
+ exception_type=exceptions.Forbidden,
+ error_message='responseTooLarge'),
+ param(
+ exception_type=exceptions.ServiceUnavailable,
+ error_message='backendError'),
+ ])
+ @mock.patch('time.sleep')
Review Comment:
also try moving this into a context manager?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]