Skip to content

@ExpectNoConnectionLeak

Jean Bisutti edited this page Nov 10, 2021 Β· 2 revisions

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.

πŸ”Ž Example

    @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();
        }
    }

Annotations

πŸ‘‰  Core

πŸ‘‰  JVM

πŸ‘‰  SQL

πŸ‘‰  Scopes

πŸ‘‰  Create an annotation

Supported frameworks

πŸ‘‰  JUnit 4

πŸ‘‰  JUnit 5

πŸ‘‰  TestNG

πŸ‘‰  Spring

How to

πŸ‘‰  Detect and fix N+1 SELECT

Project examples

πŸ‘‰  Maven performance

πŸ‘‰  Spring Boot - JUnit 4

πŸ‘‰  Spring Boot - JUnit 5

πŸ‘‰  Micronaut Data - JUnit 5

πŸ‘‰  Micronaut - Spring - JUnit 5

πŸ‘‰  Quarkus - JUnit 5

Miscellaneous

πŸ‘‰  FAQ

πŸ‘‰  QuickPerf code

Clone this wiki locally