@@ -103,6 +103,12 @@ def _pages_w_unavailable(pages):
103
103
raise google .api_core .exceptions .ServiceUnavailable ("test: please reconnect" )
104
104
105
105
106
+ def _pages_w_unknown (pages ):
107
+ for page in pages :
108
+ yield page
109
+ raise google .api_core .exceptions .Unknown ("No status received" )
110
+
111
+
106
112
def _avro_blocks_w_deadline (avro_blocks ):
107
113
for block in avro_blocks :
108
114
yield block
@@ -237,14 +243,19 @@ def test_rows_w_reconnect(class_under_test, mock_gapic_client):
237
243
]
238
244
avro_blocks_1 = _pages_w_unavailable (_bq_to_avro_blocks (bq_blocks_1 , avro_schema ))
239
245
bq_blocks_2 = [[{"int_col" : 1024 }, {"int_col" : 512 }], [{"int_col" : 256 }]]
240
- avro_blocks_2 = _bq_to_avro_blocks (bq_blocks_2 , avro_schema )
241
246
avro_blocks_2 = _pages_w_resumable_internal_error (
242
247
_bq_to_avro_blocks (bq_blocks_2 , avro_schema )
243
248
)
244
- bq_blocks_3 = [[{"int_col" : 567 }, {"int_col" : 789 }], [{"int_col" : 890 }]]
245
- avro_blocks_3 = _bq_to_avro_blocks (bq_blocks_3 , avro_schema )
246
-
247
- mock_gapic_client .read_rows .side_effect = (avro_blocks_2 , avro_blocks_3 )
249
+ bq_blocks_3 = [[{"int_col" : - 1 }, {"int_col" : - 2 }], [{"int_col" : - 4 }]]
250
+ avro_blocks_3 = _pages_w_unknown (_bq_to_avro_blocks (bq_blocks_3 , avro_schema ))
251
+ bq_blocks_4 = [[{"int_col" : 567 }, {"int_col" : 789 }], [{"int_col" : 890 }]]
252
+ avro_blocks_4 = _bq_to_avro_blocks (bq_blocks_4 , avro_schema )
253
+
254
+ mock_gapic_client .read_rows .side_effect = (
255
+ avro_blocks_2 ,
256
+ avro_blocks_3 ,
257
+ avro_blocks_4 ,
258
+ )
248
259
249
260
reader = class_under_test (
250
261
avro_blocks_1 ,
@@ -260,16 +271,20 @@ def test_rows_w_reconnect(class_under_test, mock_gapic_client):
260
271
itertools .chain .from_iterable (bq_blocks_1 ),
261
272
itertools .chain .from_iterable (bq_blocks_2 ),
262
273
itertools .chain .from_iterable (bq_blocks_3 ),
274
+ itertools .chain .from_iterable (bq_blocks_4 ),
263
275
)
264
276
)
265
277
266
278
assert tuple (got ) == expected
267
279
mock_gapic_client .read_rows .assert_any_call (
268
280
read_stream = "teststream" , offset = 4 , metadata = {"test-key" : "test-value" }
269
281
)
270
- mock_gapic_client .read_rows .assert_called_with (
282
+ mock_gapic_client .read_rows .assert_any_call (
271
283
read_stream = "teststream" , offset = 7 , metadata = {"test-key" : "test-value" }
272
284
)
285
+ mock_gapic_client .read_rows .assert_called_with (
286
+ read_stream = "teststream" , offset = 10 , metadata = {"test-key" : "test-value" }
287
+ )
273
288
274
289
275
290
def test_rows_w_reconnect_by_page (class_under_test , mock_gapic_client ):
0 commit comments