From d0e762b03be7e4c6795891730727f23383146b43 Mon Sep 17 00:00:00 2001 From: Sakthivel Subramanian Date: Tue, 17 Dec 2024 01:19:27 +0530 Subject: [PATCH] Fix delete backup issue in autogenerated admin client --- .../test/java/com/example/spanner/SpannerSampleIT.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java b/samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java index d59152b407..e2eaa22f47 100644 --- a/samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java +++ b/samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertTrue; +import com.google.api.gax.rpc.FailedPreconditionException; import com.google.cloud.Timestamp; import com.google.cloud.spanner.DatabaseId; import com.google.cloud.spanner.ErrorCode; @@ -643,8 +644,13 @@ private static void deleteAllBackups(String instanceId) throws InterruptedExcept attempts++; databaseAdminClient.deleteBackup(backup.getName()); break; - } catch (SpannerException e) { - if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION + } catch (SpannerException | FailedPreconditionException e) { + ErrorCode errorCode = ErrorCode.FAILED_PRECONDITION; + + if(e instanceof SpannerException) { + errorCode = ((SpannerException) e).getErrorCode(); + } + if (errorCode == ErrorCode.FAILED_PRECONDITION && e.getMessage() .contains( "Please try deleting the backup once the restore or post-restore optimize "