Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 7369de1

Browse files
committed
Upgrading system tests for new dependencies.
In order to get passing system tests, Client.start() and Client.stop() had to stop being used. Also add a newline (per feedback) in setup.py.
1 parent 5cf2443 commit 7369de1

File tree

7 files changed

+30
-107
lines changed

7 files changed

+30
-107
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
]
5555

5656
SETUP_BASE.pop('url')
57+
5758
setup(
5859
name='google-cloud-happybase',
5960
version='0.19.0',

src/google/cloud/happybase/connection.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ def _get_instance(timeout=None):
8585
if timeout is not None:
8686
client_kwargs['timeout_seconds'] = timeout / 1000.0
8787
client = Client(**client_kwargs)
88-
try:
89-
client.start()
90-
instances, failed_locations = client.list_instances()
91-
finally:
92-
client.stop()
88+
instances, failed_locations = client.list_instances()
9389

9490
if len(failed_locations) != 0:
9591
raise ValueError('Determining instance via ListInstances encountered '
@@ -207,26 +203,14 @@ def _handle_legacy_args(arguments_dict):
207203
def open(self):
208204
"""Open the underlying transport to Cloud Bigtable.
209205
210-
This method opens the underlying HTTP/2 gRPC connection using a
211-
:class:`~google.cloud.bigtable.client.Client` bound to the
212-
:class:`~google.cloud.bigtable.instance.Instance` owned by
213-
this connection.
206+
This method does nothing and is provided for compatibility.
214207
"""
215-
self._instance._client.start()
216208

217209
def close(self):
218210
"""Close the underlying transport to Cloud Bigtable.
219211
220-
This method closes the underlying HTTP/2 gRPC connection using a
221-
:class:`~google.cloud.bigtable.client.Client` bound to the
222-
:class:`~google.cloud.bigtable.instance.Instance` owned by
223-
this connection.
212+
This method does nothing and is provided for compatibility.
224213
"""
225-
self._instance._client.stop()
226-
227-
def __del__(self):
228-
if self._instance is not None:
229-
self.close()
230214

231215
def _table_name(self, name):
232216
"""Construct a table name by optionally adding a table name prefix.

src/google/cloud/happybase/pool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def connection(self, timeout=None):
142142
with self._lock:
143143
self._thread_connections.current = connection
144144

145-
# This is a no-op for connections that have already been opened
146-
# since they just call Client.start().
145+
# This is a no-op.
147146
connection.open()
148147
yield connection
149148

system_tests/happybase.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818

1919
import unittest
2020

21-
from google.cloud import _helpers
2221
from google.cloud.bigtable import client as client_mod
23-
from google.cloud.bigtable.happybase.connection import Connection
24-
from google.cloud.environment_vars import TESTS_PROJECT
22+
from google.cloud.happybase.connection import Connection
2523

2624
from retry import RetryResult
2725
from system_test_utils import unique_resource_id
2826

2927

3028
_PACK_I64 = struct.Struct('>q').pack
3129
_FIRST_ELT = operator.itemgetter(0)
32-
_helpers.PROJECT = TESTS_PROJECT
3330
LOCATION_ID = 'us-central1-c'
3431
# NOTE: Avoid using the same name as in bigtable.py
3532
INSTANCE_ID = 'gcl-hb' + unique_resource_id('-')
@@ -63,33 +60,37 @@ class Config(object):
6360
TABLE = None
6461

6562

66-
def _operation_wait(operation, max_attempts=5):
63+
def _operation_complete(result):
64+
"""Identity function.
65+
66+
Meant to return a boolean, but the value passed in is
67+
already equal to that value.
68+
"""
69+
return result
70+
71+
72+
def _wait_until_complete(operation, max_attempts=5):
6773
"""Wait until an operation has completed.
6874
69-
:type operation: :class:`~google.cloud.bigtable.instance.Operation`
70-
:param operation: Operation that has not finished.
75+
:type operation: :class:`google.cloud.operation.Operation`
76+
:param operation: Operation that has not completed.
7177
7278
:type max_attempts: int
7379
:param max_attempts: (Optional) The maximum number of times to check if
74-
the operation has finished. Defaults to 5.
80+
the operation has completed. Defaults to 5.
7581
7682
:rtype: bool
77-
:returns: Boolean indicating if the operation finished.
83+
:returns: Boolean indicating if the operation is complete.
7884
"""
79-
80-
def _operation_finished(result):
81-
return result
82-
83-
retry = RetryResult(_operation_finished, max_tries=max_attempts)
84-
return retry(operation.finished)()
85+
retry = RetryResult(_operation_complete, max_tries=max_attempts)
86+
return retry(operation.poll)()
8587

8688

8789
def set_connection():
8890
client = client_mod.Client(admin=True)
8991
instance = client.instance(INSTANCE_ID, LOCATION_ID)
90-
client.start()
9192
operation = instance.create()
92-
if not _operation_wait(operation):
93+
if not _wait_until_complete(operation):
9394
raise RuntimeError('Instance creation exceed 5 seconds.')
9495
Config.CONNECTION = Connection(instance=instance)
9596

system_tests/system_test_utils.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import time
1919

2020
from google.cloud.environment_vars import CREDENTIALS as TEST_CREDENTIALS
21-
from google.cloud.environment_vars import TESTS_PROJECT
2221

2322

2423
# From shell environ. May be None.
25-
PROJECT_ID = os.getenv(TESTS_PROJECT)
2624
CREDENTIALS = os.getenv(TEST_CREDENTIALS)
2725

2826
ENVIRON_ERROR_MSG = """\
@@ -44,24 +42,15 @@ def create_scoped_required():
4442

4543

4644
def check_environ():
47-
missing = []
48-
extra = ''
49-
50-
if PROJECT_ID is None:
51-
missing.append(TESTS_PROJECT)
52-
45+
err_msg = None
5346
if CREDENTIALS is None:
54-
missing.append(TEST_CREDENTIALS)
47+
err_msg = '\nMissing variables: ' + TEST_CREDENTIALS
5548
elif not os.path.isfile(CREDENTIALS):
56-
extra = '\nThe %s path %r is not a file.' % (TEST_CREDENTIALS,
57-
CREDENTIALS)
49+
err_msg = '\nThe %s path %r is not a file.' % (TEST_CREDENTIALS,
50+
CREDENTIALS)
5851

59-
if missing or extra:
60-
msg = ENVIRON_ERROR_MSG
61-
if missing:
62-
msg += '\nMissing variables: ' + ', '.join(missing)
63-
if extra:
64-
msg += extra
52+
if err_msg is not None:
53+
msg = ENVIRON_ERROR_MSG + err_msg
6554
print(msg, file=sys.stderr)
6655
sys.exit(1)
6756

unit_tests/test_connection.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def _helper(self, timeout=None, instances=(), failed_locations=()):
4444
if timeout is not None:
4545
expected_kwargs['timeout_seconds'] = timeout / 1000.0
4646
self.assertEqual(client.kwargs, expected_kwargs)
47-
self.assertEqual(client.start_calls, 1)
48-
self.assertEqual(client.stop_calls, 1)
4947

5048
def test_default(self):
5149
instance = _Instance()
@@ -83,10 +81,7 @@ def _makeOne(self, *args, **kwargs):
8381

8482
def test_constructor_defaults(self):
8583
instance = _Instance() # Avoid implicit environ check.
86-
self.assertEqual(instance._client.start_calls, 0)
8784
connection = self._makeOne(instance=instance)
88-
self.assertEqual(instance._client.start_calls, 1)
89-
self.assertEqual(instance._client.stop_calls, 0)
9085

9186
self.assertEqual(connection._instance, instance)
9287
self.assertEqual(connection.table_prefix, None)
@@ -95,8 +90,6 @@ def test_constructor_defaults(self):
9590
def test_constructor_no_autoconnect(self):
9691
instance = _Instance() # Avoid implicit environ check.
9792
connection = self._makeOne(autoconnect=False, instance=instance)
98-
self.assertEqual(instance._client.start_calls, 0)
99-
self.assertEqual(instance._client.stop_calls, 0)
10093
self.assertEqual(connection.table_prefix, None)
10194
self.assertEqual(connection.table_prefix_separator, '_')
10295

@@ -183,37 +176,6 @@ def test_constructor_non_string_prefix_separator(self):
183176
self._makeOne(autoconnect=False,
184177
table_prefix_separator=table_prefix_separator)
185178

186-
def test_open(self):
187-
instance = _Instance() # Avoid implicit environ check.
188-
connection = self._makeOne(autoconnect=False, instance=instance)
189-
self.assertEqual(instance._client.start_calls, 0)
190-
connection.open()
191-
self.assertEqual(instance._client.start_calls, 1)
192-
self.assertEqual(instance._client.stop_calls, 0)
193-
194-
def test_close(self):
195-
instance = _Instance() # Avoid implicit environ check.
196-
connection = self._makeOne(autoconnect=False, instance=instance)
197-
self.assertEqual(instance._client.stop_calls, 0)
198-
connection.close()
199-
self.assertEqual(instance._client.stop_calls, 1)
200-
self.assertEqual(instance._client.start_calls, 0)
201-
202-
def test___del__with_instance(self):
203-
instance = _Instance() # Avoid implicit environ check.
204-
connection = self._makeOne(autoconnect=False, instance=instance)
205-
self.assertEqual(instance._client.stop_calls, 0)
206-
connection.__del__()
207-
self.assertEqual(instance._client.stop_calls, 1)
208-
209-
def test___del__no_instance(self):
210-
instance = _Instance() # Avoid implicit environ check.
211-
connection = self._makeOne(autoconnect=False, instance=instance)
212-
self.assertEqual(instance._client.stop_calls, 0)
213-
del connection._instance
214-
connection.__del__()
215-
self.assertEqual(instance._client.stop_calls, 0)
216-
217179
def test__table_name_with_prefix_set(self):
218180
table_prefix = 'table-prefix'
219181
table_prefix_separator = '<>'
@@ -655,14 +617,6 @@ def __init__(self, *args, **kwargs):
655617
self.failed_locations = kwargs.pop('failed_locations', [])
656618
self.args = args
657619
self.kwargs = kwargs
658-
self.start_calls = 0
659-
self.stop_calls = 0
660-
661-
def start(self):
662-
self.start_calls += 1
663-
664-
def stop(self):
665-
self.stop_calls += 1
666620

667621
def list_instances(self):
668622
return self.instances, self.failed_locations

unit_tests/test_pool.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,7 @@ def test_connection_with_current_cnxn(self):
215215

216216

217217
class _Client(object):
218-
219-
def __init__(self):
220-
self.stop_calls = 0
221-
222-
def stop(self):
223-
self.stop_calls += 1
218+
pass
224219

225220

226221
class _Connection(object):

0 commit comments

Comments
 (0)