Skip to content

Commit 428d75a

Browse files
committed
renamed replaceablechannel to swappablechannel
1 parent 375332f commit 428d75a

File tree

6 files changed

+35
-41
lines changed

6 files changed

+35
-41
lines changed

google/cloud/bigtable/data/_async/_replaceable_channel.py renamed to google/cloud/bigtable/data/_async/_swappable_channel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
else:
2626
from grpc import Channel
2727

28-
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._replaceable_channel"
28+
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._swappable_channel"
2929

3030

3131
@CrossSync.convert_class(sync_name="_WrappedChannel", rm_aio=True)
@@ -91,10 +91,10 @@ def unsubscribe(self, callback):
9191

9292

9393
@CrossSync.convert_class(
94-
sync_name="_ReplaceableChannel",
94+
sync_name="SwappableChannel",
9595
replace_symbols={"_AsyncWrappedChannel": "_WrappedChannel"},
9696
)
97-
class _AsyncReplaceableChannel(_AsyncWrappedChannel):
97+
class AsyncSwappableChannel(_AsyncWrappedChannel):
9898
def __init__(self, channel_fn: Callable[[], Channel]):
9999
self._channel_fn = channel_fn
100100
self._channel = channel_fn()
@@ -119,7 +119,7 @@ def create_channel(self) -> Channel:
119119
)
120120
return new_channel
121121

