Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error messages when JDBC driver not found #230

Closed
ldcasillas-progreso opened this issue Oct 7, 2016 · 1 comment
Closed

Confusing error messages when JDBC driver not found #230

ldcasillas-progreso opened this issue Oct 7, 2016 · 1 comment
Milestone

Comments

@ldcasillas-progreso
Copy link

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

@rnorth
Copy link
Member

rnorth commented Nov 20, 2016

@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?

rnorth added a commit that referenced this issue Jan 22, 2017
… JDBC Driver cannot be instantiated. Connection attempts remain inside a retry loop.

Refs #230
@rnorth rnorth added this to the 1.1.9 milestone Jan 22, 2017
@rnorth rnorth closed this as completed Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants