Skip to content

Commit 3f592a5

Browse files
authored
test: Clean up resources created in ITs (#4024)
* chore: Cleanup initialized resources * chore: Delete created dataset * chore: Use try-with to close stream
1 parent f4a1536 commit 3f592a5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,12 @@ public static void beforeClass() throws InterruptedException, IOException {
10991099
.setContentType("application/json")
11001100
.build(),
11011101
JSON_CONTENT_SIMPLE.getBytes(StandardCharsets.UTF_8));
1102-
InputStream stream =
1103-
ITBigQueryTest.class.getClassLoader().getResourceAsStream("QueryTestData.csv");
1104-
storage.createFrom(
1105-
BlobInfo.newBuilder(BUCKET, LOAD_FILE_LARGE).setContentType("text/plain").build(), stream);
1102+
try (InputStream stream =
1103+
ITBigQueryTest.class.getClassLoader().getResourceAsStream("QueryTestData.csv")) {
1104+
storage.createFrom(
1105+
BlobInfo.newBuilder(BUCKET, LOAD_FILE_LARGE).setContentType("text/plain").build(),
1106+
stream);
1107+
}
11061108
storage.create(
11071109
BlobInfo.newBuilder(BUCKET, JSON_LOAD_FILE_BQ_RESULTSET)
11081110
.setContentType("application/json")
@@ -1179,10 +1181,11 @@ public static void beforeClass() throws InterruptedException, IOException {
11791181
}
11801182

11811183
@AfterClass
1182-
public static void afterClass() throws ExecutionException, InterruptedException {
1184+
public static void afterClass() throws Exception {
11831185
if (bigquery != null) {
11841186
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);
11851187
RemoteBigQueryHelper.forceDelete(bigquery, UK_DATASET);
1188+
RemoteBigQueryHelper.forceDelete(bigquery, OTHER_DATASET);
11861189
RemoteBigQueryHelper.forceDelete(bigquery, MODEL_DATASET);
11871190
RemoteBigQueryHelper.forceDelete(bigquery, ROUTINE_DATASET);
11881191
}
@@ -1191,6 +1194,11 @@ public static void afterClass() throws ExecutionException, InterruptedException
11911194
if (!wasDeleted && LOG.isLoggable(Level.WARNING)) {
11921195
LOG.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
11931196
}
1197+
storage.close();
1198+
}
1199+
1200+
if (otel instanceof OpenTelemetrySdk) {
1201+
((OpenTelemetrySdk) otel).close();
11941202
}
11951203
}
11961204

0 commit comments

Comments
 (0)