2424import com .google .api .gax .core .NoCredentialsProvider ;
2525import com .google .api .gax .grpc .testing .LocalChannelProvider ;
2626import com .google .api .gax .retrying .RetrySettings ;
27- import com .google .api .gax .rpc .StatusCode ;
2827import com .google .api .gax .rpc .UnaryCallSettings ;
2928import com .google .api .gax .rpc .UnaryCallSettings .Builder ;
3029import com .google .cloud .NoCredentials ;
3332import com .google .cloud .spanner .TransactionRunner .TransactionCallable ;
3433import com .google .cloud .spanner .v1 .SpannerClient ;
3534import com .google .cloud .spanner .v1 .SpannerSettings ;
36- import com .google .common .collect .ImmutableSet ;
3735import com .google .protobuf .ListValue ;
3836import com .google .spanner .v1 .ResultSetMetadata ;
3937import com .google .spanner .v1 .StructType ;
4341import io .grpc .StatusRuntimeException ;
4442import io .grpc .inprocess .InProcessServerBuilder ;
4543import java .io .IOException ;
46- import java .util .ArrayList ;
4744import java .util .Arrays ;
48- import java .util .Collection ;
49- import java .util .List ;
5045import java .util .concurrent .ScheduledThreadPoolExecutor ;
5146import java .util .concurrent .atomic .AtomicInteger ;
5247import org .junit .After ;
5348import org .junit .AfterClass ;
5449import org .junit .Before ;
5550import org .junit .BeforeClass ;
51+ import org .junit .Ignore ;
5652import org .junit .Rule ;
5753import org .junit .Test ;
5854import org .junit .rules .ExpectedException ;
5955import org .junit .runner .RunWith ;
60- import org .junit .runners .Parameterized ;
61- import org .junit .runners .Parameterized .Parameter ;
62- import org .junit .runners .Parameterized .Parameters ;
56+ import org .junit .runners .JUnit4 ;
6357import org .threeten .bp .Duration ;
6458
65- @ RunWith (Parameterized .class )
59+ @ RunWith (JUnit4 .class )
6660public class SpannerGaxRetryTest {
6761 private static final ResultSetMetadata READ_METADATA =
6862 ResultSetMetadata .newBuilder ()
@@ -144,17 +138,6 @@ public class SpannerGaxRetryTest {
144138 private static Spanner spanner ;
145139 private static DatabaseClient client ;
146140
147- @ Parameter (0 )
148- public boolean enableGaxRetries ;
149-
150- @ Parameters (name = "enable GAX retries = {0}" )
151- public static Collection <Object []> data () {
152- List <Object []> params = new ArrayList <>();
153- params .add (new Object [] {true });
154- params .add (new Object [] {false });
155- return params ;
156- }
157-
158141 @ Rule public ExpectedException expectedException = ExpectedException .none ();
159142
160143 @ BeforeClass
@@ -232,27 +215,6 @@ public Void apply(Builder<?, ?> input) {
232215 .executeStreamingSqlSettings ()
233216 .setRetrySettings (retrySettings );
234217 builder .getSpannerStubSettingsBuilder ().streamingReadSettings ().setRetrySettings (retrySettings );
235- if (!enableGaxRetries ) {
236- // Disable retries by removing all retryable codes.
237- builder
238- .getSpannerStubSettingsBuilder ()
239- .applyToAllUnaryMethods (
240- new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
241- @ Override
242- public Void apply (Builder <?, ?> input ) {
243- input .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
244- return null ;
245- }
246- });
247- builder
248- .getSpannerStubSettingsBuilder ()
249- .executeStreamingSqlSettings ()
250- .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
251- builder
252- .getSpannerStubSettingsBuilder ()
253- .streamingReadSettings ()
254- .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
255- }
256218 spanner = builder .build ().getService ();
257219 client = spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
258220 }
@@ -297,9 +259,7 @@ public Long run(TransactionContext transaction) throws Exception {
297259
298260 @ Test
299261 public void singleUseTimeout () {
300- if (enableGaxRetries ) {
301- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
302- }
262+ expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
303263 mockSpanner .setCreateSessionExecutionTime (ONE_SECOND );
304264 try (ResultSet rs = client .singleUse ().executeQuery (SELECT1AND2 )) {
305265 while (rs .next ()) {}
@@ -308,9 +268,6 @@ public void singleUseTimeout() {
308268
309269 @ Test
310270 public void singleUseUnavailable () {
311- if (!enableGaxRetries ) {
312- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .UNAVAILABLE ));
313- }
314271 mockSpanner .addException (UNAVAILABLE );
315272 try (ResultSet rs = client .singleUse ().executeQuery (SELECT1AND2 )) {
316273 while (rs .next ()) {}
@@ -346,9 +303,7 @@ public void singleUseInternal() {
346303
347304 @ Test
348305 public void singleUseReadOnlyTransactionTimeout () {
349- if (enableGaxRetries ) {
350- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
351- }
306+ expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
352307 mockSpanner .setCreateSessionExecutionTime (ONE_SECOND );
353308 try (ResultSet rs = client .singleUseReadOnlyTransaction ().executeQuery (SELECT1AND2 )) {
354309 while (rs .next ()) {}
@@ -357,28 +312,24 @@ public void singleUseReadOnlyTransactionTimeout() {
357312
358313 @ Test
359314 public void singleUseReadOnlyTransactionUnavailable () {
360- if (!enableGaxRetries ) {
361- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .UNAVAILABLE ));
362- }
363315 mockSpanner .addException (UNAVAILABLE );
364316 try (ResultSet rs = client .singleUseReadOnlyTransaction ().executeQuery (SELECT1AND2 )) {
365317 while (rs .next ()) {}
366318 }
367319 }
368320
369321 @ Test
322+ @ Ignore ("enable once gax 1.47 is released" )
370323 public void singleUseExecuteStreamingSqlTimeout () {
371- // Streaming calls do not timeout.
372- mockSpanner .setExecuteStreamingSqlExecutionTime (ONE_SECOND );
324+ expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
373325 try (ResultSet rs = client .singleUse ().executeQuery (SELECT1AND2 )) {
326+ mockSpanner .setExecuteStreamingSqlExecutionTime (ONE_SECOND );
374327 while (rs .next ()) {}
375328 }
376329 }
377330
378331 @ Test
379332 public void singleUseExecuteStreamingSqlUnavailable () {
380- // executeStreamingSql is always retried by the Spanner library, even if gax retries have been
381- // disabled.
382333 try (ResultSet rs = client .singleUse ().executeQuery (SELECT1AND2 )) {
383334 mockSpanner .addException (UNAVAILABLE );
384335 while (rs .next ()) {}
@@ -388,9 +339,7 @@ public void singleUseExecuteStreamingSqlUnavailable() {
388339 @ Test
389340 public void readWriteTransactionTimeout () {
390341 warmUpSessionPool ();
391- if (enableGaxRetries ) {
392- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
393- }
342+ expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
394343 mockSpanner .setBeginTransactionExecutionTime (ONE_SECOND );
395344 TransactionRunner runner = client .readWriteTransaction ();
396345 long updateCount =
@@ -407,9 +356,6 @@ public Long run(TransactionContext transaction) throws Exception {
407356 @ Test
408357 public void readWriteTransactionUnavailable () {
409358 warmUpSessionPool ();
410- if (!enableGaxRetries ) {
411- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .UNAVAILABLE ));
412- }
413359 mockSpanner .addException (UNAVAILABLE );
414360 TransactionRunner runner = client .readWriteTransaction ();
415361 long updateCount =
@@ -492,9 +438,7 @@ public Long run(TransactionContext transaction) throws Exception {
492438 @ Test
493439 public void transactionManagerTimeout () {
494440 warmUpSessionPool ();
495- if (enableGaxRetries ) {
496- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
497- }
441+ expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .DEADLINE_EXCEEDED ));
498442 mockSpanner .setBeginTransactionExecutionTime (ONE_SECOND );
499443 try (TransactionManager txManager = client .transactionManager ()) {
500444 TransactionContext tx = txManager .begin ();
@@ -514,9 +458,6 @@ public void transactionManagerTimeout() {
514458 @ Test
515459 public void transactionManagerUnavailable () {
516460 warmUpSessionPool ();
517- if (!enableGaxRetries ) {
518- expectedException .expect (SpannerMatchers .isSpannerException (ErrorCode .UNAVAILABLE ));
519- }
520461 mockSpanner .addException (UNAVAILABLE );
521462 try (TransactionManager txManager = client .transactionManager ()) {
522463 TransactionContext tx = txManager .begin ();
0 commit comments