[
https://issues.apache.org/jira/browse/BEAM-14422?focusedWorklogId=770042&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-770042
]
ASF GitHub Bot logged work on BEAM-14422:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 13/May/22 06:52
Start Date: 13/May/22 06:52
Worklog Time Spent: 10m
Work Description: 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?
Issue Time Tracking
-------------------
Worklog Id: (was: 770042)
Time Spent: 1h (was: 50m)
> ReadFromBigQuery with query requires exception handling tests
> -------------------------------------------------------------
>
> Key: BEAM-14422
> URL: https://issues.apache.org/jira/browse/BEAM-14422
> Project: Beam
> Issue Type: Bug
> Components: io-py-gcp
> Reporter: Ahmed Abualsaud
> Assignee: Ahmed Abualsaud
> Priority: P2
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Tests need to be created to test the behavior of our code when expected
> exceptions come up when querying from BigQuery.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)