Skip to content

Confusing error messages when JDBC driver not found #230

Closed

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.)

Activity

  1. rnorth commented on Nov 20, 2016

    @rnorth
    Member

    @ldcasillas-progreso sorry you encountered a problem here, and thanks for raising it. You're right - the behaviour should be more intuitive.

    As you say working out which exceptions are permanent vs retryable might be a bit of work; maybe something for later.

    In the short term, how about we include an explicit check that the driver class (returned by getDriverClassName()) can be found on the class path, before even trying to instantiate containers. That seems to cover the most likely scenario of the entire DB vendor JAR being missing.

    What do you think?

  2. added this to the 1.1.9 milestone on Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions