2323from google .cloud .bigtable_v2 import ReadRowsResponse
2424from google .cloud .bigtable .data .exceptions import InvalidChunk
2525from google .cloud .bigtable .data .row import Row
26+ from google .cloud .bigtable .data ._metrics import ActiveOperationMetric
2627from ...v2_client .test_row_merger import ReadRowsTest , TestFile
2728from google .cloud .bigtable .data ._cross_sync import CrossSync
2829
2930
3031class TestReadRowsAcceptance :
3132 @staticmethod
32- def _get_operation_class ():
33- return CrossSync ._Sync_Impl ._ReadRowsOperation
33+ def _make_operation ():
34+ metric = ActiveOperationMetric ("READ_ROWS" )
35+ op = CrossSync ._Sync_Impl ._ReadRowsOperation (
36+ mock .Mock (), mock .Mock (), 5 , 5 , metric
37+ )
38+ op ._remaining_count = None
39+ return op
3440
3541 @staticmethod
3642 def _get_client_class ():
@@ -68,13 +74,8 @@ def _process_chunks(self, *chunks):
6874 def _row_stream ():
6975 yield ReadRowsResponse (chunks = chunks )
7076
71- instance = mock .Mock ()
72- instance ._remaining_count = None
73- instance ._last_yielded_row_key = None
74- chunker = self ._get_operation_class ().chunk_stream (
75- instance , self ._coro_wrapper (_row_stream ())
76- )
77- merger = self ._get_operation_class ().merge_rows (chunker )
77+ chunker = self ._make_operation ().chunk_stream (self ._coro_wrapper (_row_stream ()))
78+ merger = self ._make_operation ().merge_rows (chunker )
7879 results = []
7980 for row in merger :
8081 results .append (row )
@@ -90,13 +91,10 @@ def _scenerio_stream():
9091
9192 try :
9293 results = []
93- instance = mock .Mock ()
94- instance ._last_yielded_row_key = None
95- instance ._remaining_count = None
96- chunker = self ._get_operation_class ().chunk_stream (
97- instance , self ._coro_wrapper (_scenerio_stream ())
94+ chunker = self ._make_operation ().chunk_stream (
95+ self ._coro_wrapper (_scenerio_stream ())
9896 )
99- merger = self ._get_operation_class ().merge_rows (chunker )
97+ merger = self ._make_operation ().merge_rows (chunker )
10098 for row in merger :
10199 for cell in row :
102100 cell_result = ReadRowsTest .Result (
@@ -179,13 +177,10 @@ def test_out_of_order_rows(self):
179177 def _row_stream ():
180178 yield ReadRowsResponse (last_scanned_row_key = b"a" )
181179
182- instance = mock .Mock ()
183- instance ._remaining_count = None
184- instance ._last_yielded_row_key = b"b"
185- chunker = self ._get_operation_class ().chunk_stream (
186- instance , self ._coro_wrapper (_row_stream ())
187- )
188- merger = self ._get_operation_class ().merge_rows (chunker )
180+ op = self ._make_operation ()
181+ op ._last_yielded_row_key = b"b"
182+ chunker = op .chunk_stream (self ._coro_wrapper (_row_stream ()))
183+ merger = self ._make_operation ().merge_rows (chunker )
189184 with pytest .raises (InvalidChunk ):
190185 for _ in merger :
191186 pass
0 commit comments