Skip to content

Confusing error messages when JDBC driver not found #230

@ldcasillas-progreso

Description

@ldcasillas-progreso

Just ran into a very confusing situation where I would have saved a good amount of time if the database container classes produced better diagnostic messages. Only about a third of the following concerns the library, but I'll briefly give all the context:

  1. I added a runtime dependency to the PostgreSQL JDBC drivers to my project's build.gradle;
  2. I forgot to click on the IntelliJ button to refresh the configuration, so IntelliJ did not place the driver into my classpath;
  3. My unit test using the PostgreSQLContainer class failed with an error saying that it timed out waiting for the database port to become available.

The problem, as I understood it, is in this line of code (though maybe elsewhere as well):

return Unreliables.retryUntilSuccess(60, TimeUnit.SECONDS, () -> getJdbcDriverInstance().connect(url, info));

If this fails with a ClassNotFoundException it will continue retrying the connection and when the timer runs out falsely report that we timed out attempting to connect. The problem is that only some exceptions in connection attempts (e.g., IOException or perhaps SQLException) should lead to a retry—others (like ClassNotFoundException) should lead to an immediate abort and report of the exception that caused the failure.

It might be rather tricky to figure out which exceptions fall into which category, however, given how so much of this might vary between different vendors' JDBC drivers.

(Version of testcontainers: 1.1.6.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions