Skip to content

Commit 9659047

Browse files
olavloitesduskis
authored andcommitted
fix test cases for gax 1.47 (#5625)
1 parent 3068ac9 commit 9659047

3 files changed

Lines changed: 22 additions & 179 deletions

File tree

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminGaxTest.java

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
import com.google.api.gax.longrunning.OperationFuture;
2222
import com.google.api.gax.paging.Page;
2323
import com.google.api.gax.retrying.RetrySettings;
24-
import com.google.api.gax.rpc.StatusCode;
2524
import com.google.api.gax.rpc.UnaryCallSettings;
2625
import com.google.api.gax.rpc.UnaryCallSettings.Builder;
2726
import com.google.cloud.NoCredentials;
2827
import com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl;
2928
import com.google.common.base.Throwables;
30-
import com.google.common.collect.ImmutableSet;
3129
import com.google.common.collect.Lists;
3230
import com.google.protobuf.AbstractMessage;
3331
import com.google.protobuf.Any;
@@ -183,22 +181,17 @@ public boolean isRetryable() {
183181
private static LocalChannelProvider channelProvider;
184182

185183
@Parameter(0)
186-
public boolean enableGaxRetries;
187-
188-
@Parameter(1)
189184
public int exceptionAtCall;
190185

191-
@Parameter(2)
186+
@Parameter(1)
192187
public ExceptionType exceptionType;
193188

194-
@Parameters(name = "enable GAX retries = {0}, exception at call = {1}, exception type = {2}")
189+
@Parameters(name = "exception at call = {0}, exception type = {1}")
195190
public static Collection<Object[]> data() {
196191
List<Object[]> params = new ArrayList<>();
197-
for (boolean enableRetries : new boolean[] {true, false}) {
198-
for (int exceptionAtCall : new int[] {0, 1}) {
199-
for (ExceptionType exceptionType : ExceptionType.values()) {
200-
params.add(new Object[] {enableRetries, exceptionAtCall, exceptionType});
201-
}
192+
for (int exceptionAtCall : new int[] {0, 1}) {
193+
for (ExceptionType exceptionType : ExceptionType.values()) {
194+
params.add(new Object[] {exceptionAtCall, exceptionType});
202195
}
203196
}
204197
return params;
@@ -272,43 +265,6 @@ public Void apply(Builder<?, ?> input) {
272265
.toBuilder()
273266
.setRetrySettings(retrySettings)
274267
.build());
275-
if (!enableGaxRetries) {
276-
// Disable retries by removing all retryable codes.
277-
builder
278-
.getDatabaseAdminStubSettingsBuilder()
279-
.applyToAllUnaryMethods(
280-
new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() {
281-
@Override
282-
public Void apply(Builder<?, ?> input) {
283-
input.setRetryableCodes(ImmutableSet.<StatusCode.Code>of());
284-
return null;
285-
}
286-
});
287-
builder
288-
.getDatabaseAdminStubSettingsBuilder()
289-
.createDatabaseOperationSettings()
290-
.setInitialCallSettings(
291-
builder
292-
.getDatabaseAdminStubSettingsBuilder()
293-
.createDatabaseOperationSettings()
294-
.getInitialCallSettings()
295-
.toBuilder()
296-
.setRetrySettings(retrySettings)
297-
.setRetryableCodes(ImmutableSet.<StatusCode.Code>of())
298-
.build());
299-
builder
300-
.getDatabaseAdminStubSettingsBuilder()
301-
.updateDatabaseDdlOperationSettings()
302-
.setInitialCallSettings(
303-
builder
304-
.getDatabaseAdminStubSettingsBuilder()
305-
.updateDatabaseDdlOperationSettings()
306-
.getInitialCallSettings()
307-
.toBuilder()
308-
.setRetrySettings(retrySettings)
309-
.setRetryableCodes(ImmutableSet.<StatusCode.Code>of())
310-
.build());
311-
}
312268
spanner = builder.build().getService();
313269
client = spanner.getDatabaseAdminClient();
314270
}
@@ -319,12 +275,7 @@ public void tearDown() throws Exception {
319275
}
320276

321277
private Exception setupException() {
322-
if (exceptionType.isRetryable()) {
323-
if (!enableGaxRetries) {
324-
expectedException.expect(
325-
SpannerMatchers.isSpannerException(exceptionType.getExpectedErrorCodeWithoutGax()));
326-
}
327-
} else {
278+
if (!exceptionType.isRetryable()) {
328279
expectedException.expect(
329280
SpannerMatchers.isSpannerException(exceptionType.getExpectedErrorCodeWithGax()));
330281
}

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminGaxTest.java

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
import com.google.api.gax.longrunning.OperationFuture;
2222
import com.google.api.gax.paging.Page;
2323
import com.google.api.gax.retrying.RetrySettings;
24-
import com.google.api.gax.rpc.StatusCode;
2524
import com.google.api.gax.rpc.UnaryCallSettings;
2625
import com.google.api.gax.rpc.UnaryCallSettings.Builder;
2726
import com.google.cloud.NoCredentials;
2827
import com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl;
2928
import com.google.common.base.Throwables;
30-
import com.google.common.collect.ImmutableSet;
3129
import com.google.common.collect.Lists;
3230
import com.google.protobuf.AbstractMessage;
3331
import com.google.protobuf.Any;
@@ -186,22 +184,17 @@ public boolean isRetryable() {
186184
private static LocalChannelProvider channelProvider;
187185

188186
@Parameter(0)
189-
public boolean enableGaxRetries;
190-
191-
@Parameter(1)
192187
public int exceptionAtCall;
193188

194-
@Parameter(2)
189+
@Parameter(1)
195190
public ExceptionType exceptionType;
196191

197-
@Parameters(name = "enable GAX retries = {0}, exception at call = {1}, exception type = {2}")
192+
@Parameters(name = "exception at call = {0}, exception type = {1}")
198193
public static Collection<Object[]> data() {
199194
List<Object[]> params = new ArrayList<>();
200-
for (boolean enableRetries : new boolean[] {true, false}) {
201-
for (int exceptionAtCall : new int[] {0, 1}) {
202-
for (ExceptionType exceptionType : ExceptionType.values()) {
203-
params.add(new Object[] {enableRetries, exceptionAtCall, exceptionType});
204-
}
195+
for (int exceptionAtCall : new int[] {0, 1}) {
196+
for (ExceptionType exceptionType : ExceptionType.values()) {
197+
params.add(new Object[] {exceptionAtCall, exceptionType});
205198
}
206199
}
207200
return params;
@@ -275,43 +268,6 @@ public Void apply(Builder<?, ?> input) {
275268
.toBuilder()
276269
.setRetrySettings(retrySettings)
277270
.build());
278-
if (!enableGaxRetries) {
279-
// Disable retries by removing all retryable codes.
280-
builder
281-
.getInstanceAdminStubSettingsBuilder()
282-
.applyToAllUnaryMethods(
283-
new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() {
284-
@Override
285-
public Void apply(Builder<?, ?> input) {
286-
input.setRetryableCodes(ImmutableSet.<StatusCode.Code>of());
287-
return null;
288-
}
289-
});
290-
builder
291-
.getInstanceAdminStubSettingsBuilder()
292-
.createInstanceOperationSettings()
293-
.setInitialCallSettings(
294-
builder
295-
.getInstanceAdminStubSettingsBuilder()
296-
.createInstanceOperationSettings()
297-
.getInitialCallSettings()
298-
.toBuilder()
299-
.setRetrySettings(retrySettings)
300-
.setRetryableCodes(ImmutableSet.<StatusCode.Code>of())
301-
.build());
302-
builder
303-
.getInstanceAdminStubSettingsBuilder()
304-
.updateInstanceOperationSettings()
305-
.setInitialCallSettings(
306-
builder
307-
.getInstanceAdminStubSettingsBuilder()
308-
.updateInstanceOperationSettings()
309-
.getInitialCallSettings()
310-
.toBuilder()
311-
.setRetrySettings(retrySettings)
312-
.setRetryableCodes(ImmutableSet.<StatusCode.Code>of())
313-
.build());
314-
}
315271
spanner = builder.build().getService();
316272
client = spanner.getInstanceAdminClient();
317273
}
@@ -322,12 +278,7 @@ public void tearDown() throws Exception {
322278
}
323279

324280
private Exception setupException() {
325-
if (exceptionType.isRetryable()) {
326-
if (!enableGaxRetries) {
327-
expectedException.expect(
328-
SpannerMatchers.isSpannerException(exceptionType.getExpectedErrorCodeWithoutGax()));
329-
}
330-
} else {
281+
if (!exceptionType.isRetryable()) {
331282
expectedException.expect(
332283
SpannerMatchers.isSpannerException(exceptionType.getExpectedErrorCodeWithGax()));
333284
}

google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerGaxRetryTest.java

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.api.gax.core.NoCredentialsProvider;
2525
import com.google.api.gax.grpc.testing.LocalChannelProvider;
2626
import com.google.api.gax.retrying.RetrySettings;
27-
import com.google.api.gax.rpc.StatusCode;
2827
import com.google.api.gax.rpc.UnaryCallSettings;
2928
import com.google.api.gax.rpc.UnaryCallSettings.Builder;
3029
import com.google.cloud.NoCredentials;
@@ -33,7 +32,6 @@
3332
import com.google.cloud.spanner.TransactionRunner.TransactionCallable;
3433
import com.google.cloud.spanner.v1.SpannerClient;
3534
import com.google.cloud.spanner.v1.SpannerSettings;
36-
import com.google.common.collect.ImmutableSet;
3735
import com.google.protobuf.ListValue;
3836
import com.google.spanner.v1.ResultSetMetadata;
3937
import com.google.spanner.v1.StructType;
@@ -43,26 +41,22 @@
4341
import io.grpc.StatusRuntimeException;
4442
import io.grpc.inprocess.InProcessServerBuilder;
4543
import java.io.IOException;
46-
import java.util.ArrayList;
4744
import java.util.Arrays;
48-
import java.util.Collection;
49-
import java.util.List;
5045
import java.util.concurrent.ScheduledThreadPoolExecutor;
5146
import java.util.concurrent.atomic.AtomicInteger;
5247
import org.junit.After;
5348
import org.junit.AfterClass;
5449
import org.junit.Before;
5550
import org.junit.BeforeClass;
51+
import org.junit.Ignore;
5652
import org.junit.Rule;
5753
import org.junit.Test;
5854
import org.junit.rules.ExpectedException;
5955
import 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;
6357
import org.threeten.bp.Duration;
6458

65-
@RunWith(Parameterized.class)
59+
@RunWith(JUnit4.class)
6660
public 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

Comments
 (0)