From 8c5847946401746f2f4cebe36747bc583063f683 Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Thu, 21 Jun 2018 07:29:02 +0530 Subject: [PATCH 1/6] Add split keys on create table --- bigtable/google/cloud/bigtable/table.py | 26 +++++++-- bigtable/tests/system.py | 31 +++++++--- bigtable/tests/unit/test_table.py | 75 +++++++++++++++++++------ 3 files changed, 101 insertions(+), 31 deletions(-) diff --git a/bigtable/google/cloud/bigtable/table.py b/bigtable/google/cloud/bigtable/table.py index 773dcf0b1a77..21f76002a407 100644 --- a/bigtable/google/cloud/bigtable/table.py +++ b/bigtable/google/cloud/bigtable/table.py @@ -21,8 +21,6 @@ from google.api_core.retry import if_exception_type from google.api_core.retry import Retry from google.cloud._helpers import _to_bytes -from google.cloud.bigtable_v2.proto import ( - bigtable_pb2 as data_messages_v2_pb2) from google.cloud.bigtable.column_family import _gc_rule_from_pb from google.cloud.bigtable.column_family import ColumnFamily from google.cloud.bigtable.row import AppendRow @@ -30,6 +28,10 @@ from google.cloud.bigtable.row import DirectRow from google.cloud.bigtable.row_data import PartialRowsData from google.cloud.bigtable.row_data import YieldRowsData +from google.cloud.bigtable_v2.proto import ( + bigtable_pb2 as data_messages_v2_pb2) +from google.cloud.bigtable_admin_v2.proto import ( + bigtable_table_admin_pb2 as table_admin_messages_v2_pb2) # Maximum number of mutations in bulk (MutateRowsRequest message): @@ -174,7 +176,7 @@ def __eq__(self, other): def __ne__(self, other): return not self == other - def create(self): + def create(self, initial_split_keys=None): """Creates this table. .. note:: @@ -182,11 +184,27 @@ def create(self): A create request returns a :class:`._generated.table_pb2.Table` but we don't use this response. + + :type initial_split_keys: list + :param initial_split_keys: The optional list of row keys in bytes that + will be used to initially split the table + into several tablets. """ table_client = self._instance._client.table_admin_client instance_name = self._instance.name + + if initial_split_keys is not None: + splits = [] + for initial_split_key in initial_split_keys: + splits.append( + table_admin_messages_v2_pb2.CreateTableRequest.Split( + key=initial_split_key)) + else: + splits = None + table_client.create_table( - parent=instance_name, table_id=self.table_id, table={}) + parent=instance_name, table_id=self.table_id, table={}, + initial_splits=splits) def delete(self): """Delete this table.""" diff --git a/bigtable/tests/system.py b/bigtable/tests/system.py index 47a8095f19a7..f28c19ea2e0f 100644 --- a/bigtable/tests/system.py +++ b/bigtable/tests/system.py @@ -89,12 +89,12 @@ def setUpModule(): if not Config.IN_EMULATOR: retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable) - instances, failed_locations = retry(Config.CLIENT.list_instances)() + instances_response = retry(Config.CLIENT.list_instances)() - if len(failed_locations) != 0: + if len(instances_response.failed_locations) != 0: raise ValueError('List instances failed in module set up.') - EXISTING_INSTANCES[:] = instances + EXISTING_INSTANCES[:] = instances_response.instances # After listing, create the test instance. created_op = Config.INSTANCE.create() @@ -119,14 +119,14 @@ def tearDown(self): instance.delete() def test_list_instances(self): - expected = set([instance.name for instance in EXISTING_INSTANCES]) - expected.add(Config.INSTANCE.name) - instances, failed_locations = Config.CLIENT.list_instances() - self.assertEqual(failed_locations, []) - found = set([instance.name for instance in instances]) - self.assertTrue(expected.issubset(found)) + # We have added one new instance in `setUpModule`. + self.assertEqual(len(instances), len(EXISTING_INSTANCES) + 1) + for instance in instances: + instance_existence = (instance in EXISTING_INSTANCES or + instance == Config.INSTANCE) + self.assertTrue(instance_existence) def test_reload(self): # Use same arguments as Config.INSTANCE (created in `setUpModule`) @@ -242,6 +242,19 @@ def test_create_table(self): sorted_tables = sorted(tables, key=name_attr) self.assertEqual(sorted_tables, expected_tables) + def test_create_table_with_split_keys(self): + temp_table_id = 'foo-bar-baz-split-table' + initial_split_keys = [b'split_key_1', b'split_key_10', + b'split_key_20', b''] + temp_table = Config.INSTANCE.table(temp_table_id) + temp_table.create(initial_split_keys=initial_split_keys) + self.tables_to_delete.append(temp_table) + + # Read Sample Row Keys for created splits + sample_row_keys = temp_table.sample_row_keys() + self.assertEqual(set([srk.row_key for srk in sample_row_keys]), + set(initial_split_keys)) + def test_create_column_family(self): temp_table_id = 'test-create-column-family' temp_table = Config.INSTANCE.table(temp_table_id) diff --git a/bigtable/tests/unit/test_table.py b/bigtable/tests/unit/test_table.py index 84d48b03a892..77c6d77d3714 100644 --- a/bigtable/tests/unit/test_table.py +++ b/bigtable/tests/unit/test_table.py @@ -258,10 +258,11 @@ def _create_test_helper(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client, bigtable_table_admin_client) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) - instance_api = mock.create_autospec( - bigtable_instance_admin_client.BigtableInstanceAdminClient) + table_api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) + instance_api = ( + bigtable_instance_admin_client.BigtableInstanceAdminClient( + mock.Mock())) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -282,6 +283,44 @@ def _create_test_helper(self): def test_create(self): self._create_test_helper() + def test_create_with_split_keys(self): + from google.cloud.bigtable_admin_v2.gapic import ( + bigtable_instance_admin_client, bigtable_table_admin_client) + from google.cloud.bigtable_admin_v2.proto import ( + bigtable_table_admin_pb2 as table_admin_messages_v2_pb2) + + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) + instance_api = ( + bigtable_instance_admin_client.BigtableInstanceAdminClient( + mock.Mock())) + credentials = _make_credentials() + client = self._make_client(project='project-id', + credentials=credentials, admin=True) + instance = client.instance(instance_id=self.INSTANCE_ID) + table = self._make_one(self.TABLE_ID, instance) + + split_keys = [b'split1', b'split2', b'split3'] + + # Patch API calls + client._table_admin_client = table_api + client._instance_admin_client = instance_api + + # Perform the method and check the result. + table.create(split_keys) + + splits = [] + for split_key in split_keys: + splits.append( + table_admin_messages_v2_pb2.CreateTableRequest.Split( + key=split_key)) + + table_api.create_table.assert_called_once_with( + parent=self.INSTANCE_NAME, + table={}, + table_id=self.TABLE_ID, + initial_splits=splits) + def test_delete(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) @@ -308,7 +347,7 @@ def _list_column_families_helper(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( + api = bigtable_table_admin_client.BigtableTableAdminClient( mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', @@ -324,7 +363,7 @@ def _list_column_families_helper(self): ) # Patch the stub used by the API method. - client._table_admin_client = table_api + client._table_admin_client = api bigtable_table_stub = ( client._table_admin_client.bigtable_table_admin_stub) bigtable_table_stub.GetTable.side_effect = [response_pb] @@ -349,8 +388,8 @@ def _read_row_helper(self, chunks, expected_result, app_profile_id=None): bigtable_table_admin_client) data_api = bigtable_client.BigtableClient(mock.Mock()) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) + table_api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -435,13 +474,13 @@ def test_mutate_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) + api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) instance = client.instance(instance_id=self.INSTANCE_ID) - client._table_admin_client = table_api + client._table_admin_client = api table = self._make_one(self.TABLE_ID, instance) response = [Status(code=0), Status(code=1)] @@ -465,8 +504,8 @@ def test_read_rows(self): bigtable_table_admin_client) data_api = bigtable_client.BigtableClient(mock.Mock()) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) + table_api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -762,9 +801,9 @@ def test_callable_empty_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - data_api = mock.create_autospec(bigtable_client.BigtableClient) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) + data_api = bigtable_client.BigtableClient(mock.Mock()) + table_api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -943,8 +982,8 @@ def test_do_mutate_retryable_rows_empty_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - table_api = mock.create_autospec( - bigtable_table_admin_client.BigtableTableAdminClient) + table_api = bigtable_table_admin_client.BigtableTableAdminClient( + mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) From 4b78a00cb8ccf2419b5d2ef464ce96c32f10f7e9 Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Thu, 21 Jun 2018 08:22:12 +0530 Subject: [PATCH 2/6] Update create table --- bigtable/google/cloud/bigtable/table.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigtable/google/cloud/bigtable/table.py b/bigtable/google/cloud/bigtable/table.py index 21f76002a407..b0f12bd57a4b 100644 --- a/bigtable/google/cloud/bigtable/table.py +++ b/bigtable/google/cloud/bigtable/table.py @@ -202,9 +202,9 @@ def create(self, initial_split_keys=None): else: splits = None - table_client.create_table( - parent=instance_name, table_id=self.table_id, table={}, - initial_splits=splits) + table_client.create_table(parent=instance_name, + table_id=self.table_id, table={}, + initial_splits=splits) def delete(self): """Delete this table.""" From 1c72b7874d532bf9a4e80097bfe8d4cd2a6c707c Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Thu, 21 Jun 2018 08:31:51 +0530 Subject: [PATCH 3/6] Downgrade get_target_packages.py file --- test_utils/scripts/get_target_packages.py | 66 +++++------------------ 1 file changed, 12 insertions(+), 54 deletions(-) diff --git a/test_utils/scripts/get_target_packages.py b/test_utils/scripts/get_target_packages.py index 1d51830cc23a..0ff47d2ace46 100644 --- a/test_utils/scripts/get_target_packages.py +++ b/test_utils/scripts/get_target_packages.py @@ -23,18 +23,7 @@ CURRENT_DIR = os.path.realpath(os.path.dirname(__file__)) BASE_DIR = os.path.realpath(os.path.join(CURRENT_DIR, '..', '..')) GITHUB_REPO = os.environ.get('GITHUB_REPO', 'google-cloud-python') -CI = os.environ.get('CI', '') -CI_BRANCH = os.environ.get('CIRCLE_BRANCH') -CI_PR = os.environ.get('CIRCLE_PR_NUMBER') CIRCLE_TAG = os.environ.get('CIRCLE_TAG') -head_hash, head_name = subprocess.check_output(['git', 'show-ref', 'HEAD'] -).strip().decode('ascii').split() -rev_parse = subprocess.check_output( - ['git', 'rev-parse', '--abbrev-ref', 'HEAD'] -).strip().decode('ascii') -MAJOR_DIV = '#' * 78 -MINOR_DIV = '#' + '-' * 77 - # NOTE: This reg-ex is copied from ``get_tagged_packages``. TAG_RE = re.compile(r""" ^ @@ -48,6 +37,7 @@ # As of this writing, the only "real" dependency is that of error_reporting # (on logging), the rest are just system test dependencies. PKG_DEPENDENCIES = { + 'error_reporting': {'logging'}, 'logging': {'pubsub'}, } @@ -55,8 +45,7 @@ def get_baseline(): """Return the baseline commit. - On a pull request, or on a branch, return the common parent revision - with the master branch. + On a pull request, or on a branch, return the master tip. Locally, return a value pulled from environment variables, or None if the environment variables are not set. @@ -64,24 +53,21 @@ def get_baseline(): On a push to master, return None. This will effectively cause everything to be considered to be affected. """ + ci_branch = os.environ.get('CIRCLE_BRANCH') + ci_pr = os.environ.get('CIRCLE_PR_NUMBER') # If this is a pull request or branch, return the tip for master. # We will test only packages which have changed since that point. - ci_non_master = (CI == 'true') and any([CI_BRANCH != 'master', CI_PR]) - + ci_non_master = os.environ.get('CI', '') == 'true' and any([ + ci_branch != 'master', + ci_pr, + ]) if ci_non_master: - repo_url = 'git@github.com:GoogleCloudPlatform/{}'.format(GITHUB_REPO) subprocess.run(['git', 'remote', 'add', 'baseline', repo_url], stderr=subprocess.DEVNULL) subprocess.run(['git', 'pull', 'baseline'], stderr=subprocess.DEVNULL) - - if CI_PR is None and CI_BRANCH is not None: - output = subprocess.check_output([ - 'git', 'merge-base', '--fork-point', - 'baseline/master', CI_BRANCH]) - return output.strip().decode('ascii') - + # Can we have a PR but not a branch? return 'baseline/master' # If environment variables are set identifying what the master tip is, @@ -92,7 +78,7 @@ def get_baseline(): return '%s/%s' % (remote, branch) # If we are not in CI and we got this far, issue a warning. - if not CI: + if not os.environ.get('CI', ''): warnings.warn('No baseline could be determined; this means tests ' 'will run for every package. If this is local ' 'development, set the $GOOGLE_CLOUD_TESTING_REMOTE ' @@ -109,7 +95,6 @@ def get_changed_files(): """ # Get the baseline, and fail quickly if there is no baseline. baseline = get_baseline() - print('# Baseline commit: {}'.format(baseline)) if not baseline: return None @@ -230,39 +215,12 @@ def get_target_packages(): tagged_package = get_tagged_package() if tagged_package is None: file_list = get_changed_files() - print(MAJOR_DIV) - print('# Changed files:') - print(MINOR_DIV) - for file_ in file_list or (): - print('# {}'.format(file_)) for package in sorted(get_changed_packages(file_list)): yield package else: yield tagged_package -def main(): - print(MAJOR_DIV) - print('# Environment') - print(MINOR_DIV) - print('# CircleCI: {}'.format(CI)) - print('# CircleCI branch: {}'.format(CI_BRANCH)) - print('# CircleCI pr: {}'.format(CI_PR)) - print('# CircleCI tag: {}'.format(CIRCLE_TAG)) - print('# HEAD ref: {}'.format(head_hash)) - print('# {}'.format(head_name)) - print('# Git branch: {}'.format(rev_parse)) - print(MAJOR_DIV) - - packages = list(get_target_packages()) - - print(MAJOR_DIV) - print('# Target packages:') - print(MINOR_DIV) - for package in packages: - print(package) - print(MAJOR_DIV) - - if __name__ == '__main__': - main() + for package in get_target_packages(): + print(package) From 38a102912df046bde2701d44f75406f6bfbd9d62 Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Fri, 22 Jun 2018 14:22:04 +0530 Subject: [PATCH 4/6] update with main repo --- test_utils/scripts/get_target_packages.py | 66 ++++++++++++++++++----- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/test_utils/scripts/get_target_packages.py b/test_utils/scripts/get_target_packages.py index 0ff47d2ace46..1d51830cc23a 100644 --- a/test_utils/scripts/get_target_packages.py +++ b/test_utils/scripts/get_target_packages.py @@ -23,7 +23,18 @@ CURRENT_DIR = os.path.realpath(os.path.dirname(__file__)) BASE_DIR = os.path.realpath(os.path.join(CURRENT_DIR, '..', '..')) GITHUB_REPO = os.environ.get('GITHUB_REPO', 'google-cloud-python') +CI = os.environ.get('CI', '') +CI_BRANCH = os.environ.get('CIRCLE_BRANCH') +CI_PR = os.environ.get('CIRCLE_PR_NUMBER') CIRCLE_TAG = os.environ.get('CIRCLE_TAG') +head_hash, head_name = subprocess.check_output(['git', 'show-ref', 'HEAD'] +).strip().decode('ascii').split() +rev_parse = subprocess.check_output( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'] +).strip().decode('ascii') +MAJOR_DIV = '#' * 78 +MINOR_DIV = '#' + '-' * 77 + # NOTE: This reg-ex is copied from ``get_tagged_packages``. TAG_RE = re.compile(r""" ^ @@ -37,7 +48,6 @@ # As of this writing, the only "real" dependency is that of error_reporting # (on logging), the rest are just system test dependencies. PKG_DEPENDENCIES = { - 'error_reporting': {'logging'}, 'logging': {'pubsub'}, } @@ -45,7 +55,8 @@ def get_baseline(): """Return the baseline commit. - On a pull request, or on a branch, return the master tip. + On a pull request, or on a branch, return the common parent revision + with the master branch. Locally, return a value pulled from environment variables, or None if the environment variables are not set. @@ -53,21 +64,24 @@ def get_baseline(): On a push to master, return None. This will effectively cause everything to be considered to be affected. """ - ci_branch = os.environ.get('CIRCLE_BRANCH') - ci_pr = os.environ.get('CIRCLE_PR_NUMBER') # If this is a pull request or branch, return the tip for master. # We will test only packages which have changed since that point. - ci_non_master = os.environ.get('CI', '') == 'true' and any([ - ci_branch != 'master', - ci_pr, - ]) + ci_non_master = (CI == 'true') and any([CI_BRANCH != 'master', CI_PR]) + if ci_non_master: + repo_url = 'git@github.com:GoogleCloudPlatform/{}'.format(GITHUB_REPO) subprocess.run(['git', 'remote', 'add', 'baseline', repo_url], stderr=subprocess.DEVNULL) subprocess.run(['git', 'pull', 'baseline'], stderr=subprocess.DEVNULL) - # Can we have a PR but not a branch? + + if CI_PR is None and CI_BRANCH is not None: + output = subprocess.check_output([ + 'git', 'merge-base', '--fork-point', + 'baseline/master', CI_BRANCH]) + return output.strip().decode('ascii') + return 'baseline/master' # If environment variables are set identifying what the master tip is, @@ -78,7 +92,7 @@ def get_baseline(): return '%s/%s' % (remote, branch) # If we are not in CI and we got this far, issue a warning. - if not os.environ.get('CI', ''): + if not CI: warnings.warn('No baseline could be determined; this means tests ' 'will run for every package. If this is local ' 'development, set the $GOOGLE_CLOUD_TESTING_REMOTE ' @@ -95,6 +109,7 @@ def get_changed_files(): """ # Get the baseline, and fail quickly if there is no baseline. baseline = get_baseline() + print('# Baseline commit: {}'.format(baseline)) if not baseline: return None @@ -215,12 +230,39 @@ def get_target_packages(): tagged_package = get_tagged_package() if tagged_package is None: file_list = get_changed_files() + print(MAJOR_DIV) + print('# Changed files:') + print(MINOR_DIV) + for file_ in file_list or (): + print('# {}'.format(file_)) for package in sorted(get_changed_packages(file_list)): yield package else: yield tagged_package -if __name__ == '__main__': - for package in get_target_packages(): +def main(): + print(MAJOR_DIV) + print('# Environment') + print(MINOR_DIV) + print('# CircleCI: {}'.format(CI)) + print('# CircleCI branch: {}'.format(CI_BRANCH)) + print('# CircleCI pr: {}'.format(CI_PR)) + print('# CircleCI tag: {}'.format(CIRCLE_TAG)) + print('# HEAD ref: {}'.format(head_hash)) + print('# {}'.format(head_name)) + print('# Git branch: {}'.format(rev_parse)) + print(MAJOR_DIV) + + packages = list(get_target_packages()) + + print(MAJOR_DIV) + print('# Target packages:') + print(MINOR_DIV) + for package in packages: print(package) + print(MAJOR_DIV) + + +if __name__ == '__main__': + main() From 12ccebab72135991579c000b09f2c502d1b40a1e Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Fri, 29 Jun 2018 07:58:53 +0530 Subject: [PATCH 5/6] Fix requested changes --- bigtable/tests/system.py | 12 +++++----- bigtable/tests/unit/test_table.py | 37 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/bigtable/tests/system.py b/bigtable/tests/system.py index f28c19ea2e0f..2e80db649fea 100644 --- a/bigtable/tests/system.py +++ b/bigtable/tests/system.py @@ -119,14 +119,14 @@ def tearDown(self): instance.delete() def test_list_instances(self): + expected = set([instance.name for instance in EXISTING_INSTANCES]) + expected.add(Config.INSTANCE.name) + instances, failed_locations = Config.CLIENT.list_instances() + self.assertEqual(failed_locations, []) - # We have added one new instance in `setUpModule`. - self.assertEqual(len(instances), len(EXISTING_INSTANCES) + 1) - for instance in instances: - instance_existence = (instance in EXISTING_INSTANCES or - instance == Config.INSTANCE) - self.assertTrue(instance_existence) + found = set([instance.name for instance in instances]) + self.assertTrue(expected.issubset(found)) def test_reload(self): # Use same arguments as Config.INSTANCE (created in `setUpModule`) diff --git a/bigtable/tests/unit/test_table.py b/bigtable/tests/unit/test_table.py index 77c6d77d3714..fa8a22156f0e 100644 --- a/bigtable/tests/unit/test_table.py +++ b/bigtable/tests/unit/test_table.py @@ -258,11 +258,10 @@ def _create_test_helper(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client, bigtable_table_admin_client) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) - instance_api = ( - bigtable_instance_admin_client.BigtableInstanceAdminClient( - mock.Mock())) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) + instance_api = mock.create_autospec( + bigtable_instance_admin_client.BigtableInstanceAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -347,7 +346,7 @@ def _list_column_families_helper(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - api = bigtable_table_admin_client.BigtableTableAdminClient( + table_api = bigtable_table_admin_client.BigtableTableAdminClient( mock.Mock()) credentials = _make_credentials() client = self._make_client(project='project-id', @@ -363,7 +362,7 @@ def _list_column_families_helper(self): ) # Patch the stub used by the API method. - client._table_admin_client = api + client._table_admin_client = table_api bigtable_table_stub = ( client._table_admin_client.bigtable_table_admin_stub) bigtable_table_stub.GetTable.side_effect = [response_pb] @@ -388,8 +387,8 @@ def _read_row_helper(self, chunks, expected_result, app_profile_id=None): bigtable_table_admin_client) data_api = bigtable_client.BigtableClient(mock.Mock()) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -474,13 +473,13 @@ def test_mutate_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) instance = client.instance(instance_id=self.INSTANCE_ID) - client._table_admin_client = api + client._table_admin_client = table_api table = self._make_one(self.TABLE_ID, instance) response = [Status(code=0), Status(code=1)] @@ -504,8 +503,8 @@ def test_read_rows(self): bigtable_table_admin_client) data_api = bigtable_client.BigtableClient(mock.Mock()) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -801,9 +800,9 @@ def test_callable_empty_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - data_api = bigtable_client.BigtableClient(mock.Mock()) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) + data_api = mock.create_autospec(bigtable_client.BigtableClient) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) @@ -982,8 +981,8 @@ def test_do_mutate_retryable_rows_empty_rows(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_table_admin_client) - table_api = bigtable_table_admin_client.BigtableTableAdminClient( - mock.Mock()) + table_api = mock.create_autospec( + bigtable_table_admin_client.BigtableTableAdminClient) credentials = _make_credentials() client = self._make_client(project='project-id', credentials=credentials, admin=True) From 4e0ae68d829e026e7a8e437eeef5e86ece5e0f7c Mon Sep 17 00:00:00 2001 From: Aneep Tandel Date: Mon, 2 Jul 2018 08:44:22 +0530 Subject: [PATCH 6/6] Update system.py with master --- bigtable/tests/system.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigtable/tests/system.py b/bigtable/tests/system.py index 2e80db649fea..e047c21aab1b 100644 --- a/bigtable/tests/system.py +++ b/bigtable/tests/system.py @@ -89,12 +89,12 @@ def setUpModule(): if not Config.IN_EMULATOR: retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable) - instances_response = retry(Config.CLIENT.list_instances)() + instances, failed_locations = retry(Config.CLIENT.list_instances)() - if len(instances_response.failed_locations) != 0: + if len(failed_locations) != 0: raise ValueError('List instances failed in module set up.') - EXISTING_INSTANCES[:] = instances_response.instances + EXISTING_INSTANCES[:] = instances # After listing, create the test instance. created_op = Config.INSTANCE.create()