Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed test connection resource after use #502

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
import com.typesafe.config.ConfigFactory;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.spark.util.sketch.BloomFilter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -65,15 +67,14 @@

class FilterTypesTest {

Connection conn;
final String username = "sa";
final String password = "";
final String connectionUrl = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE";
private final String username = "sa";
private final String password = "";
private final String connectionUrl = "jdbc:h2:mem:test;MODE=MariaDB;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE";
private final Connection conn = Assertions
.assertDoesNotThrow(() -> DriverManager.getConnection(connectionUrl, username, password));

@BeforeEach
public void setup() {
Config config = ConfigFactory.parseProperties(defaultProperties());
this.conn = new LazyConnection(config).get();
Assertions.assertDoesNotThrow(() -> {
conn.prepareStatement("DROP ALL OBJECTS").execute(); // h2 clear database
});
Expand All @@ -90,6 +91,11 @@ public void setup() {

}

@AfterEach
public void teardown() {
Assertions.assertDoesNotThrow(conn::close);
}

@Test
public void testSortedMapMethod() {
Config config = ConfigFactory.parseProperties(defaultProperties());
Expand Down Expand Up @@ -136,12 +142,12 @@ public void testWriteFilterTypesToDatabase() {
Assertions.assertEquals(3, fppList.size());
Assertions.assertEquals(Arrays.asList(1000L, 2000L, 3000L), expectedSizeList);
Assertions.assertEquals(Arrays.asList(0.01, 0.02, 0.03), fppList);
Assertions.assertDoesNotThrow(result::close);
});
}

@Test
public void testEquals() {
;
Config config = ConfigFactory.parseProperties(defaultProperties());
FilterTypes filterTypes1 = new FilterTypes(config);
FilterTypes filterTypes2 = new FilterTypes(config);
Expand Down