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

Commit 417faf0

Browse files
committed
got tests to run
1 parent a4746f0 commit 417faf0

3 files changed

Lines changed: 77 additions & 95 deletions

File tree

tests/system/data/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,67 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import asyncio
17+
import pytest
18+
import uuid
19+
from google.cloud.bigtable.data._cross_sync import CrossSync
1620

1721
TEST_FAMILY = "test-family"
1822
TEST_FAMILY_2 = "test-family-2"
1923
TEST_AGGREGATE_FAMILY = "test-aggregate-family"
24+
25+
class SystemTestRunner:
26+
"""
27+
configures a system test class with configuration for clusters/tables/etc
28+
29+
used by standard system tests, and metrics tests
30+
"""
31+
32+
@CrossSync.drop
33+
@pytest.fixture(scope="session")
34+
def event_loop(self):
35+
loop = asyncio.get_event_loop()
36+
yield loop
37+
loop.stop()
38+
loop.close()
39+
40+
@pytest.fixture(scope="session")
41+
def init_table_id(self):
42+
"""
43+
The table_id to use when creating a new test table
44+
"""
45+
return f"test-table-{uuid.uuid4().hex}"
46+
47+
@pytest.fixture(scope="session")
48+
def cluster_config(self, project_id):
49+
"""
50+
Configuration for the clusters to use when creating a new instance
51+
"""
52+
from google.cloud.bigtable_admin_v2 import types
53+
54+
cluster = {
55+
"test-cluster": types.Cluster(
56+
location=f"projects/{project_id}/locations/us-central1-b",
57+
serve_nodes=1,
58+
)
59+
}
60+
return cluster
61+
62+
@pytest.fixture(scope="session")
63+
def column_family_config(self):
64+
"""
65+
specify column families to create when creating a new test table
66+
"""
67+
from google.cloud.bigtable_admin_v2 import types
68+
69+
int_aggregate_type = types.Type.Aggregate(
70+
input_type=types.Type(int64_type={"encoding": {"big_endian_bytes": {}}}),
71+
sum={},
72+
)
73+
return {
74+
TEST_FAMILY: types.ColumnFamily(),
75+
TEST_FAMILY_2: types.ColumnFamily(),
76+
TEST_AGGREGATE_FAMILY: types.ColumnFamily(
77+
value_type=types.Type(aggregate_type=int_aggregate_type)
78+
),
79+
}

tests/system/data/test_metrics_async.py

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from google.cloud.bigtable.data._cross_sync import CrossSync
2323

2424

25-
from . import TEST_FAMILY
25+
from . import TEST_FAMILY, SystemTestRunner
2626

2727
__CROSS_SYNC_OUTPUT__ = "tests.system.data.test_metrics_autogen"
2828

@@ -54,48 +54,12 @@ def clear(self):
5454
self.completed_operations.clear()
5555
self.completed_attempts.clear()
5656

57+
def __repr__(self):
58+
return f"{self.__class__}(completed_operations={len(self.completed_operations)}, cancelled_operations={len(self.cancelled_operations)}, completed_attempts={len(self.completed_attempts)}"
5759

58-
@CrossSync.convert_class(sync_name="TestSystem")
59-
class TestMetricsAsync:
6060

61-
@CrossSync.drop
62-
@pytest.fixture(scope="session")
63-
def event_loop(self):
64-
loop = asyncio.get_event_loop()
65-
yield loop
66-
loop.stop()
67-
loop.close()
68-
69-
@pytest.fixture(scope="session")
70-
def init_table_id(self):
71-
"""
72-
The table_id to use when creating a new test table
73-
"""
74-
return f"test-metrics-{uuid.uuid4().hex}"
75-
76-
@pytest.fixture(scope="session")
77-
def cluster_config(self, project_id):
78-
"""
79-
Configuration for the clusters to use when creating a new instance
80-
"""
81-
from google.cloud.bigtable_admin_v2 import types
82-
83-
cluster = {
84-
"test-cluster": types.Cluster(
85-
location=f"projects/{project_id}/locations/us-central1-b",
86-
serve_nodes=1,
87-
)
88-
}
89-
return cluster
90-
91-
@pytest.fixture(scope="session")
92-
def column_family_config(self):
93-
"""
94-
specify column families to create when creating a new test table
95-
"""
96-
from google.cloud.bigtable_admin_v2 import types
97-
98-
return {TEST_FAMILY: types.ColumnFamily()}
61+
@CrossSync.convert_class(sync_name="TestMetrics")
62+
class TestMetricsAsync(SystemTestRunner):
9963

