Skip to content

Commit 5109f13

Browse files
committed
chore: address review comments
1 parent 2e76e62 commit 5109f13

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerErrorInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
7272
public void onClose(Status status, Metadata trailers) {
7373
try {
7474
// Translate INTERNAL errors that should be retried to a retryable error code.
75-
if (status.getCode() == Code.INTERNAL
76-
&& IsRetryableInternalError.INSTANCE.isRetryableInternalError(status)) {
75+
if (IsRetryableInternalError.INSTANCE.isRetryableInternalError(status)) {
7776
status =
7877
Status.fromCode(Code.UNAVAILABLE).withDescription(status.getDescription());
7978
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,34 @@ public void testTranslateInternalException() {
5656
Status.INTERNAL
5757
.withDescription("Authentication backend internal server error. Please retry.")
5858
.asRuntimeException()));
59-
mockSpanner.setExecuteSqlExecutionTime(
60-
SimulatedExecutionTime.ofException(
61-
Status.INTERNAL
62-
.withDescription("Authentication backend internal server error. Please retry.")
63-
.asRuntimeException()));
6459

60+
// Execute a query. This will block until a BatchCreateSessions call has finished and then
61+
// invoke ExecuteStreamingSql. Both of these RPCs should be retried.
6562
try (ResultSet resultSet = client.singleUse().executeQuery(SELECT1_STATEMENT)) {
6663
assertTrue(resultSet.next());
6764
assertFalse(resultSet.next());
6865
}
66+
// Verify that both the BatchCreateSessions call and the ExecuteStreamingSql call were
67+
// retried.
68+
assertEquals(2, mockSpanner.countRequestsOfType(BatchCreateSessionsRequest.class));
69+
assertEquals(2, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
70+
// Clear the requests before the next test.
71+
mockSpanner.clearRequests();
72+
73+
// Execute a DML statement. This uses the ExecuteSql RPC.
74+
assertEquals(0, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
75+
mockSpanner.setExecuteSqlExecutionTime(
76+
SimulatedExecutionTime.ofException(
77+
Status.INTERNAL
78+
.withDescription("Authentication backend internal server error. Please retry.")
79+
.asRuntimeException()));
6980
assertEquals(
7081
Long.valueOf(1L),
7182
client
7283
.readWriteTransaction()
7384
.run(transaction -> transaction.executeUpdate(INSERT_STATEMENT)));
74-
75-
// Verify that all the RPCs were retried.
76-
assertEquals(2, mockSpanner.countRequestsOfType(BatchCreateSessionsRequest.class));
77-
assertEquals(4, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
85+
// Verify that also this request was retried.
86+
assertEquals(2, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
7887
}
7988
}
8089
}

0 commit comments

Comments
 (0)