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

No suitable driver found for Postgresql with TestContainers since Quarkus 1.8 #12116

Closed
agoncal opened this issue Sep 15, 2020 · 8 comments · Fixed by #12181
Closed

No suitable driver found for Postgresql with TestContainers since Quarkus 1.8 #12116

agoncal opened this issue Sep 15, 2020 · 8 comments · Fixed by #12181
Labels
kind/bug Something isn't working
Milestone

Comments

@agoncal
Copy link
Contributor

agoncal commented Sep 15, 2020

Describe the bug

I have a TestContainers test that pings a Postgres DB. This test does not actually use Quarkus but I realized that it was working in 1.7.3 and failing in 1.8.

It is not a stopper for me (as I said, I realized I should have taken the @QuarkusTest annotation) but it sounds that something has been introduced that it makes this test fail (this test has been working since Quarkus 1.6 at least).

Expected behavior

The test should pass as in 1.7.3

Actual behavior

The test fail with:

java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:32831/vintageStoreDB?loggerLevel=OFF
        at org.acme.PingPostgreSQLTest.shouldPingPostgreSQL(PingPostgreSQLTest.java:32)

To Reproduce

Generate a brand new Quarkus 1.7.3-Final app with the Postgres extension. Then, add the TestContainers dependency:

  <properties>
   ...
    <testcontainers.version>1.14.3</testcontainers.version>
  </properties>

    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>postgresql</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>

Now create a new Test

@QuarkusTest
@Testcontainers
public class PingPostgreSQLTest {

  @Container
  public static PostgreSQLContainer pg = new PostgreSQLContainer<>("postgres:12.4")
    .withDatabaseName("vintageStoreDB")
    .withUsername("vintage")
    .withPassword("vintage")
    .withExposedPorts(5432);

  @Test
  public void shouldPingPostgreSQL() throws Exception {
    pg.start();

    try (Connection con = DriverManager.getConnection(pg.getJdbcUrl(), pg.getUsername(), pg.getPassword());
         Statement st = con.createStatement();
         ResultSet rs = st.executeQuery("SELECT VERSION()")) {

      if (rs.next()) {
        assertTrue(rs.getString(1).contains("PostgreSQL 12"));
      } else {
        throw new Exception();
      }
    }

    pg.stop();
  }
}

This test just uses TestContainers to ping a Postgres db. It doesn't use any Quarkus. In fact, if you leave the @QuarkusTest annotation it also works. Then, move to Quarkus 1.8.0, it fails.

Configuration

The test with 1.7.3 works even without any application.properties file declaring a Postgres driver or JDBC URL.
Because it is now failing with 1.8 I tried to add quarkus.datasource.db-kind=postgresql and so on.

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin iMac-Pro-de-Antonio.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64
  • Output of java -version: java version "11.0.6" 2020-01-14 LTS
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.8.0-Final
  • Build tool (ie. output of mvnw --version or gradlew --version): 3.6.3_1

Additional context
(Add any other context about the problem here.)

@agoncal agoncal added the kind/bug Something isn't working label Sep 15, 2020
@geoand
Copy link
Contributor

geoand commented Sep 15, 2020

@gsmet does this ring a bell?

@gsmet
Copy link
Member

gsmet commented Sep 16, 2020

No. It doesn't. Given there's nothing Quarkus in it, I don't think it's related to any of my changes.

@agoncal please provide a reproducer. Going through steps is cumbersome and generates unnecessary noise. Thanks.

@geoand
Copy link
Contributor

geoand commented Sep 16, 2020

Yeah, the reproducer also makes it trivial to actually debug and compare between the 2 versions.

But my guess is that if it worked before, it was mostly by accident.

@agoncal
Copy link
Contributor Author

agoncal commented Sep 16, 2020

Here it is : https://github.com/agoncal/agoncal-bug-quarkus-testcontainers

It is the exact same code. The only thing that changes is the Quarkus version. If you run a mvn test on the root, the Postgres test of Quarkus 1.7.3 succeeds, while the 1.8 fails.

@gsmet
Copy link
Member

gsmet commented Sep 17, 2020

I can reproduce the issue. I wonder if it could be a CL issue as I don't see how other changes could be related to that considering how level this is.

@stuartwdouglas does it ring a bell?

stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Sep 18, 2020
The act of clearing the manager could result in
the drivers being initialized, which can change
the runtime behaviour.

Fixes quarkusio#12116
@stuartwdouglas
Copy link
Member

This will work if you call DriverManager.getDrivers() before the getConnection call. Weirdly it will also work if you try and call getConnection a second time.

The root cause of this is the DriverRemover, which calls getDriver and initializes it with a ClassLoader that is being closed.

@agoncal
Copy link
Contributor Author

agoncal commented Sep 18, 2020

Hum... I've tried to invoke DriverManager.getDrivers() before getting the connection, but it does not work.

gsmet pushed a commit to stuartwdouglas/quarkus that referenced this issue Sep 18, 2020
The act of clearing the manager could result in
the drivers being initialized, which can change
the runtime behaviour.

Fixes quarkusio#12116
@gsmet gsmet modified the milestones: 1.9.0 - master, 1.8.2.Final Oct 1, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 1, 2020
The act of clearing the manager could result in
the drivers being initialized, which can change
the runtime behaviour.

Fixes quarkusio#12116
@agoncal
Copy link
Contributor Author

agoncal commented Oct 7, 2020

Just tested with Quarkus 1.8.2 and its ok now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants