Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 4871abd

Browse files
committed
Merge branch 'main' into csm_1_data_model
2 parents 05fe577 + 6fa3008 commit 4871abd

5 files changed

Lines changed: 81 additions & 47 deletions

File tree

tests/system/admin_overlay/test_system_async.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,27 @@ async def create_instance(
143143
default_storage_type=storage_type,
144144
)
145145

146-
create_instance_request = admin_v2.CreateInstanceRequest(
147-
parent=instance_admin_client.common_project_path(project_id),
148-
instance_id=instance_id,
149-
instance=admin_v2.Instance(
150-
display_name=instance_id[
151-
:30
152-
], # truncate to 30 characters because of character limit
153-
),
154-
clusters=clusters,
155-
)
156-
operation = await instance_admin_client.create_instance(create_instance_request)
157-
instance = await operation.result()
146+
# Instance and cluster creation are currently unsupported in the Bigtable emulator
147+
if os.getenv(BIGTABLE_EMULATOR):
148+
# All we need for system tests so far is the instance name.
149+
instance = admin_v2.Instance(
150+
name=instance_admin_client.instance_path(project_id, instance_id),
151+
)
152+
else:
153+
create_instance_request = admin_v2.CreateInstanceRequest(
154+
parent=instance_admin_client.common_project_path(project_id),
155+
instance_id=instance_id,
156+
instance=admin_v2.Instance(
157+
display_name=instance_id[
158+
:30
159+
], # truncate to 30 characters because of character limit
160+
),
161+
clusters=clusters,
162+
)
163+
operation = await instance_admin_client.create_instance(create_instance_request)
164+
instance = await operation.result()
158165

159-
instances_to_delete.append(instance)
166+
instances_to_delete.append(instance)
160167