10064
def _make_client(self):
10165
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
@@ -136,7 +100,8 @@ async def target(self, client, table_id, instance_id, handler):
136100
table._metrics.add_handler(handler)
137101
yield table
138102

139-
async def test_read_modify_write(self, target, temp_rows):
103+
@CrossSync.pytest
104+
async def test_read_modify_write(self, target, temp_rows, handler):
140105
from google.cloud.bigtable.data.read_modify_write_rules import IncrementRule
141106

142107
row_key = b"test-row-key"
@@ -146,6 +111,12 @@ async def test_read_modify_write(self, target, temp_rows):
146111
row_key, value=0, family=family, qualifier=qualifier
147112
)
148113
rule = IncrementRule(family, qualifier, 1)
149-
result = await target.read_modify_write_row(row_key, rule)
114+
await target.read_modify_write_row(row_key, rule)
150115
breakpoint()
151-
print(result)
116+
assert handler.total() == 1
117+
assert len(handler.completed_operations) == 1
118+
assert len(handler.completed_attempts) == 1
119+
assert len(handler.cancelled_operations) == 0
120+
operation = handler.completed_operations[0]
121+
assert operation.final_status.value[0] == 0
122+
assert operation.final_status.value[0] == 0

tests/system/data/test_system_async.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from google.cloud.bigtable.data._cross_sync import CrossSync
2929

30-
from . import TEST_FAMILY, TEST_FAMILY_2, TEST_AGGREGATE_FAMILY
30+
from . import TEST_FAMILY, TEST_FAMILY_2, TEST_AGGREGATE_FAMILY, SystemTestRunner
3131

3232
if CrossSync.is_async:
3333
from google.cloud.bigtable_v2.services.bigtable.transports.grpc_asyncio import (
@@ -119,7 +119,7 @@ async def delete_rows(self):
119119

120120

121121
@CrossSync.convert_class(sync_name="TestSystem")
122-
class TestSystemAsync:
122+
class TestSystemAsync(SystemTestRunner):
123123
@CrossSync.convert
124124
@CrossSync.pytest_fixture(scope="session")
125125
async def client(self):
@@ -146,55 +146,6 @@ async def target(self, client, table_id, authorized_view_id, instance_id, reques
146146
else:
147147
raise ValueError(f"unknown target type: {request.param}")
148148

149-
@CrossSync.drop
150-
@pytest.fixture(scope="session")
151-
def event_loop(self):
152-
loop = asyncio.get_event_loop()
153-
yield loop
154-
loop.stop()
155-
loop.close()
156-
157-
@pytest.fixture(scope="session")
158-
def column_family_config(self):
159-
"""
160-
specify column families to create when creating a new test table
161-
"""
162-
from google.cloud.bigtable_admin_v2 import types
163-
164-
int_aggregate_type = types.Type.Aggregate(
165-
input_type=types.Type(int64_type={"encoding": {"big_endian_bytes": {}}}),
166-
sum={},
167-
)
168-
return {
169-
TEST_FAMILY: types.ColumnFamily(),
170-
TEST_FAMILY_2: types.ColumnFamily(),
171-
TEST_AGGREGATE_FAMILY: types.ColumnFamily(
172-
value_type=types.Type(aggregate_type=int_aggregate_type)
173-
),
174-
}
175-
176-
@pytest.fixture(scope="session")
177-
def init_table_id(self):
178-
"""
179-
The table_id to use when creating a new test table
180-
"""
181-
return f"test-table-{uuid.uuid4().hex}"
182-
183-
@pytest.fixture(scope="session")
184-
def cluster_config(self, project_id):
185-
"""
186-
Configuration for the clusters to use when creating a new instance
187-
"""
188-
from google.cloud.bigtable_admin_v2 import types
189-
190-
cluster = {
191-
"test-cluster": types.Cluster(
192-
location=f"projects/{project_id}/locations/us-central1-b",
193-
serve_nodes=1,
194-
)
195-
}
196-
return cluster
197-
198149
@CrossSync.convert
199150
@pytest.mark.usefixtures("target")
200151
async def _retrieve_cell_value(self, target, row_key):

0 commit comments

Comments
 (0)