Skip to content

Commit 37ab932

Browse files
committed
test: Close resources after tests run
1 parent ea1bcc5 commit 37ab932

13 files changed

+53
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.List;
3636
import java.util.UUID;
3737
import java.util.concurrent.ExecutionException;
38+
import java.util.concurrent.TimeUnit;
3839
import javax.annotation.Generated;
3940
import org.junit.After;
4041
import org.junit.AfterClass;
@@ -79,6 +80,7 @@ public void setUp() throws IOException {
7980
@After
8081
public void tearDown() throws Exception {
8182
client.close();
83+
client.awaitTermination(10, TimeUnit.SECONDS);
8284
}
8385

8486
@Test

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import java.util.List;
4343
import java.util.UUID;
4444
import java.util.concurrent.ExecutionException;
45+
import java.util.concurrent.TimeUnit;
46+
4547
import org.junit.After;
4648
import org.junit.AfterClass;
4749
import org.junit.Assert;
@@ -98,6 +100,7 @@ public void onRetryAttempt(Status prevStatus, Metadata prevMetadata) {
98100
@After
99101
public void tearDown() throws Exception {
100102
client.close();
103+
client.awaitTermination(10, TimeUnit.SECONDS);
101104
}
102105

103106
@Test

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.List;
3939
import java.util.UUID;
4040
import java.util.concurrent.ExecutionException;
41+
import java.util.concurrent.TimeUnit;
4142
import javax.annotation.Generated;
4243
import org.junit.After;
4344
import org.junit.AfterClass;
@@ -82,6 +83,7 @@ public void setUp() throws IOException {
8283
@After
8384
public void tearDown() throws Exception {
8485
client.close();
86+
client.awaitTermination(10, TimeUnit.SECONDS);
8587
}
8688

8789
@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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import java.util.Map;
5959
import java.util.UUID;
6060
import java.util.concurrent.ExecutionException;
61+
import java.util.concurrent.TimeUnit;
62+
6163
import org.json.JSONArray;
6264
import org.json.JSONObject;
6365
import org.junit.After;
@@ -158,6 +160,9 @@ public void setUp() throws Exception {
158160
@After
159161
public void tearDown() throws Exception {
160162
serviceHelper.stop();
163+
164+
client.close();
165+
client.awaitTermination(10, TimeUnit.SECONDS);
161166
}
162167

163168
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: 7 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,7 @@ public void testStructAndArraySqlTypes() throws InterruptedException, IOExceptio
14361438
}
14371439

14381440
@Test
1439-
public void testSimpleReadWithBackgroundExecutorProvider() throws IOException {
1441+
public void testSimpleReadWithBackgroundExecutorProvider() throws IOException, InterruptedException {
14401442
BigQueryReadSettings bigQueryReadSettings =
14411443
BigQueryReadSettings.newBuilder()
14421444
.setBackgroundExecutorProvider(
@@ -1484,6 +1486,9 @@ public void testSimpleReadWithBackgroundExecutorProvider() throws IOException {
14841486
}
14851487

14861488
assertEquals(164_656, rowCount);
1489+
1490+
client.close();
1491+
client.awaitTermination(10, TimeUnit.SECONDS);
14871492
}
14881493

14891494
@Test

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import java.time.LocalTime;
4545
import java.util.Iterator;
4646
import java.util.concurrent.ExecutionException;
47+
import java.util.concurrent.TimeUnit;
48+
4749
import org.json.JSONArray;
4850
import org.json.JSONObject;
4951
import org.junit.AfterClass;
@@ -98,9 +100,10 @@ public static void beforeClass() throws IOException {
98100
}
99101

100102
@AfterClass
101-
public static void afterClass() {
103+
public static void afterClass() throws InterruptedException {
102104
if (client != null) {
103105
client.close();
106+
client.awaitTermination(10, TimeUnit.SECONDS);
104107
}
105108
if (bigquery != null) {
106109
RemoteBigQueryHelper.forceDelete(bigquery, DATASET);

0 commit comments

Comments
 (0)