Skip to content

Commit

Permalink
More reliable test setup in integration-tests/hibernate-orm-tenancy/d…
Browse files Browse the repository at this point in the history
…atasource

The previous config was relying on FlyWay on a default datasource to create other databases
which named datasources pointed at.

Which works well, until a named datasource gets initialized before the default datasource;
then named datasource initialization fails because the corresponding database doesn't exist yet.

This happened on my local laptop, I don't know why it didn't happen on CI.
  • Loading branch information
yrodiere committed Nov 2, 2023
1 parent 6932a4c commit 10cd7be
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
12 changes: 8 additions & 4 deletions integration-tests/hibernate-orm-tenancy/datasource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Additionally, you can generate a native image and run the tests for this native
mvn clean install -Dtest-containers -Dstart-containers -Dnative
```

If you don't want to run MariaDB as a Docker container, you can start your own MariaDB server. It needs to listen on the default port and have a database called `hibernate_orm_test` and a root user with the password `secret`.
If you don't want to run MariaDB as a Docker container, you can start your own MariaDB server.
It needs to listen on the default port and have a database called `hibernate_orm_test` and a root user with the password `secret`,
and it needs to be initialized with the SQL script found at `custom-mariadbconfig/init.sql`.

You can then run the tests as follows (either with `-Dnative` or not):

Expand All @@ -34,18 +36,20 @@ should not include the database name: check the `application.properties` to see
To run the MariaDB server "manually" via command line for testing, the following command line could be useful:

```
docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name quarkus_test_mariadb -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 mariadb:10.4
docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name quarkus_test_mariadb -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=secret -p 3308:3306 mariadb:10.4
```

or if you prefer podman, this won't need root permissions:

```
podman run --rm=true --net=host --memory-swappiness=0 --tmpfs /var/lib/mysql:rw --tmpfs /var/log:rw --name mariadb_demo -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 mariadb:10.4
podman run --rm=true --net=host --memory-swappiness=0 --tmpfs /var/lib/mysql:rw --tmpfs /var/log:rw --name mariadb_demo -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=secret -p 3308:3306 mariadb:10.4
```

N.B. it takes a while for MariaDB to be actually booted and accepting connections.

After it's fully booted, you can run all integration tests via
After it's fully booted you will then need to initialize the database with the SQL script found at `custom-mariadbconfig/init.sql`.

Once that's done, you can run all integration tests via:

```
mvn clean install -Dtest-containers -Dnative
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/hibernate-orm-tenancy/datasource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@
<wait>
<time>20000</time>
<healthy>true</healthy>
<exec>
<breakOnError>true</breakOnError>
<postStart>bash -c eval\ ${@} -- mysql -h localhost -uroot -psecret &lt;/etc/mysql/conf.d/init.sql</postStart>
</exec>
</wait>
<volumes>
<bind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ quarkus.hibernate-orm.database.generation=none
quarkus.hibernate-orm.multitenant=database
quarkus.hibernate-orm.packages=io.quarkus.it.hibernate.multitenancy.fruit

# Default DB Configuration
quarkus.datasource.db-kind=mariadb
quarkus.datasource.username=root
quarkus.datasource.password=secret
quarkus.datasource.jdbc.url=${mariadb.base_url}/hibernate_orm_test
quarkus.datasource.jdbc.max-size=1
quarkus.flyway.migrate-at-start=true
#Reset Flyway metadata at boot, as the database might have been tainted by previous integration tests:
quarkus.flyway.clean-at-start=true
quarkus.flyway.locations=classpath:database/default

# DATABASE Tenant 'base' Configuration
quarkus.datasource.base.db-kind=mariadb
quarkus.datasource.base.username=jane
Expand Down

0 comments on commit 10cd7be

Please sign in to comment.