diff --git a/samples/hello_happybase/main.py b/samples/hello_happybase/main.py index 7999fd006..ffe520abd 100644 --- a/samples/hello_happybase/main.py +++ b/samples/hello_happybase/main.py @@ -97,6 +97,12 @@ def main(project_id, instance_id, table_name): finally: connection.close() + # make sure table is deleted + try: + table = instance.table(table_name) + table.delete() + except Exception: + pass if __name__ == "__main__": diff --git a/samples/instanceadmin/instanceadmin.py b/samples/instanceadmin/instanceadmin.py index 7341bfc46..9afd82039 100644 --- a/samples/instanceadmin/instanceadmin.py +++ b/samples/instanceadmin/instanceadmin.py @@ -48,6 +48,7 @@ def run_instance_operations(project_id, instance_id, cluster_id): :type instance_id: str :param instance_id: Instance of the client. """ + print(f"Running instance operations on {project_id} and {instance_id}") client = bigtable.Client(project=project_id, admin=True) location_id = "us-central1-f" serve_nodes = 1 diff --git a/samples/instanceadmin/noxfile_config.py b/samples/instanceadmin/noxfile_config.py new file mode 100644 index 000000000..cf88dcf8c --- /dev/null +++ b/samples/instanceadmin/noxfile_config.py @@ -0,0 +1,41 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be imported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + "ignored_versions": ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + "gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT", + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": {}, +} diff --git a/samples/instanceadmin/test_instanceadmin.py b/samples/instanceadmin/test_instanceadmin.py index b0041294b..017961dfa 100644 --- a/samples/instanceadmin/test_instanceadmin.py +++ b/samples/instanceadmin/test_instanceadmin.py @@ -99,7 +99,6 @@ def test_run_instance_operations(capsys, dispose_of): def test_delete_instance(capsys, dispose_of): from concurrent.futures import TimeoutError - @backoff.on_exception(backoff.expo, TimeoutError) def _set_up_instance(): dispose_of(INSTANCE) @@ -125,7 +124,6 @@ def _set_up_instance(): def test_add_and_delete_cluster(capsys, dispose_of): from concurrent.futures import TimeoutError - @backoff.on_exception(backoff.expo, TimeoutError) def _set_up_instance(): dispose_of(INSTANCE) diff --git a/samples/metricscaler/metricscaler_test.py b/samples/metricscaler/metricscaler_test.py index 47be38187..fb51f3b1f 100644 --- a/samples/metricscaler/metricscaler_test.py +++ b/samples/metricscaler/metricscaler_test.py @@ -39,6 +39,27 @@ BIGTABLE_DEV_INSTANCE = INSTANCE_ID_FORMAT.format(str(uuid.uuid4())[:10]) +@pytest.fixture(scope="module", autouse=True) +def preclean(): + """In case any test instances weren't cleared out in a previous run. + + Deletes any test instances that were created over an hour ago. Newer instances may + be being used by a concurrent test run. + """ + import time + import warnings + prefix = INSTANCE_ID_FORMAT.format("") + client = bigtable.Client(project=PROJECT, admin=True) + for instance in client.list_instances()[0]: + if instance.instance_id.startswith(prefix): + timestamp = instance.instance_id.split("-")[-1] + timestamp = int(timestamp) + if time.time() - timestamp > 3600: + warnings.warn( + f"Deleting leftover test instance: {instance.name}" + ) + instance.delete() + # System tests to verify API calls succeed diff --git a/tests/unit/test_row_data.py b/tests/unit/test_row_data.py index 9f2c40a54..7c2987b56 100644 --- a/tests/unit/test_row_data.py +++ b/tests/unit/test_row_data.py @@ -362,6 +362,30 @@ def test__retry_read_rows_exception_deadline_exceeded_wrapped_in_grpc(): assert _retry_read_rows_exception(exception) +def test_partial_cell_data(): + from google.cloud.bigtable.row_data import PartialCellData + + expected_key = b"row-key" + expected_family_name = b"family-name" + expected_qualifier = b"qualifier" + expected_timestamp = 1234 + instance = PartialCellData( + expected_key, expected_family_name, expected_qualifier, expected_timestamp + ) + assert instance.row_key == expected_key + assert instance.family_name == expected_family_name + assert instance.qualifier == expected_qualifier + assert instance.timestamp_micros == expected_timestamp + assert instance.value == b"" + assert instance.labels == () + # test updating value + added_value = b"added-value" + instance.append_value(added_value) + assert instance.value == added_value + instance.append_value(added_value) + assert instance.value == added_value + added_value + + def _make_partial_rows_data(*args, **kwargs): from google.cloud.bigtable.row_data import PartialRowsData