Skip to content

Commit 1523be4

Browse files
committed
Upgrading Bigtable package to use gRPC beta.
1 parent 4ad2926 commit 1523be4

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

gcloud/bigtable/_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def make_stub(client, stub_factory, host, port):
8282
:type port: int
8383
:param port: The port for the service.
8484
85-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
85+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
8686
:returns: The stub object used to make gRPC requests to a given API.
8787
"""
8888
custom_metadata_transformer = MetadataTransformer(client)

gcloud/bigtable/client.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def project_name(self):
207207
def _data_stub(self):
208208
"""Getter for the gRPC stub used for the Data API.
209209
210-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
210+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
211211
:returns: A gRPC stub object.
212212
:raises: :class:`ValueError <exceptions.ValueError>` if the current
213213
client has not been :meth:`start`-ed.
@@ -220,7 +220,7 @@ def _data_stub(self):
220220
def _cluster_stub(self):
221221
"""Getter for the gRPC stub used for the Cluster Admin API.
222222
223-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
223+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
224224
:returns: A gRPC stub object.
225225
:raises: :class:`ValueError <exceptions.ValueError>` if the current
226226
client is not an admin client or if it has not been
@@ -236,7 +236,7 @@ def _cluster_stub(self):
236236
def _operations_stub(self):
237237
"""Getter for the gRPC stub used for the Operations API.
238238
239-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
239+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
240240
:returns: A gRPC stub object.
241241
:raises: :class:`ValueError <exceptions.ValueError>` if the current
242242
client is not an admin client or if it has not been
@@ -252,7 +252,7 @@ def _operations_stub(self):
252252
def _table_stub(self):
253253
"""Getter for the gRPC stub used for the Table Admin API.
254254
255-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
255+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
256256
:returns: A gRPC stub object.
257257
:raises: :class:`ValueError <exceptions.ValueError>` if the current
258258
client is not an admin client or if it has not been
@@ -267,7 +267,7 @@ def _table_stub(self):
267267
def _make_data_stub(self):
268268
"""Creates gRPC stub to make requests to the Data API.
269269
270-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
270+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
271271
:returns: A gRPC stub object.
272272
"""
273273
return make_stub(self, DATA_STUB_FACTORY,
@@ -276,7 +276,7 @@ def _make_data_stub(self):
276276
def _make_cluster_stub(self):
277277
"""Creates gRPC stub to make requests to the Cluster Admin API.
278278
279-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
279+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
280280
:returns: A gRPC stub object.
281281
"""
282282
return make_stub(self, CLUSTER_STUB_FACTORY,
@@ -288,7 +288,7 @@ def _make_operations_stub(self):
288288
These are for long-running operations of the Cluster Admin API,
289289
hence the host and port matching.
290290
291-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
291+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
292292
:returns: A gRPC stub object.
293293
"""
294294
return make_stub(self, OPERATIONS_STUB_FACTORY,
@@ -297,7 +297,7 @@ def _make_operations_stub(self):
297297
def _make_table_stub(self):
298298
"""Creates gRPC stub to make requests to the Table Admin API.
299299
300-
:rtype: :class:`grpc.early_adopter.implementations._Stub`
300+
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
301301
:returns: A gRPC stub object.
302302
"""
303303
return make_stub(self, TABLE_STUB_FACTORY,
@@ -388,10 +388,9 @@ def list_zones(self):
388388
zones is not in ``OK`` state.
389389
"""
390390
request_pb = messages_pb2.ListZonesRequest(name=self.project_name)
391-
response = self._cluster_stub.ListZones.async(request_pb,
392-
self.timeout_seconds)
393391
# We expect a `.messages_pb2.ListZonesResponse`
394-
list_zones_response = response.result()
392+
list_zones_response = self._cluster_stub.ListZones(
393+
request_pb, self.timeout_seconds)
395394

396395
result = []
397396
for zone in list_zones_response.zones:
@@ -410,10 +409,9 @@ def list_clusters(self):
410409
zones in the request).
411410
"""
412411
request_pb = messages_pb2.ListClustersRequest(name=self.project_name)
413-
response = self._cluster_stub.ListClusters.async(request_pb,
414-
self.timeout_seconds)
415412
# We expect a `.messages_pb2.ListClustersResponse`
416-
list_clusters_response = response.result()
413+
list_clusters_response = self._cluster_stub.ListClusters(
414+
request_pb, self.timeout_seconds)
417415

418416
failed_zones = [zone.display_name
419417
for zone in list_clusters_response.failed_zones]

gcloud/bigtable/test_client.py

+8-19
Original file line numberDiff line numberDiff line change
@@ -651,30 +651,19 @@ def __getattr__(self, name):
651651

652652

653653
class _MethodMock(object):
654-
"""Mock for :class:`grpc.framework.alpha._reexport._UnaryUnarySyncAsync`.
654+
"""Mock for API method attached to a gRPC stub.
655655
656-
May need to be callable and needs to (in our use) have an
657-
``async`` method.
656+
In the beta implementation, these are of type.
657+
:class:`grpc.framework.crust.implementations._UnaryUnaryMultiCallable`
658658
"""
659659

660660
def __init__(self, name, factory):
661661
self._name = name
662662
self._factory = factory
663663

664-
def async(self, *args, **kwargs):
665-
"""Async method meant to mock a gRPC stub request."""
664+
def __call__(self, *args, **kwargs):
665+
"""Sync method meant to mock a gRPC stub request."""
666666
self._factory.method_calls.append((self._name, args, kwargs))
667-
curr_result, self._factory.results = (self._factory.results[0],
668-
self._factory.results[1:])
669-
return _AsyncResult(curr_result)
670-
671-
672-
class _AsyncResult(object):
673-
"""Result returned from a ``_MethodMock.async`` call."""
674-
675-
def __init__(self, result):
676-
self._result = result
677-
678-
def result(self):
679-
"""Result method on an asyc object."""
680-
return self._result
667+
curr_result = self._factory.results[0]
668+
self._factory.results = self._factory.results[1:]
669+
return curr_result

0 commit comments

Comments
 (0)