-
Notifications
You must be signed in to change notification settings - Fork 4
@ExpectNoConnectionLeak
ExpectNoConnectionLeak annotation allows detecting database connection leaks.
The test method will fail if the tested code gets a connection from javax.sql.DataSource but does not close it.
We recommend attributing a global scope to this annotation. You can look at the other suggested SQL global scope annotations here.
See also @ProfileConnection.
@ExpectNoConnectionLeak
@Test
public void code_with_connection_leak() throws SQLException {
Connection connection = getConnection();
try (PreparedStatement statement = connection.prepareStatement("select isbn from Book");) {
statement.executeQuery();
}
}
The test fails will the following message on the console: [PERF] Database connection leak
.
The test does not fail with this code:
@ExpectNoConnectionLeak
@Test
public void code_without_connection_leak() throws SQLException {
try (Connection connection = getConnection();
PreparedStatement statement = connection.prepareStatement("select isbn from Book");) {
statement.executeQuery();
}
}
π Core
π JVM
π SQL
π Scopes
π Create an annotation
π JUnit 4
π JUnit 5
π TestNG
π Spring
π Detect and fix N+1 SELECT
π Maven performance
π Spring Boot - JUnit 4
π Spring Boot - JUnit 5
π Micronaut Data - JUnit 5
π Micronaut - Spring - JUnit 5
π Quarkus - JUnit 5
π FAQ
π QuickPerf code