Skip to content

Commit f1e03e6

Browse files
committed
Addressed code review feedback + test fixes
1 parent 406ae29 commit f1e03e6

File tree

10 files changed

+207
-192
lines changed

10 files changed

+207
-192
lines changed

google/cloud/bigtable/client.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
from google.api_core.gapic_v1 import client_info as client_info_lib
3535
from google.auth.credentials import AnonymousCredentials # type: ignore
3636

37-
from google.cloud import bigtable_v2
3837
from google.cloud import bigtable_admin_v2
39-
from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport
4038
from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin.transports import (
4139
BigtableInstanceAdminGrpcTransport,
4240
)
@@ -150,7 +148,6 @@ class Client(ClientWithProject):
150148
_table_data_client = None
151149
_table_admin_client = None
152150
_instance_admin_client = None
153-
_new_table_data_client = None
154151

155152
def __init__(
156153
self,
@@ -295,18 +292,7 @@ def table_data_client(self):
295292
:rtype: :class:`.bigtable_v2.BigtableClient`
296293
:returns: A BigtableClient object.
297294
"""
298-
if self._table_data_client is None:
299-
transport = self._create_gapic_client_channel(
300-
bigtable_v2.BigtableClient,
301-
BigtableGrpcTransport,
302-
)
303-
klass = _create_gapic_client(
304-
bigtable_v2.BigtableClient,
305-
client_options=self._client_options,
306-
transport=transport,
307-
)
308-
self._table_data_client = klass(self)
309-
return self._table_data_client
295+
return self._data_client._gapic_client
310296

311297
@property
312298
def table_admin_client(self):
@@ -375,21 +361,17 @@ def instance_admin_client(self):
375361
return self._instance_admin_client
376362

377363
@property
378-
def new_table_data_client(self):
379-
"""Getter for the new Data Table API.
380-
381-
TODO: Replace table_data_client with this implementation
382-
when shimming legacy client is finished.
383-
"""
384-
if self._new_table_data_client is None:
385-
self._new_table_data_client = BigtableDataClient(
364+
def _data_client(self):
365+
"""Getter for the new Data Table API."""
366+
if self._table_data_client is None:
367+
self._table_data_client = BigtableDataClient(
386368
project=self.project,
387369
credentials=self._credentials,
388370
client_options=self._client_options,
389-
client_info=self._client_info,
390-
disable_background_channel_refresh=True,
371+
_client_info=self._client_info,
372+
_disable_background_channel_refresh=True,
391373
)
392-
return self._new_table_data_client
374+
return self._table_data_client
393375

394376
def instance(self, instance_id, display_name=None, instance_type=None, labels=None):
395377
"""Factory to create a instance associated with this client.

google/cloud/bigtable/data/_async/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,15 @@ def __init__(
184184
"""
185185
if "pool_size" in kwargs:
186186
warnings.warn("pool_size no longer supported")
187-
# set up client info headers for veneer library
188-
self.client_info = kwargs.get("client_info") or DEFAULT_CLIENT_INFO
189-
self.client_info.client_library_version = self._client_version()
187+
if "_client_info" in kwargs:
188+
# use client_info passed in from legacy client. For internal use only, for the legacy
189+
# client shim.
190+
self.client_info = kwargs["_client_info"]
191+
else:
192+
# set up client info headers for veneer library.
193+
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
194+
self.client_info.client_library_version = self._client_version()
195+
190196
# parse client options
191197
if type(client_options) is dict:
192198
client_options = client_options_lib.from_dict(client_options)
@@ -237,7 +243,7 @@ def __init__(
237243
)
238244
self._is_closed = CrossSync.Event()
239245
self._disable_background_channel_refresh = bool(
240-
kwargs.get("disable_background_channel_refresh", False)
246+
kwargs.get("_disable_background_channel_refresh", False)
241247
)
242248
self.transport = cast(TransportType, self._gapic_client.transport)
243249
# keep track of active instances to for warmup on channel refresh

google/cloud/bigtable/data/_sync_autogen/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ def __init__(
127127
"""
128128
if "pool_size" in kwargs:
129129
warnings.warn("pool_size no longer supported")
130-
self.client_info = kwargs.get("client_info") or DEFAULT_CLIENT_INFO
131-
self.client_info.client_library_version = self._client_version()
130+
if "_client_info" in kwargs:
131+
self.client_info = kwargs["_client_info"]
132+
else:
133+
self.client_info = kwargs.get("_client_info", DEFAULT_CLIENT_INFO)
134+
self.client_info.client_library_version = self._client_version()
132135
if type(client_options) is dict:
133136
client_options = client_options_lib.from_dict(client_options)
134137
client_options = cast(
@@ -169,7 +172,7 @@ def __init__(
169172
)
170173
self._is_closed = CrossSync._Sync_Impl.Event()
171174
self._disable_background_channel_refresh = bool(
172-
kwargs.get("disable_background_channel_refresh", False)
175+
kwargs.get("_disable_background_channel_refresh", False)
173176
)
174177
self.transport = cast(TransportType, self._gapic_client.transport)
175178
self._active_instances: Set[_WarmedInstanceKey] = set()

google/cloud/bigtable/table.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ def __init__(self, table_id, instance, mutation_timeout=None, app_profile_id=Non
132132
self._app_profile_id = app_profile_id
133133
self.mutation_timeout = mutation_timeout
134134

135+
self._table_impl = (
136+
self._instance._client._data_client.get_table(
137+
self._instance.instance_id,
138+
self.table_id,
139+
)
140+
if self._instance
141+
else None
142+
)
143+
135144
@property
136145
def name(self):
137146
"""Table name used in requests.

tests/unit/data/_async/test_client.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ async def test_ctor_client_info(self):
178178
from google.api_core import client_options as client_options_lib
179179
from google.api_core.gapic_v1.client_info import ClientInfo
180180

181-
import copy
182-
183181
project = "project-id"
184182
credentials = AnonymousCredentials()
185183
client_info = ClientInfo(gapic_version="1.2.3", user_agent="test-client-")
@@ -192,9 +190,9 @@ async def test_ctor_client_info(self):
192190
self._make_client(
193191
project=project,
194192
credentials=credentials,
195-
client_info=client_info,
196193
client_options=options_parsed,
197194
use_emulator=False,
195+
_client_info=client_info,
198196
)
199197
except TypeError:
200198
pass
@@ -205,18 +203,7 @@ async def test_ctor_client_info(self):
205203
assert kwargs["credentials"] == credentials
206204
assert kwargs["client_options"] == options_parsed
207205

208-
expected_client_info = copy.copy(client_info)
209-
expected_client_info.client_library_version = (
210-
CrossSync.DataClient._client_version()
211-
)
212-
assert (
213-
kwargs["client_info"].to_user_agent()
214-
== expected_client_info.to_user_agent()
215-
)
216-
assert (
217-
kwargs["client_info"].to_grpc_metadata()
218-
== expected_client_info.to_grpc_metadata()
219-
)
206+
kwargs["client_info"] == client_info
220207

221208
@CrossSync.pytest
222209
async def test_ctor_dict_options(self):
@@ -313,14 +300,17 @@ async def test__start_background_channel_refresh(self):
313300
async def test__start_background_channel_refresh_disable_refresh(self):
314301
client = self._make_client(
315302
project="project-id",
316-
disable_background_channel_refresh=True,
303+
_disable_background_channel_refresh=True,
317304
)
318305
# should create background tasks for each channel
319-
with mock.patch.object(client, "_ping_and_warm_instances", CrossSync.Mock()):
306+
with mock.patch.object(
307+
client, "_ping_and_warm_instances", CrossSync.Mock()
308+
) as ping_and_warm:
320309
client._emulator_host = None
321310
client.transport._grpc_channel = CrossSync.SwappableChannel(mock.Mock)
322311
client._start_background_channel_refresh()
323312
assert client._channel_refresh_task is None
313+
ping_and_warm.assert_not_called()
324314

325315
@CrossSync.drop
326316
@CrossSync.pytest

tests/unit/data/_sync_autogen/test_client.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def test_ctor_super_inits(self):
141141
def test_ctor_client_info(self):
142142
from google.api_core import client_options as client_options_lib
143143
from google.api_core.gapic_v1.client_info import ClientInfo
144-
import copy
145144

146145
project = "project-id"
147146
credentials = AnonymousCredentials()
@@ -155,28 +154,17 @@ def test_ctor_client_info(self):
155154
self._make_client(
156155
project=project,
157156
credentials=credentials,
158-
client_info=client_info,
159157
client_options=options_parsed,
160158
use_emulator=False,
159+
_client_info=client_info,
161160
)
162161
except TypeError:
163162
pass
164163
assert bigtable_client_init.call_count == 1
165164
kwargs = bigtable_client_init.call_args[1]
166165
assert kwargs["credentials"] == credentials
167166
assert kwargs["client_options"] == options_parsed
168-
expected_client_info = copy.copy(client_info)
169-
expected_client_info.client_library_version = (
170-
CrossSync._Sync_Impl.DataClient._client_version()
171-
)
172-
assert (
173-
kwargs["client_info"].to_user_agent()
174-
== expected_client_info.to_user_agent()
175-
)
176-
assert (
177-
kwargs["client_info"].to_grpc_metadata()
178-
== expected_client_info.to_grpc_metadata()
179-
)
167+
kwargs["client_info"] == client_info
180168

181169
def test_ctor_dict_options(self):
182170
from google.api_core.client_options import ClientOptions
@@ -252,17 +240,18 @@ def test__start_background_channel_refresh(self):
252240

253241
def test__start_background_channel_refresh_disable_refresh(self):
254242
client = self._make_client(
255-
project="project-id", disable_background_channel_refresh=True
243+
project="project-id", _disable_background_channel_refresh=True
256244
)
257245
with mock.patch.object(
258246
client, "_ping_and_warm_instances", CrossSync._Sync_Impl.Mock()
259-
):
247+
) as ping_and_warm:
260248
client._emulator_host = None
261249
client.transport._grpc_channel = CrossSync._Sync_Impl.SwappableChannel(
262250
mock.Mock
263251
)
264252
client._start_background_channel_refresh()
265253
assert client._channel_refresh_task is None
254+
ping_and_warm.assert_not_called()
266255

267256
def test__ping_and_warm_instances(self):
268257
"""test ping and warm with mocked asyncio.gather"""

0 commit comments

Comments
 (0)