122-
def replace_wrapped_channel(self, new_channel: Channel) -> Channel:
122+
def swap_channel(self, new_channel: Channel) -> Channel:
123123
old_channel = self._channel
124124
self._channel = new_channel
125125
return old_channel

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@
9696
BigtableAsyncClient as GapicClient,
9797
)
9898
from google.cloud.bigtable.data._async.mutations_batcher import _MB_SIZE
99-
from google.cloud.bigtable.data._async._replaceable_channel import (
100-
_AsyncReplaceableChannel,
99+
from google.cloud.bigtable.data._async._swappable_channel import (
100+
AsyncSwappableChannel,
101101
)
102102
else:
103103
from typing import Iterable # noqa: F401
104104
from grpc import insecure_channel
105105
from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport as TransportType # type: ignore
106106
from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient # type: ignore
107107
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE
108-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import ( # noqa: F401
109-
_ReplaceableChannel,
108+
from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( # noqa: F401
109+
SwappableChannel,
110110
)
111111

112112

@@ -244,15 +244,15 @@ def __init__(
244244
)
245245

246246
@CrossSync.convert(
247-
replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"}
247+
replace_symbols={"AsyncSwappableChannel": "SwappableChannel"}
248248
)
249-
def _build_grpc_channel(self, *args, **kwargs) -> _AsyncReplaceableChannel:
249+
def _build_grpc_channel(self, *args, **kwargs) -> AsyncSwappableChannel:
250250
if self._emulator_host is not None:
251251
# emulators use insecure channel
252252
create_channel_fn = partial(insecure_channel, self._emulator_host)
253253
else:
254254
create_channel_fn = partial(TransportType.create_channel, *args, **kwargs)
255-
return _AsyncReplaceableChannel(create_channel_fn)
255+
return AsyncSwappableChannel(create_channel_fn)
256256

257257
@staticmethod
258258
def _client_version() -> str:
@@ -357,7 +357,7 @@ def _invalidate_channel_stubs(self):
357357
self.transport._prep_wrapped_messages(self.client_info)
358358

359359
@CrossSync.convert(
360-
replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"}
360+
replace_symbols={"AsyncSwappableChannel": "SwappableChannel"}
361361
)
362362
async def _manage_channel(
363363
self,
@@ -383,10 +383,10 @@ async def _manage_channel(
383383
grace_period: time to allow previous channel to serve existing
384384
requests before closing, in seconds
385385
"""
386-
if not isinstance(self.transport.grpc_channel, _AsyncReplaceableChannel):
386+
if not isinstance(self.transport.grpc_channel, AsyncSwappableChannel):
387387
warnings.warn("Channel does not support auto-refresh.")
388388
return
389-
super_channel: _AsyncReplaceableChannel = self.transport.grpc_channel
389+
super_channel: AsyncSwappableChannel = self.transport.grpc_channel
390390
first_refresh = self._channel_init_time + random.uniform(
391391
refresh_interval_min, refresh_interval_max
392392
)
@@ -409,7 +409,7 @@ async def _manage_channel(
409409
new_channel = super_channel.create_channel()
410410
await self._ping_and_warm_instances(channel=new_channel)
411411
# cycle channel out of use, with long grace window before closure
412-
old_channel = super_channel.replace_wrapped_channel(new_channel)
412+
old_channel = super_channel.swap_channel(new_channel)
413413
self._invalidate_channel_stubs()
414414
# give old_channel a chance to complete existing rpcs
415415
if CrossSync.is_async:

google/cloud/bigtable/data/_sync_autogen/_replaceable_channel.py renamed to google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def unsubscribe(self, callback):
7171
return self._channel.unsubscribe(callback)
7272

7373

74-
class _ReplaceableChannel(_WrappedChannel):
74+
class SwappableChannel(_WrappedChannel):
7575
def __init__(self, channel_fn: Callable[[], Channel]):
7676
self._channel_fn = channel_fn
7777
self._channel = channel_fn()
@@ -80,7 +80,7 @@ def create_channel(self) -> Channel:
8080
new_channel = self._channel_fn()
8181
return new_channel
8282

83-
def replace_wrapped_channel(self, new_channel: Channel) -> Channel:
83+
def swap_channel(self, new_channel: Channel) -> Channel:
8484
old_channel = self._channel
8585
self._channel = new_channel
8686
return old_channel

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@
8080
)
8181
from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient
8282
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE
83-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import (
84-
_ReplaceableChannel,
85-
)
83+
from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel
8684

8785
if TYPE_CHECKING:
8886
from google.cloud.bigtable.data._helpers import RowKeySamples
@@ -180,12 +178,12 @@ def __init__(
180178
stacklevel=2,
181179
)
182180

183-
def _build_grpc_channel(self, *args, **kwargs) -> _ReplaceableChannel:
181+
def _build_grpc_channel(self, *args, **kwargs) -> SwappableChannel:
184182
if self._emulator_host is not None:
185183
create_channel_fn = partial(insecure_channel, self._emulator_host)
186184
else:
187185
create_channel_fn = partial(TransportType.create_channel, *args, **kwargs)
188-
return _ReplaceableChannel(create_channel_fn)
186+
return SwappableChannel(create_channel_fn)
189187

190188
@staticmethod
191189
def _client_version() -> str:
@@ -290,10 +288,10 @@ def _manage_channel(
290288
between `refresh_interval_min` and `refresh_interval_max`
291289
grace_period: time to allow previous channel to serve existing
292290
requests before closing, in seconds"""
293-
if not isinstance(self.transport.grpc_channel, _ReplaceableChannel):
291+
if not isinstance(self.transport.grpc_channel, SwappableChannel):
294292
warnings.warn("Channel does not support auto-refresh.")
295293
return
296-
super_channel: _ReplaceableChannel = self.transport.grpc_channel
294+
super_channel: SwappableChannel = self.transport.grpc_channel
297295
first_refresh = self._channel_init_time + random.uniform(
298296
refresh_interval_min, refresh_interval_max
299297
)
@@ -309,7 +307,7 @@ def _manage_channel(
309307
start_timestamp = time.monotonic()
310308
new_channel = super_channel.create_channel()
311309
self._ping_and_warm_instances(channel=new_channel)
312-
old_channel = super_channel.replace_wrapped_channel(new_channel)
310+
old_channel = super_channel.swap_channel(new_channel)
313311
self._invalidate_channel_stubs()
314312
if grace_period:
315313
self._is_closed.wait(grace_period)

tests/unit/data/_async/test_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@
5151
if CrossSync.is_async:
5252
from google.api_core import grpc_helpers_async
5353
from google.cloud.bigtable.data._async.client import TableAsync
54-
from google.cloud.bigtable.data._async._replaceable_channel import (
55-
_AsyncReplaceableChannel,
54+
from google.cloud.bigtable.data._async._swappable_channel import (
55+
AsyncSwappableChannel,
5656
)
5757

5858
CrossSync.add_mapping("grpc_helpers", grpc_helpers_async)
59-
CrossSync.add_mapping("ReplaceableChannel", _AsyncReplaceableChannel)
59+
CrossSync.add_mapping("SwappableChannel", AsyncSwappableChannel)
6060
else:
6161
from google.api_core import grpc_helpers
6262
from google.cloud.bigtable.data._sync_autogen.client import Table # noqa: F401
63-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import (
64-
_ReplaceableChannel,
63+
from google.cloud.bigtable.data._sync_autogen._swappable_channel import (
64+
SwappableChannel,
6565
)
6666

6767
CrossSync.add_mapping("grpc_helpers", grpc_helpers)
68-
CrossSync.add_mapping("ReplaceableChannel", _ReplaceableChannel)
68+
CrossSync.add_mapping("SwappableChannel", SwappableChannel)
6969

7070
__CROSS_SYNC_OUTPUT__ = "tests.unit.data._sync_autogen.test_client"
7171

@@ -236,7 +236,7 @@ async def test__start_background_channel_refresh(self):
236236
client, "_ping_and_warm_instances", CrossSync.Mock()
237237
) as ping_and_warm:
238238
client._emulator_host = None
239-
client.transport._grpc_channel = CrossSync.ReplaceableChannel(mock.Mock)
239+
client.transport._grpc_channel = CrossSync.SwappableChannel(mock.Mock)
240240
client._start_background_channel_refresh()
241241
assert client._channel_refresh_task is not None
242242
assert isinstance(client._channel_refresh_task, CrossSync.Task)
@@ -500,7 +500,7 @@ async def test__manage_channel_refresh(self, num_cycles):
500500
new_channel = grpc_lib.insecure_channel("localhost:8080")
501501
create_channel_mock = mock.Mock()
502502
create_channel_mock.return_value = new_channel
503-
refreshable_channel = CrossSync.ReplaceableChannel(create_channel_mock)
503+
refreshable_channel = CrossSync.SwappableChannel(create_channel_mock)
504504

505505
with mock.patch.object(CrossSync, "event_wait") as sleep:
506506
sleep.side_effect = [None for i in range(num_cycles)] + [RuntimeError]

tests/unit/data/_sync_autogen/test_client.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
str_val,
4646
)
4747
from google.api_core import grpc_helpers
48-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import (
49-
_ReplaceableChannel,
50-
)
48+
from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel
5149

5250
CrossSync._Sync_Impl.add_mapping("grpc_helpers", grpc_helpers)
53-
CrossSync._Sync_Impl.add_mapping("ReplaceableChannel", _ReplaceableChannel)
51+
CrossSync._Sync_Impl.add_mapping("SwappableChannel", SwappableChannel)
5452

5553

5654
@CrossSync._Sync_Impl.add_mapping_decorator("TestBigtableDataClient")
@@ -185,7 +183,7 @@ def test__start_background_channel_refresh(self):
185183
client, "_ping_and_warm_instances", CrossSync._Sync_Impl.Mock()
186184
) as ping_and_warm:
187185
client._emulator_host = None
188-
client.transport._grpc_channel = CrossSync._Sync_Impl.ReplaceableChannel(
186+
client.transport._grpc_channel = CrossSync._Sync_Impl.SwappableChannel(
189187
mock.Mock
190188
)
191189
client._start_background_channel_refresh()
@@ -398,9 +396,7 @@ def test__manage_channel_refresh(self, num_cycles):
398396
new_channel = grpc_lib.insecure_channel("localhost:8080")
399397
create_channel_mock = mock.Mock()
400398
create_channel_mock.return_value = new_channel
401-
refreshable_channel = CrossSync._Sync_Impl.ReplaceableChannel(
402-
create_channel_mock
403-
)
399+
refreshable_channel = CrossSync._Sync_Impl.SwappableChannel(create_channel_mock)
404400
with mock.patch.object(CrossSync._Sync_Impl, "event_wait") as sleep:
405401
sleep.side_effect = [None for i in range(num_cycles)] + [RuntimeError]
406402
client = self._make_client(project="project-id")

0 commit comments

Comments
 (0)