2626import com .google .api .client .util .BackOff ;
2727import com .google .cloud .spanner .v1 .stub .SpannerStubSettings ;
2828import com .google .common .collect .AbstractIterator ;
29+ import com .google .common .collect .ImmutableList ;
2930import com .google .common .collect .Lists ;
3031import com .google .protobuf .ByteString ;
3132import com .google .protobuf .Duration ;
5253import org .junit .Before ;
5354import org .junit .Test ;
5455import org .junit .runner .RunWith ;
55- import org .junit .runners .JUnit4 ;
56+ import org .junit .runners .Parameterized ;
57+ import org .junit .runners .Parameterized .Parameter ;
58+ import org .junit .runners .Parameterized .Parameters ;
5659import org .mockito .Mockito ;
5760
5861/** Unit tests for {@link ResumableStreamIterator}. */
59- @ RunWith (JUnit4 .class )
62+ @ RunWith (Parameterized .class )
6063public class ResumableStreamIteratorTest {
6164 interface Starter {
6265 AbstractResultSet .CloseableIterator <PartialResultSet > startStream (
@@ -69,6 +72,14 @@ interface ResultSetStream {
6972 void close ();
7073 }
7174
75+ @ Parameter (0 )
76+ public ErrorCode errorCodeParameter ;
77+
78+ @ Parameters (name = "errorCodeParameter = {0}" )
79+ public static List <ErrorCode > data () {
80+ return ImmutableList .of (ErrorCode .UNAVAILABLE , ErrorCode .RESOURCE_EXHAUSTED );
81+ }
82+
7283 private static StatusRuntimeException statusWithRetryInfo (ErrorCode code ) {
7384 Metadata .Key <RetryInfo > key = ProtoUtils .keyForProto (RetryInfo .getDefaultInstance ());
7485 Metadata trailers = new Metadata ();
@@ -223,7 +234,7 @@ public void restart() {
223234 Mockito .when (s1 .next ())
224235 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r1" ), "a" ))
225236 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r2" ), "b" ))
226- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
237+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
227238
228239 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
229240 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r2" )))
@@ -244,7 +255,7 @@ public void restartWithHoldBack() {
244255 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r2" ), "b" ))
245256 .thenReturn (resultSet (null , "X" ))
246257 .thenReturn (resultSet (null , "X" ))
247- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
258+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
248259
249260 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
250261 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r2" )))
@@ -265,7 +276,7 @@ public void restartWithHoldBackMidStream() {
265276 .thenReturn (resultSet (null , "b" ))
266277 .thenReturn (resultSet (null , "c" ))
267278 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r2" ), "d" ))
268- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
279+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
269280
270281 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
271282 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r2" )))
@@ -360,7 +371,7 @@ public void bufferLimitRestart() {
360371 Mockito .when (s1 .next ())
361372 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r1" ), "a" ))
362373 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r2" ), "b" ))
363- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
374+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
364375
365376 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
366377 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r2" )))
@@ -380,7 +391,7 @@ public void bufferLimitRestartWithinLimitAtStartOfResults() {
380391 Mockito .when (starter .startStream (null )).thenReturn (new ResultSetIterator (s1 ));
381392 Mockito .when (s1 .next ())
382393 .thenReturn (resultSet (null , "XXXXXX" ))
383- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
394+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
384395
385396 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
386397 Mockito .when (starter .startStream (null )).thenReturn (new ResultSetIterator (s2 ));
@@ -400,7 +411,7 @@ public void bufferLimitRestartWithinLimitMidResults() {
400411 Mockito .when (s1 .next ())
401412 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r1" ), "a" ))
402413 .thenReturn (resultSet (null , "XXXXXX" ))
403- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
414+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
404415
405416 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
406417 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r1" )))
@@ -422,11 +433,11 @@ public void bufferLimitMissingTokensUnsafeToRetry() {
422433 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r1" ), "a" ))
423434 .thenReturn (resultSet (null , "b" ))
424435 .thenReturn (resultSet (null , "c" ))
425- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
436+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
426437
427438 assertThat (consumeAtMost (3 , resumableStreamIterator )).containsExactly ("a" , "b" , "c" ).inOrder ();
428439 SpannerException e = assertThrows (SpannerException .class , () -> resumableStreamIterator .next ());
429- assertThat (e .getErrorCode ()).isEqualTo (ErrorCode . UNAVAILABLE );
440+ assertThat (e .getErrorCode ()).isEqualTo (errorCodeParameter );
430441 }
431442
432443 @ Test
@@ -439,7 +450,7 @@ public void bufferLimitMissingTokensSafeToRetry() {
439450 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r1" ), "a" ))
440451 .thenReturn (resultSet (null , "b" ))
441452 .thenReturn (resultSet (ByteString .copyFromUtf8 ("r3" ), "c" ))
442- .thenThrow (new RetryableException (ErrorCode . UNAVAILABLE , "failed by test" ));
453+ .thenThrow (new RetryableException (errorCodeParameter , "failed by test" ));
443454
444455 ResultSetStream s2 = Mockito .mock (ResultSetStream .class );
445456 Mockito .when (starter .startStream (ByteString .copyFromUtf8 ("r3" )))
0 commit comments