Skip to content

Commit 2fa3929

Browse files
Fix delete backup issue in autogenerated admin client
1 parent 9faac07 commit 2fa3929

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.junit.Assert.assertTrue;
2121

22+
import com.google.api.gax.rpc.FailedPreconditionException;
2223
import com.google.cloud.Timestamp;
2324
import com.google.cloud.spanner.DatabaseId;
2425
import com.google.cloud.spanner.ErrorCode;
@@ -643,8 +644,13 @@ private static void deleteAllBackups(String instanceId) throws InterruptedExcept
643644
attempts++;
644645
databaseAdminClient.deleteBackup(backup.getName());
645646
break;
646-
} catch (SpannerException e) {
647-
if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION
647+
} catch (SpannerException | FailedPreconditionException e) {
648+
ErrorCode errorCode = ErrorCode.FAILED_PRECONDITION;
649+
650+
if (e instanceof SpannerException) {
651+
errorCode = ((SpannerException) e).getErrorCode();
652+
}
653+
if (errorCode == ErrorCode.FAILED_PRECONDITION
648654
&& e.getMessage()
649655
.contains(
650656
"Please try deleting the backup once the restore or post-restore optimize "

0 commit comments

Comments
 (0)