Skip to content

Commit a2b500e

Browse files
test: clean up warnings about unclosed connections in test (#4199)
Change-Id: Ie68df6368d6daaff7f8c81d6f6f2f7dd04d5ea13 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable-hbase/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 9c3cff8 commit a2b500e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestBigtableConnection.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.hadoop.hbase.TableName;
4141
import org.apache.hadoop.hbase.client.Connection;
4242
import org.apache.hadoop.hbase.util.Bytes;
43+
import org.junit.After;
4344
import org.junit.AfterClass;
4445
import org.junit.Before;
4546
import org.junit.BeforeClass;
@@ -86,13 +87,20 @@ public void setUp() throws IOException {
8687
connection = new BigtableConnection(configuration);
8788
}
8889

90+
@After
91+
public void tearDown() throws Exception {
92+
if (connection != null) {
93+
connection.close();
94+
}
95+
}
96+
8997
@Test
9098
public void testOverloadedConstructor() throws IOException {
91-
Connection hbaseConnection =
92-
new BigtableConnection(configuration, false, Executors.newSingleThreadExecutor(), null);
93-
94-
assertTrue(hbaseConnection.getAdmin() instanceof BigtableAdmin);
95-
assertTrue(hbaseConnection.getTable(TABLE_NAME) instanceof AbstractBigtableTable);
99+
try (Connection hbaseConnection =
100+
new BigtableConnection(configuration, false, Executors.newSingleThreadExecutor(), null)) {
101+
assertTrue(hbaseConnection.getAdmin() instanceof BigtableAdmin);
102+
assertTrue(hbaseConnection.getTable(TABLE_NAME) instanceof AbstractBigtableTable);
103+
}
96104
}
97105

98106
@Test

0 commit comments

Comments
 (0)