Quarkus: Test DataSource not used in 1.4.1.Final

Created on 28 Apr 2020  路  11Comments  路  Source: quarkusio/quarkus

Describe the bug
Tests use only the DataSource configured in main resources instead of the one in test resources.

Expected behavior
The in-memory DataSource configured in the test resources is used like in 1.4.0.CR1 and before.

Actual behavior
The in-memory test resource H2 database is started but agroal is configured to use main resources PostgreSQL DataSource.

To Reproduce
Steps to reproduce the behavior:

  1. Configure a data source in main resources.
  2. Configure a data source in test resources.
  3. Shutdown main data base.
  4. Execute tests accessing the database.

Configuration
Main application.properties:

# Add your application.properties here, if applicable.
quarkus.datasource.db-kind = postgresql
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:2345/test-db
quarkus.datasource.username = postgres
quarkus.datasource.password = secret

Test application.properties:

# Add your application.properties here, if applicable.
quarkus.datasource.url = jdbc:h2:tcp://localhost/mem:test-db;MODE=PostgreSQL
quarkus.datasource.driver = org.h2.Driver

Screenshots
(If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):

  • Output of uname -a or ver: Linux voyager 5.6.7-arch1-1 #1 SMP PREEMPT Thu, 23 Apr 2020 09:13:56 +0000 x86_64 GNU/Linux
  • Output of java -version: openjdk version "11.0.6" 2020-01-14
    OpenJDK Runtime Environment GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02)
    OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02, mixed mode, sharing)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.4.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Gradle 6.3
kinbug

Most helpful comment

We used to support it and we got several complaints of it not working so I would be in favor of having it working again.

All 11 comments

TBH, I don't think we ever consciously supported using
src/test/resources/application.properties.
I am pretty sure that what you are seeing is a result of https://github.com/quarkusio/quarkus/pull/8284 (which made things a lot more sensible).

You should be able to use differentiate the test properties by using %test.as a prefix in
src/main/resources/application.properties
(as explained here)

cc @gsmet @aloubyansky

We used to support it and we got several complaints of it not working so I would be in favor of having it working again.

@geoand this is not so clear when following the data source guide [1] where the prefix is not mentioned.

Also I prefer to separate test related configuration from the main configuration where I use different profiles for different flavors of the application. So I'd vote to introduce this again as supported feature.

/edit: I also noticed that for using '%test.' properties, I need to add h2 driver to main dependencies (implementation or runtimeOnly) resulting in test related classes showing up in the final runner jar file.

[1] https://quarkus.io/guides/datasource#in-memory-databases

Is this a regression in 1.4.1? Do you guys want me to look into it?

I guess it is a regression, although from my POV I don't think we ever advertised this way of doing things - but I might just have missed it.

That's what I get for answering questions on SO... :facepalm: :facepalm: :facepalm:

Better keep my mouth shut next time :laughing:

FWIW, I'd just like to throw in a big fat +1 for @pschyma's statement:

Also I prefer to separate test related configuration from the main configuration where I use different profiles for different flavors of the application.

This is a Gradle-only issue, AFAICT.

I think it's the same issue as #8845

Was this page helpful?
0 / 5 - 0 ratings