stankiewicz commented on code in PR #34135:
URL: https://github.com/apache/beam/pull/34135#discussion_r1979455221
##########
sdks/python/apache_beam/io/gcp/bigquery_tools_test.py:
##########
@@ -578,6 +643,65 @@ def test_start_query_job_priority_configuration(self):
client.jobs.Insert.call_args[0][0].job.configuration.query.priority,
'INTERACTIVE')
+ def test_negative_ttl_validation(self):
+ client = mock.Mock()
+ wrapper = beam.io.gcp.bigquery_tools.BigQueryWrapper(client)
+ with self.assertRaises(ValueError):
+ wrapper.set_table_definition_ttl(-1)
+
+ def test_cache_clearing_on_enable(self):
+ client = mock.Mock()
+ def create_new_mock_response(*args, **kwargs):
+ return mock.Mock()
+ client.tables.Get.side_effect = create_new_mock_response
+ wrapper = beam.io.gcp.bigquery_tools.BigQueryWrapper(client)
+
+ # Disable caching
+ wrapper.set_table_definition_ttl(0)
+ table1 = wrapper.get_table('project', 'dataset', 'table')
+
+ # Enable caching - should clear cache
+ wrapper.set_table_definition_ttl(3600)
+ table2 = wrapper.get_table('project', 'dataset', 'table')
+
+ self.assertEqual(client.tables.Get.call_count, 2)
+ self.assertIsNot(table1, table2)
+
+ def test_concurrent_access(self):
+ client = mock.Mock()
+ def create_new_mock_response(*args, **kwargs):
+ return mock.Mock()
+ client.tables.Get.side_effect = create_new_mock_response
+ wrapper = beam.io.gcp.bigquery_tools.BigQueryWrapper(client)
+
+ def get_table():
+ return wrapper.get_table('project', 'dataset', 'table')
+
+ import threading
+ threads = [threading.Thread(target=get_table) for _ in range(10)]
+ for t in threads:
+ t.start()
+ for t in threads:
+ t.join()
Review Comment:
can you elaborate why this is needed here?
--
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]