16
16
package com .google .cloud .bigtable .data .v2 .stub .readrows ;
17
17
18
18
import com .google .api .gax .core .NoCredentialsProvider ;
19
+ import com .google .api .gax .grpc .GrpcStatusCode ;
19
20
import com .google .api .gax .grpc .GrpcTransportChannel ;
21
+ import com .google .api .gax .rpc .ApiException ;
20
22
import com .google .api .gax .rpc .FixedTransportChannelProvider ;
23
+ import com .google .api .gax .rpc .InternalException ;
21
24
import com .google .api .gax .rpc .ServerStream ;
22
25
import com .google .bigtable .v2 .BigtableGrpc ;
23
26
import com .google .bigtable .v2 .ReadRowsRequest ;
39
42
import com .google .protobuf .StringValue ;
40
43
import io .grpc .Status ;
41
44
import io .grpc .Status .Code ;
45
+ import io .grpc .StatusRuntimeException ;
42
46
import io .grpc .stub .StreamObserver ;
43
47
import io .grpc .testing .GrpcServerRule ;
44
48
import java .io .IOException ;
@@ -260,6 +264,30 @@ public void retryWithLastScannedKeyTest() {
260
264
Truth .assertThat (actualResults ).containsExactly ("r7" ).inOrder ();
261
265
}
262
266
267
+ @ Test
268
+ public void retryRstStreamExceptionTest () {
269
+ ApiException exception =
270
+ new InternalException (
271
+ new StatusRuntimeException (
272
+ Status .INTERNAL .withDescription (
273
+ "HTTP/2 error code: INTERNAL_ERROR\n Received Rst stream" )),
274
+ GrpcStatusCode .of (Code .INTERNAL ),
275
+ false );
276
+ service .expectations .add (
277
+ RpcExpectation .create ()
278
+ .expectRequest ("k1" )
279
+ .expectRequest (Range .closedOpen ("r1" , "r3" ))
280
+ .respondWithException (Code .INTERNAL , exception ));
281
+ service .expectations .add (
282
+ RpcExpectation .create ()
283
+ .expectRequest ("k1" )
284
+ .expectRequest (Range .closedOpen ("r1" , "r3" ))
285
+ .respondWith ("k1" , "r1" , "r2" ));
286
+
287
+ List <String > actualResults = getResults (Query .create (TABLE_ID ).rowKey ("k1" ).range ("r1" , "r3" ));
288
+ Truth .assertThat (actualResults ).containsExactly ("k1" , "r1" , "r2" ).inOrder ();
289
+ }
290
+
263
291
private List <String > getResults (Query query ) {
264
292
ServerStream <Row > actualRows = client .readRows (query );
265
293
List <String > actualValues = Lists .newArrayList ();
@@ -292,6 +320,8 @@ public void readRows(
292
320
}
293
321
if (expectedRpc .statusCode .toStatus ().isOk ()) {
294
322
responseObserver .onCompleted ();
323
+ } else if (expectedRpc .exception != null ) {
324
+ responseObserver .onError (expectedRpc .exception );
295
325
} else {
296
326
responseObserver .onError (expectedRpc .statusCode .toStatus ().asRuntimeException ());
297
327
}
@@ -301,6 +331,7 @@ public void readRows(
301
331
private static class RpcExpectation {
302
332
ReadRowsRequest .Builder requestBuilder ;
303
333
Status .Code statusCode ;
334
+ ApiException exception ;
304
335
List <ReadRowsResponse > responses ;
305
336
306
337
private RpcExpectation () {
@@ -370,6 +401,12 @@ RpcExpectation respondWithStatus(Status.Code code) {
370
401
return this ;
371
402
}
372
403
404
+ RpcExpectation respondWithException (Status .Code code , ApiException exception ) {
405
+ this .statusCode = code ;
406
+ this .exception = exception ;
407
+ return this ;
408
+ }
409
+
373
410
RpcExpectation respondWith (String ... responses ) {
374
411
for (String response : responses ) {
375
412
this .responses .add (
0 commit comments