Skip to content

Commit

Permalink
Merge pull request quarkusio#36833 from yrodiere/tenancy-datasource-t…
Browse files Browse the repository at this point in the history
…estfix

More reliable test setup in integration-tests/hibernate-orm-tenancy/datasource
  • Loading branch information
yrodiere authored Nov 2, 2023
2 parents 2fe9d6e + 5da533e commit 72d993c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 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
@@ -1,19 +1,9 @@
# Hibernate ORM settings
quarkus.hibernate-orm.database.generation=none
quarkus.hibernate-orm.multitenant=database
quarkus.hibernate-orm.datasource=base
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 All @@ -37,7 +27,7 @@ quarkus.flyway.mycompany.locations=classpath:database/mycompany
# Inventory persistence unit
quarkus.hibernate-orm."inventory".database.generation=none
quarkus.hibernate-orm."inventory".multitenant=database
quarkus.hibernate-orm."inventory".datasource=<default>
quarkus.hibernate-orm."inventory".datasource=inventory
quarkus.hibernate-orm."inventory".packages=io.quarkus.it.hibernate.multitenancy.inventory

# DATABASE Tenant 'inventory' / 'base' Configuration
Expand Down

0 comments on commit 72d993c

Please sign in to comment.