161168
# Create a table within the instance
162169
create_table_request = admin_v2.CreateTableRequest(
@@ -272,6 +279,10 @@ async def assert_table_cell_value_equal_to(
272279
}
273280
)
274281
@CrossSync.pytest
282+
@pytest.mark.skipif(
283+
os.getenv(BIGTABLE_EMULATOR),
284+
reason="Backups are not supported in the Bigtable emulator",
285+
)
275286
@pytest.mark.parametrize(
276287
"second_instance_storage_type,expect_optimize_operation",
277288
[

tests/system/admin_overlay/test_system_autogen.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,20 @@ def create_instance(
113113
location=instance_admin_client.common_location_path(project_id, location),
114114
default_storage_type=storage_type,
115115
)
116-
create_instance_request = admin_v2.CreateInstanceRequest(
117-
parent=instance_admin_client.common_project_path(project_id),
118-
instance_id=instance_id,
119-
instance=admin_v2.Instance(display_name=instance_id[:30]),
120-
clusters=clusters,
121-
)
122-
operation = instance_admin_client.create_instance(create_instance_request)
123-
instance = operation.result()
124-
instances_to_delete.append(instance)
116+
if os.getenv(BIGTABLE_EMULATOR):
117+
instance = admin_v2.Instance(
118+
name=instance_admin_client.instance_path(project_id, instance_id)
119+
)
120+
else:
121+
create_instance_request = admin_v2.CreateInstanceRequest(
122+
parent=instance_admin_client.common_project_path(project_id),
123+
instance_id=instance_id,
124+
instance=admin_v2.Instance(display_name=instance_id[:30]),
125+
clusters=clusters,
126+
)
127+
operation = instance_admin_client.create_instance(create_instance_request)
128+
instance = operation.result()
129+
instances_to_delete.append(instance)
125130
create_table_request = admin_v2.CreateTableRequest(
126131
parent=instance_admin_client.instance_path(project_id, instance_id),
127132
table_id=TEST_TABLE_NAME,
@@ -201,6 +206,10 @@ def assert_table_cell_value_equal_to(
201206
assert latest_cell.value.decode("utf-8") == value
202207

203208

209+
@pytest.mark.skipif(
210+
os.getenv(BIGTABLE_EMULATOR),
211+
reason="Backups are not supported in the Bigtable emulator",
212+
)
204213
@pytest.mark.parametrize(
205214
"second_instance_storage_type,expect_optimize_operation",
206215
[(admin_v2.StorageType.HDD, False), (admin_v2.StorageType.SSD, True)],
@@ -215,15 +224,15 @@ def test_optimize_restored_table(
215224
second_instance_storage_type,
216225
expect_optimize_operation,
217226
):
218-
instance_with_backup, table_to_backup = create_instance(
227+
(instance_with_backup, table_to_backup) = create_instance(
219228
instance_admin_client,
220229
table_admin_client,
221230
data_client,
222231
admin_overlay_project_id,
223232
instances_to_delete,
224233
admin_v2.StorageType.HDD,
225234
)
226-
instance_to_restore, _ = create_instance(
235+
(instance_to_restore, _) = create_instance(
227236
instance_admin_client,
228237
table_admin_client,
229238
data_client,
@@ -273,7 +282,7 @@ def test_wait_for_consistency(
273282
instances_to_delete,
274283
admin_overlay_project_id,
275284
):
276-
instance, table = create_instance(
285+
(instance, table) = create_instance(
277286
instance_admin_client,
278287
table_admin_client,
279288
data_client,

tests/system/data/test_system_async.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ async def delete_rows(self):
119119

120120
@CrossSync.convert_class(sync_name="TestSystem")
121121
class TestSystemAsync:
122+
def _make_client(self):
123+
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
124+
return CrossSync.DataClient(project=project)
125+
122126
@CrossSync.convert
123127
@CrossSync.pytest_fixture(scope="session")
124128
async def client(self):
125-
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
126-
async with CrossSync.DataClient(project=project) as client:
129+
async with self._make_client() as client:
127130
yield client
128131

129132
@CrossSync.convert
@@ -268,8 +271,7 @@ async def test_channel_refresh(self, table_id, instance_id, temp_rows):
268271
"""
269272
await temp_rows.add_row(b"row_key_1")
270273
await temp_rows.add_row(b"row_key_2")
271-
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
272-
client = CrossSync.DataClient(project=project)
274+
client = self._make_client()
273275
# start custom refresh task
274276
try:
275277
client._channel_refresh_task = CrossSync.create_task(

tests/system/data/test_system_autogen.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ def delete_rows(self):
102102

103103

104104
class TestSystem:
105+
def _make_client(self):
106+
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
107+
return CrossSync._Sync_Impl.DataClient(project=project)
108+
105109
@pytest.fixture(scope="session")
106110
def client(self):
107-
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
108-
with CrossSync._Sync_Impl.DataClient(project=project) as client:
111+
with self._make_client() as client:
109112
yield client
110113

111114
@pytest.fixture(scope="session", params=TARGETS)
@@ -222,8 +225,7 @@ def test_channel_refresh(self, table_id, instance_id, temp_rows):
222225
to ensure new channel works"""
223226
temp_rows.add_row(b"row_key_1")
224227
temp_rows.add_row(b"row_key_2")
225-
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
226-
client = CrossSync._Sync_Impl.DataClient(project=project)
228+
client = self._make_client()
227229
try:
228230
client._channel_refresh_task = CrossSync._Sync_Impl.create_task(
229231
client._manage_channel,
@@ -258,7 +260,7 @@ def test_mutation_set_cell(self, target, temp_rows):
258260
"""Ensure cells can be set properly"""
259261
row_key = b"bulk_mutate"
260262
new_value = uuid.uuid4().hex.encode()
261-
row_key, mutation = self._create_row_and_mutation(
263+
(row_key, mutation) = self._create_row_and_mutation(
262264
target, temp_rows, new_value=new_value
263265
)
264266
target.mutate_row(row_key, mutation)
@@ -312,7 +314,7 @@ def test_bulk_mutations_set_cell(self, client, target, temp_rows):
312314
from google.cloud.bigtable.data.mutations import RowMutationEntry
313315

314316
new_value = uuid.uuid4().hex.encode()
315-
row_key, mutation = self._create_row_and_mutation(
317+
(row_key, mutation) = self._create_row_and_mutation(
316318
target, temp_rows, new_value=new_value
317319
)
318320
bulk_mutation = RowMutationEntry(row_key, [mutation])
@@ -347,11 +349,11 @@ def test_mutations_batcher_context_manager(self, client, target, temp_rows):
347349
"""test batcher with context manager. Should flush on exit"""
348350
from google.cloud.bigtable.data.mutations import RowMutationEntry
349351

350-
new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)]
351-
row_key, mutation = self._create_row_and_mutation(
352+
(new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)]
353+
(row_key, mutation) = self._create_row_and_mutation(
352354
target, temp_rows, new_value=new_value
353355
)
354-
row_key2, mutation2 = self._create_row_and_mutation(
356+
(row_key2, mutation2) = self._create_row_and_mutation(
355357
target, temp_rows, new_value=new_value2
356358
)
357359
bulk_mutation = RowMutationEntry(row_key, [mutation])
@@ -372,7 +374,7 @@ def test_mutations_batcher_timer_flush(self, client, target, temp_rows):
372374
from google.cloud.bigtable.data.mutations import RowMutationEntry
373375

374376
new_value = uuid.uuid4().hex.encode()
375-
row_key, mutation = self._create_row_and_mutation(
377+
(row_key, mutation) = self._create_row_and_mutation(
376378
target, temp_rows, new_value=new_value
377379
)
378380
bulk_mutation = RowMutationEntry(row_key, [mutation])
@@ -394,12 +396,12 @@ def test_mutations_batcher_count_flush(self, client, target, temp_rows):
394396
"""batch should flush after flush_limit_mutation_count mutations"""
395397
from google.cloud.bigtable.data.mutations import RowMutationEntry
396398

397-
new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)]
398-
row_key, mutation = self._create_row_and_mutation(
399+
(new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)]
400+
(row_key, mutation) = self._create_row_and_mutation(
399401
target, temp_rows, new_value=new_value
400402
)
401403
bulk_mutation = RowMutationEntry(row_key, [mutation])
402-
row_key2, mutation2 = self._create_row_and_mutation(
404+
(row_key2, mutation2) = self._create_row_and_mutation(
403405
target, temp_rows, new_value=new_value2
404406
)
405407
bulk_mutation2 = RowMutationEntry(row_key2, [mutation2])
@@ -426,12 +428,12 @@ def test_mutations_batcher_bytes_flush(self, client, target, temp_rows):
426428
"""batch should flush after flush_limit_bytes bytes"""
427429
from google.cloud.bigtable.data.mutations import RowMutationEntry
428430

429-
new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)]
430-
row_key, mutation = self._create_row_and_mutation(
431+
(new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)]
432+
(row_key, mutation) = self._create_row_and_mutation(
431433
target, temp_rows, new_value=new_value
432434
)
433435
bulk_mutation = RowMutationEntry(row_key, [mutation])
434-
row_key2, mutation2 = self._create_row_and_mutation(
436+
(row_key2, mutation2) = self._create_row_and_mutation(
435437
target, temp_rows, new_value=new_value2
436438
)
437439
bulk_mutation2 = RowMutationEntry(row_key2, [mutation2])
@@ -457,11 +459,11 @@ def test_mutations_batcher_no_flush(self, client, target, temp_rows):
457459

458460
new_value = uuid.uuid4().hex.encode()
459461
start_value = b"unchanged"
460-
row_key, mutation = self._create_row_and_mutation(
462+
(row_key, mutation) = self._create_row_and_mutation(
461463
target, temp_rows, start_value=start_value, new_value=new_value
462464
)
463465
bulk_mutation = RowMutationEntry(row_key, [mutation])
464-
row_key2, mutation2 = self._create_row_and_mutation(
466+
(row_key2, mutation2) = self._create_row_and_mutation(
465467
target, temp_rows, start_value=start_value, new_value=new_value
466468
)
467469
bulk_mutation2 = RowMutationEntry(row_key2, [mutation2])

tests/unit/data/_sync_autogen/test_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ def _make_one(
938938

939939
def test_ctor(self):
940940
from google.cloud.bigtable.data._helpers import _WarmedInstanceKey
941+
from google.cloud.bigtable.data._metrics import (
942+
BigtableClientSideMetricsController,
943+
)
941944

942945
expected_table_id = "table-id"
943946
expected_instance_id = "instance-id"
@@ -978,6 +981,8 @@ def test_ctor(self):
978981
instance_key = _WarmedInstanceKey(table.instance_name, table.app_profile_id)
979982
assert instance_key in client._active_instances
980983
assert client._instance_owners[instance_key] == {id(table)}
984+
assert isinstance(table._metrics, BigtableClientSideMetricsController)
985+
assert table._metrics.interceptor == client._metrics_interceptor
981986
assert table.default_operation_timeout == expected_operation_timeout
982987
assert table.default_attempt_timeout == expected_attempt_timeout
983988
assert (
@@ -1195,6 +1200,9 @@ def _make_one(
11951200

11961201
def test_ctor(self):
11971202
from google.cloud.bigtable.data._helpers import _WarmedInstanceKey
1203+
from google.cloud.bigtable.data._metrics import (
1204+
BigtableClientSideMetricsController,
1205+
)
11981206

11991207
expected_table_id = "table-id"
12001208
expected_instance_id = "instance-id"
@@ -1242,6 +1250,8 @@ def test_ctor(self):
12421250
instance_key = _WarmedInstanceKey(view.instance_name, view.app_profile_id)
12431251
assert instance_key in client._active_instances
12441252
assert client._instance_owners[instance_key] == {id(view)}
1253+
assert isinstance(view._metrics, BigtableClientSideMetricsController)
1254+
assert view._metrics.interceptor == client._metrics_interceptor
12451255
assert view.default_operation_timeout == expected_operation_timeout
12461256
assert view.default_attempt_timeout == expected_attempt_timeout
12471257
assert (

0 commit comments

Comments
 (0)