Skip to content

Commit 5a0f92f

Browse files
authored
issue_503: Closed test connection after use (#504)
* test connection closed after use in BloomFilterTableTest class * Removed unnecessary setEnv() method and h2 test database clearing * Removed unnecessary assertion
1 parent a1a3040 commit 5a0f92f

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

src/test/java/com/teragrep/pth10/steps/teragrep/bloomfilter/BloomFilterTableTest.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.junit.jupiter.api.*;
5252

5353
import java.sql.Connection;
54+
import java.sql.DriverManager;
5455
import java.sql.ResultSet;
5556
import java.util.ArrayList;
5657
import java.util.List;
@@ -59,29 +60,15 @@
5960
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
6061
public class BloomFilterTableTest {
6162

62-
final String username = "sa";
63-
final String password = "";
64-
final String connectionUrl = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE";
65-
66-
@BeforeAll
67-
void setEnv() {
68-
Config config = ConfigFactory.parseProperties(getDefaultProperties());
69-
Connection connection = new LazyConnection(config).get();
70-
Assertions.assertDoesNotThrow(() -> {
71-
connection.prepareStatement("DROP ALL OBJECTS").execute(); // h2 clear database
72-
});
73-
Assertions.assertDoesNotThrow(() -> {
74-
Class.forName("org.h2.Driver");
75-
});
76-
}
63+
private final String username = "sa";
64+
private final String password = "";
65+
private final String connectionUrl = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE";
66+
private final Connection connection = Assertions
67+
.assertDoesNotThrow(() -> DriverManager.getConnection(connectionUrl, username, password));
7768

7869
@AfterAll
7970
void tearDown() {
80-
Assertions.assertDoesNotThrow(() -> {
81-
Config config = ConfigFactory.parseProperties(getDefaultProperties());
82-
Connection connection = new LazyConnection(config).get();
83-
connection.prepareStatement("DROP ALL OBJECTS").execute(); // h2 clear database
84-
});
71+
Assertions.assertDoesNotThrow(connection::close);
8572
}
8673

8774
@Test
@@ -121,7 +108,7 @@ void testCreateToDatabase() {
121108
table.create();
122109
String sql = "SHOW COLUMNS FROM " + tableName + ";";
123110
Assertions.assertDoesNotThrow(() -> {
124-
ResultSet rs = new LazyConnection(config).get().prepareStatement(sql).executeQuery();
111+
ResultSet rs = connection.prepareStatement(sql).executeQuery();
125112
int cols = 0;
126113
List<String> columnList = new ArrayList<>(4);
127114
while (rs.next()) {

0 commit comments

Comments
 (0)