Skip to content

Commit 98331e9

Browse files
committed
fix: register errors before creating the client
1 parent 8b14750 commit 98331e9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryableInternalErrorTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
public class RetryableInternalErrorTest extends AbstractMockServerTest {
3737
@Test
3838
public void testTranslateInternalException() {
39+
mockSpanner.setBatchCreateSessionsExecutionTime(
40+
SimulatedExecutionTime.ofException(
41+
Status.INTERNAL
42+
.withDescription("Authentication backend internal server error. Please retry.")
43+
.asRuntimeException()));
44+
mockSpanner.setExecuteStreamingSqlExecutionTime(
45+
SimulatedExecutionTime.ofException(
46+
Status.INTERNAL
47+
.withDescription("Authentication backend internal server error. Please retry.")
48+
.asRuntimeException()));
49+
3950
try (Spanner spanner =
4051
SpannerOptions.newBuilder()
4152
.setProjectId("my-project")
@@ -46,22 +57,12 @@ public void testTranslateInternalException() {
4657
SessionPoolOptions.newBuilder()
4758
.setMinSessions(1)
4859
.setMaxSessions(1)
49-
.setWaitForMinSessions(Duration.ofSeconds(1))
60+
.setWaitForMinSessions(Duration.ofSeconds(5))
5061
.build())
5162
.build()
5263
.getService()) {
53-
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
54-
mockSpanner.setBatchCreateSessionsExecutionTime(
55-
SimulatedExecutionTime.ofException(
56-
Status.INTERNAL
57-
.withDescription("Authentication backend internal server error. Please retry.")
58-
.asRuntimeException()));
59-
mockSpanner.setExecuteStreamingSqlExecutionTime(
60-
SimulatedExecutionTime.ofException(
61-
Status.INTERNAL
62-
.withDescription("Authentication backend internal server error. Please retry.")
63-
.asRuntimeException()));
6464

65+
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
6566
// Execute a query. This will block until a BatchCreateSessions call has finished and then
6667
// invoke ExecuteStreamingSql. Both of these RPCs should be retried.
6768
try (ResultSet resultSet = client.singleUse().executeQuery(SELECT1_STATEMENT)) {

0 commit comments

Comments
 (0)