Skip to content

Commit 68a6729

Browse files
committed
Destroy connection @AfterEach Test
1 parent 6c6415f commit 68a6729

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/src/test/java/org/vss/impl/postgres/PostgresBackendImplIntegrationTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.jooq.DSLContext;
66
import org.jooq.SQLDialect;
77
import org.jooq.impl.DSL;
8+
import org.junit.jupiter.api.AfterEach;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.testcontainers.containers.PostgreSQLContainer;
1011
import org.testcontainers.junit.jupiter.Container;
@@ -23,20 +24,27 @@ public class PostgresBackendImplIntegrationTest extends AbstractKVStoreIntegrati
2324
.withUsername("postgres")
2425
.withPassword("postgres");
2526

27+
private Connection connection;
28+
2629
@BeforeEach
27-
public void initEach() throws Exception {
30+
void initEach() throws Exception {
2831

2932
// This is required to get postgres driver in classpath before we attempt to fetch a connection
3033
Class.forName("org.postgresql.Driver");
31-
Connection conn = DriverManager.getConnection(postgreSQLContainer.getJdbcUrl(),
34+
this.connection = DriverManager.getConnection(postgreSQLContainer.getJdbcUrl(),
3235
postgreSQLContainer.getUsername(), postgreSQLContainer.getPassword());
33-
DSLContext dslContext = DSL.using(conn, SQLDialect.POSTGRES);
36+
DSLContext dslContext = DSL.using(connection, SQLDialect.POSTGRES);
3437

3538
this.kvStore = new PostgresBackendImpl(dslContext);
3639

3740
createTable(dslContext);
3841
}
3942

43+
@AfterEach
44+
void destroy() throws Exception {
45+
this.connection.close();
46+
}
47+
4048
private void createTable(DSLContext dslContext) {
4149
dslContext.execute("CREATE TABLE vss_db ("
4250
+ "store_id character varying(120) NOT NULL CHECK (store_id <> ''),"

0 commit comments

Comments
 (0)