-
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