Skip to content

Commit 3268649

Browse files
authored
Merge pull request #203 from Montana/patch-2
`Statement` and `ResultSet` were never closed.closed statements. If more tests or queries run in the same JVM, these unclosed resources can pile up and cause connection pool exhaustion or memory leaks.
2 parents f5e0540 + 9209cbc commit 3268649

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/test/java/com/opentable/db/postgres/embedded/LiquibasePreparerContextTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@
2626
import static org.junit.Assert.assertEquals;
2727

2828
public class LiquibasePreparerContextTest {
29-
@Rule
30-
public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(LiquibasePreparer.forClasspathLocation("liqui/master-test.xml", new Contexts("test")));
29+
@Rule
30+
public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(
31+
LiquibasePreparer.forClasspathLocation("liqui/master-test.xml", new Contexts("test"))
32+
);
3133

32-
@Test
33-
public void testEmptyTables() throws Exception {
34-
try (Connection c = db.getTestDatabase().getConnection();
35-
Statement s = c.createStatement()) {
36-
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM foo");
37-
rs.next();
38-
assertEquals(0, rs.getInt(1));
39-
}
34+
@Test
35+
public void testEmptyTables() throws Exception {
36+
try (Connection c = db.getTestDatabase().getConnection();
37+
Statement s = c.createStatement();
38+
ResultSet rs = s.executeQuery("SELECT COUNT(*) AS cnt FROM foo")) {
39+
40+
rs.next();
41+
long count = rs.getLong("cnt");
42+
assertEquals(0L, count);
4043
}
44+
}
4145
}

0 commit comments

Comments
 (0)