Skip to content

Commit 90b72e0

Browse files
authored
test: clean up instance in test (#2849)
* test: clean up instance in test Change-Id: Ib3a73e2cc24f7e27fd346eb80b7ec5175e3c11a4 * format Change-Id: I41393dc1a87fffa0e8ec72d791a80f6e1434ab65
1 parent d79abf5 commit 90b72e0

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class BigtableBackupIT {
8080
private static String targetClusterHot;
8181
private static Table testTable;
8282
private static Table testTableHot;
83+
private static Instance testInstance;
8384

8485
@BeforeClass
8586
public static void setUpClass() throws InterruptedException, IOException {
@@ -98,9 +99,12 @@ public static void setUpClass() throws InterruptedException, IOException {
9899
String newInstanceId = PrefixGenerator.newPrefix("backupIT");
99100
targetClusterHot = newInstanceId + "-c1";
100101

101-
instanceAdmin.createInstance(
102-
CreateInstanceRequest.of(newInstanceId)
103-
.addCluster(targetClusterHot, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD));
102+
testInstance =
103+
instanceAdmin.createInstance(
104+
CreateInstanceRequest.of(newInstanceId)
105+
.setDisplayName("BigtableBackupIT")
106+
.addCluster(
107+
targetClusterHot, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD));
104108

105109
tableAdminHot =
106110
BigtableTableAdminClient.create(
@@ -122,6 +126,13 @@ public static void tearDownClass() {
122126
// Ignore.
123127
}
124128
}
129+
if (testInstance != null) {
130+
try {
131+
instanceAdmin.deleteInstance(testInstance.getId());
132+
} catch (Exception e) {
133+
LOGGER.log(Level.WARNING, "Failed to clean up instance ", e);
134+
}
135+
}
125136
}
126137

127138
private static void deleteBackupIgnoreErrors(

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static void validatePlatform() throws IOException {
115115
LOGGER.info("Creating cluster in zone: " + zones.get(0));
116116
instanceAdmin.createInstance(
117117
CreateInstanceRequest.of(instanceId)
118+
.setDisplayName("BigtableCmekIT")
118119
.addCmekCluster(clusterId1, zones.get(0), 1, StorageType.SSD, kmsKeyName));
119120
// Create a table. Key is inherited from the cluster configuration
120121
tableAdmin.createTable(CreateTableRequest.of(TEST_TABLE_ID).addFamily("cf"));

0 commit comments

Comments
 (0)