Skip to content

Commit c9f5048

Browse files
authored
fix: drop databases after sample tests (#1401)
There was a bug on dropping databases / deleting backups after the sample tests where we were trying to delete in the regional instance first and if an exception was thrown, we would try to delete on the second instance. This did not work, because the delete / drop operations do not fail if the database / backup are not found in the instance, the call simply returns. In this PR we have applied both deletes one after the other to fix the issue, instead of relying on the exceptions.
1 parent 2e22bb4 commit c9f5048

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

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

+13-17
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,26 @@ public static void beforeClass() {
6161
@AfterClass
6262
public static void afterClass() {
6363
for (String databaseId : idGenerator.getDatabaseIds()) {
64+
System.out.println("Trying to drop " + databaseId);
6465
try {
66+
// If the database is not found, it is ignored (no exception is thrown)
6567
databaseAdminClient.dropDatabase(instanceId, databaseId);
66-
} catch (Exception e1) {
67-
try {
68-
databaseAdminClient.dropDatabase(multiRegionalInstanceId, databaseId);
69-
} catch (Exception e2) {
70-
System.out.println(
71-
"Failed to drop database " + databaseId + " due to " + e2.getMessage()
72-
+ ", skipping..."
73-
);
74-
}
68+
databaseAdminClient.dropDatabase(multiRegionalInstanceId, databaseId);
69+
} catch (Exception e) {
70+
System.out.println(
71+
"Failed to drop database " + databaseId + " due to " + e.getMessage() + ", skipping..."
72+
);
7573
}
7674
}
7775
for (String backupId : idGenerator.getBackupIds()) {
7876
try {
77+
// If the backup is not found, it is ignored (no exception is thrown)
7978
databaseAdminClient.deleteBackup(instanceId, backupId);
80-
} catch (Exception e1) {
81-
try {
82-
databaseAdminClient.deleteBackup(multiRegionalInstanceId, backupId);
83-
} catch (Exception e2) {
84-
System.out.println(
85-
"Failed to delete backup " + backupId + " due to " + e2.getMessage() + ", skipping..."
86-
);
87-
}
79+
databaseAdminClient.deleteBackup(multiRegionalInstanceId, backupId);
80+
} catch (Exception e) {
81+
System.out.println(
82+
"Failed to delete backup " + backupId + " due to " + e.getMessage() + ", skipping..."
83+
);
8884
}
8985
}
9086
spanner.close();

0 commit comments

Comments
 (0)