Skip to content

Commit 864d32c

Browse files
test: fix clean up of tables with protected views (#2184)
Change-Id: I9a4de8ecdaa3a1d096117853cc27805c7544fe04 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 3ccd8fc commit 864d32c

File tree

1 file changed

+17
-0
lines changed
  • google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env

1 file changed

+17
-0
lines changed

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/TestEnvRule.java

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.cloud.bigtable.admin.v2.models.AppProfile;
2525
import com.google.cloud.bigtable.admin.v2.models.Cluster;
2626
import com.google.cloud.bigtable.admin.v2.models.Instance;
27+
import com.google.cloud.bigtable.admin.v2.models.UpdateAuthorizedViewRequest;
2728
import com.google.common.base.Joiner;
2829
import com.google.common.base.Preconditions;
2930
import com.google.common.base.Strings;
@@ -203,6 +204,7 @@ private void cleanupStaleTables(String stalePrefix) {
203204
continue;
204205
}
205206
if (stalePrefix.compareTo(tableId) > 0) {
207+
prepTableForDelete(tableId);
206208
try {
207209
env().getTableAdminClient().deleteTable(tableId);
208210
} catch (NotFoundException ignored) {
@@ -212,6 +214,21 @@ private void cleanupStaleTables(String stalePrefix) {
212214
}
213215
}
214216

217+
private void prepTableForDelete(String tableId) {
218+
// Unprotected views
219+
if (!(env() instanceof EmulatorEnv)) {
220+
for (String viewId : env().getTableAdminClient().listAuthorizedViews(tableId)) {
221+
try {
222+
env()
223+
.getTableAdminClient()
224+
.updateAuthorizedView(
225+
UpdateAuthorizedViewRequest.of(tableId, viewId).setDeletionProtection(false));
226+
} catch (NotFoundException ignored) {
227+
}
228+
}
229+
}
230+
}
231+
215232
/**
216233
* Clean up AppProfile that were dynamically created in the default instance that have been
217234
* orphaned.

0 commit comments

Comments
 (0)