Skip to content

Commit b32f761

Browse files
test: Close resources after tests run (#3139)
* test: Close resources after tests run * chore: generate libraries at Thu Dec 11 21:24:33 UTC 2025 * chore: Fix failing IT test case --------- Co-authored-by: cloud-java-bot <[email protected]>
1 parent e391dbd commit b32f761

11 files changed

+42
-7
lines changed

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/BigQueryReadClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.UUID;
4444
import java.util.concurrent.ExecutionException;
45+
import java.util.concurrent.TimeUnit;
4546
import org.junit.After;
4647
import org.junit.AfterClass;
4748
import org.junit.Assert;
@@ -98,6 +99,7 @@ public void onRetryAttempt(Status prevStatus, Metadata prevMetadata) {
9899
@After
99100
public void tearDown() throws Exception {
100101
client.close();
102+
client.awaitTermination(10, TimeUnit.SECONDS);
101103
}
102104

103105
@Test

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.List;
4848
import java.util.UUID;
4949
import java.util.concurrent.ExecutionException;
50+
import java.util.concurrent.TimeUnit;
5051
import java.util.logging.Logger;
5152
import org.apache.arrow.memory.RootAllocator;
5253
import org.apache.arrow.vector.VarCharVector;
@@ -60,6 +61,7 @@
6061
import org.apache.arrow.vector.types.pojo.Field;
6162
import org.apache.arrow.vector.types.pojo.FieldType;
6263
import org.apache.arrow.vector.types.pojo.Schema;
64+
import org.junit.After;
6365
import org.junit.Before;
6466
import org.junit.Test;
6567
import org.junit.runner.RunWith;
@@ -103,6 +105,14 @@ public void setUp() throws Exception {
103105
.build());
104106
}
105107

108+
@After
109+
public void cleanUp() throws InterruptedException {
110+
serviceHelper.stop();
111+
112+
client.close();
113+
client.awaitTermination(10, TimeUnit.SECONDS);
114+
}
115+
106116
@Test
107117
public void testMultiplexedAppendSuccess_NonNullTraceId() throws Exception {
108118
testMultiplexedIngestion(

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.Map;
5959
import java.util.UUID;
6060
import java.util.concurrent.ExecutionException;
61+
import java.util.concurrent.TimeUnit;
6162
import org.json.JSONArray;
6263
import org.json.JSONObject;
6364
import org.junit.After;
@@ -158,6 +159,9 @@ public void setUp() throws Exception {
158159
@After
159160
public void tearDown() throws Exception {
160161
serviceHelper.stop();
162+
163+
client.close();
164+
client.awaitTermination(10, TimeUnit.SECONDS);
161165
}
162166

163167
private JsonStreamWriter.Builder getTestJsonStreamWriterBuilder(

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ public void setUp() throws Exception {
189189
@After
190190
public void tearDown() throws Exception {
191191
log.info("tearDown called");
192-
client.close();
193192
serviceHelper.stop();
194193
StreamWriter.cleanUp();
194+
195+
client.close();
196+
client.awaitTermination(10, TimeUnit.SECONDS);
195197
}
196198

197199
private StreamWriter getMultiplexingTestStreamWriter() throws IOException {
@@ -1996,6 +1998,9 @@ public void testBuilderExplicitSetting() throws Exception {
19961998
((GoogleCredentialsProvider) writerSettings2.getCredentialsProvider())
19971999
.getScopesToApply()
19982000
.size());
2001+
2002+
client.close();
2003+
client.awaitTermination(10, TimeUnit.SECONDS);
19992004
}
20002005

20012006
@Test

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryBigDecimalByteStringEncoderTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.math.BigDecimal;
4545
import java.util.Iterator;
4646
import java.util.concurrent.ExecutionException;
47+
import java.util.concurrent.TimeUnit;
4748
import java.util.logging.Logger;
4849
import org.json.JSONArray;
4950
import org.json.JSONObject;
@@ -91,9 +92,10 @@ public static void beforeClass() throws IOException {
9192
}
9293

9394
@AfterClass
94-
public static void afterClass() {
95+
public static void afterClass() throws InterruptedException {
9596
if (client != null) {
9697
client.close();
98+
client.awaitTermination(10, TimeUnit.SECONDS);
9799
}
98100
if (bigquery != null) {
99101
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageLongRunningTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.ExecutorService;
3535
import java.util.concurrent.Executors;
3636
import java.util.concurrent.Future;
37+
import java.util.concurrent.TimeUnit;
3738
import java.util.logging.Logger;
3839
import org.junit.AfterClass;
3940
import org.junit.Assume;
@@ -74,9 +75,10 @@ public static void beforeClass() throws IOException {
7475
}
7576

7677
@AfterClass
77-
public static void afterClass() {
78+
public static void afterClass() throws InterruptedException {
7879
if (client != null) {
7980
client.close();
81+
client.awaitTermination(10, TimeUnit.SECONDS);
8082
}
8183
}
8284

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import java.util.Iterator;
105105
import java.util.List;
106106
import java.util.Map;
107+
import java.util.concurrent.TimeUnit;
107108
import java.util.logging.Logger;
108109
import org.apache.avro.Conversions;
109110
import org.apache.avro.LogicalTypes;
@@ -516,9 +517,10 @@ public static void beforeClass() throws IOException {
516517
}
517518

518519
@AfterClass
519-
public static void afterClass() {
520+
public static void afterClass() throws InterruptedException {
520521
if (client != null) {
521522
client.close();
523+
client.awaitTermination(10, TimeUnit.SECONDS);
522524
}
523525

524526
if (bigquery != null) {
@@ -1436,7 +1438,8 @@ public void testStructAndArraySqlTypes() throws InterruptedException, IOExceptio
14361438
}
14371439

14381440
@Test
1439-
public void testSimpleReadWithBackgroundExecutorProvider() throws IOException {
1441+
public void testSimpleReadWithBackgroundExecutorProvider()
1442+
throws IOException, InterruptedException {
14401443
BigQueryReadSettings bigQueryReadSettings =
14411444
BigQueryReadSettings.newBuilder()
14421445
.setBackgroundExecutorProvider(

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryTimeEncoderTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.time.LocalTime;
4545
import java.util.Iterator;
4646
import java.util.concurrent.ExecutionException;
47+
import java.util.concurrent.TimeUnit;
4748
import org.json.JSONArray;
4849
import org.json.JSONObject;
4950
import org.junit.AfterClass;
@@ -98,9 +99,10 @@ public static void beforeClass() throws IOException {
9899
}
99100

100101
@AfterClass
101-
public static void afterClass() {
102+
public static void afterClass() throws InterruptedException {
102103
if (client != null) {
103104
client.close();
105+
client.awaitTermination(10, TimeUnit.SECONDS);
104106
}
105107
if (bigquery != null) {
106108
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ public static void beforeClass() throws IOException {
216216
}
217217

218218
@AfterClass
219-
public static void afterClass() {
219+
public static void afterClass() throws InterruptedException {
220220
if (client != null) {
221221
client.close();
222+
client.awaitTermination(10, TimeUnit.SECONDS);
222223
}
223224

224225
if (bigquery != null) {

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/stub/ResourceHeaderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.cloud.bigquery.storage.v1.ReadRowsRequest;
2929
import com.google.cloud.bigquery.storage.v1.ReadSession;
3030
import com.google.cloud.bigquery.storage.v1.SplitReadStreamRequest;
31+
import java.util.concurrent.TimeUnit;
3132
import java.util.regex.Pattern;
3233
import org.junit.After;
3334
import org.junit.AfterClass;
@@ -88,6 +89,7 @@ public void setUp() throws Exception {
8889
@After
8990
public void tearDown() throws Exception {
9091
client.close();
92+
client.awaitTermination(10, TimeUnit.SECONDS);
9193
}
9294

9395
@AfterClass

0 commit comments

Comments
 (0)