@ExpectNoConnectionLeak - quick-perf/doc GitHub Wiki

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.

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