2014-12-29 13:39:42 +00:00
Test with various databases
===========================
MySQL
-----
2015-04-14 08:30:58 +00:00
The simplest way to test with MySQL is to use the official [MySQL docker image ](https://registry.hub.docker.com/_/mysql/ ).
2014-12-29 13:39:42 +00:00
Start MySQL:
docker run --name mysql -e MYSQL_DATABASE=keycloak -e MYSQL_USER=keycloak -e MYSQL_PASSWORD=keycloak -e MYSQL_ROOT_PASSWORD=keycloak -d mysql
Run tests:
2015-04-14 08:30:58 +00:00
mvn install -Dkeycloak.connectionsJpa.url=jdbc:mysql://`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mysql`/keycloak -Dkeycloak.connectionsJpa.driver=com.mysql.jdbc.Driver -Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak
2014-12-29 13:39:42 +00:00
Stop MySQl:
docker rm -f mysql
PostgreSQL
----------
2015-04-14 08:30:58 +00:00
The simplest way to test with PostgreSQL is to use the official [PostgreSQL docker image ](https://registry.hub.docker.com/_/postgres/ ).
2014-12-29 13:39:42 +00:00
2014-12-30 09:05:27 +00:00
Start PostgreSQL:
2014-12-29 13:39:42 +00:00
docker run --name postgres -e POSTGRES_DATABASE=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=keycloak -e POSTGRES_ROOT_PASSWORD=keycloak -d postgres
Run tests:
2015-04-14 08:30:58 +00:00
mvn install -Dkeycloak.connectionsJpa.url=jdbc:postgresql://`docker inspect --format '{{ .NetworkSettings.IPAddress }}' postgres`:5432/keycloak -Dkeycloak.connectionsJpa.driver=org.postgresql.Driver -Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak
2014-12-29 13:39:42 +00:00
2014-12-30 09:05:27 +00:00
Stop PostgreSQL:
2014-12-29 13:39:42 +00:00
docker rm -f postgres
2016-05-04 15:31:46 +00:00
MariaDB
-------
The simplest way to test with MariaDB is to use the official [MariaDB docker image ](https://registry.hub.docker.com/_/mariadb/ ).
Start MariaDB:
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=keycloak -e MYSQL_USER=keycloak -e MYSQL_PASSWORD=keycloak -d mariadb:10.1
Run tests:
mvn install -Dkeycloak.connectionsJpa.url=jdbc:mariadb://`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mariadb`/keycloak -Dkeycloak.connectionsJpa.driver=org.mariadb.jdbc.Driver -Dkeycloak.connectionsJpa.user=keycloak -Dkeycloak.connectionsJpa.password=keycloak
Stop MySQl:
2019-01-29 17:17:58 +00:00
docker rm -f mariadb
2014-12-29 13:39:42 +00:00
2019-01-29 17:17:58 +00:00
Using built-in profiles to run database tests using docker containers
-------
2019-03-19 10:41:42 +00:00
The project provides specific profiles to run database tests using containers. Below is a just a sample of implemented profiles. In order to get a full list, please invoke (`mvn help:all-profiles -pl testsuite/integration-arquillian | grep -- db- | grep -v allocator`):
2019-01-29 17:17:58 +00:00
* `db-mysql`
* `db-postgres`
2019-01-31 15:42:27 +00:00
As an example, to run tests using a MySQL docker container on Undertow auth-server:
2019-01-29 17:17:58 +00:00
2019-01-31 15:42:27 +00:00
mvn -f testsuite/integration-arquillian clean verify -Pdb-mysql
2019-01-29 17:17:58 +00:00
If you want to run tests using a pre-configured Keycloak distribution (instead of Undertow):
2022-09-30 07:41:57 +00:00
mvn -f testsuite/integration-arquillian clean verify -Pdb-mysql,jpa,auth-server-quarkus
2019-01-31 15:42:27 +00:00
2022-09-30 07:41:57 +00:00
Note that you must always activate the `jpa` profile when using auth-server-quarkus.
2019-01-31 15:42:27 +00:00
If the mvn command fails for any reason, it may also fail to remove the container which
must be then removed manually.
2022-11-18 16:50:21 +00:00
For Oracle databases, the images are not publicly available due to licensing restrictions.
Build the Docker image per instructions at
https://github.com/oracle/docker-images/tree/main/OracleDatabase.
Update the property `docker.database.image` if you used a different
2019-01-31 15:42:27 +00:00
name or tag for the image.
Note that Docker containers may occupy some space even after termination, and
especially with databases that might be easily a gigabyte. It is thus
advisable to run `docker system prune` occasionally to reclaim that space.
2019-03-19 10:41:42 +00:00
Using DB Allocator Service
-------
The testsuite can use the DB Allocator Service to allocate and release desired database automatically.
Since some of the database properties (such as JDBC URL, Username or Password) need to be used when building the Auth Server,
the allocation and deallocation need to happen when building the `integration-arquillian` project (instead of `tests/base` as
it happens in other cases).
In order to use the DB Allocator Service, you must use the `jpa` profile with one of the `db-allocator-*` . Here's a full example to
2022-09-30 07:41:57 +00:00
run JPA with Auth Server Quarkus and MSSQL 2016:
2019-03-19 10:41:42 +00:00
```
2019-05-24 10:59:57 +00:00
mvn -f testsuite/integration-arquillian/pom.xml clean verify \
2022-09-30 07:41:57 +00:00
-Pjpa,auth-server-quarkus,db-allocator-db-mssql2016 \
2019-03-19 10:41:42 +00:00
-Ddballocator.uri=< < db-allocator-servlet-url > > \
-Ddballocator.user=< < db-allocator-user > > \
-Dmaven.test.failure.ignore=true
```
Using `-Dmaven.test.failure.ignore=true` is not strictly required but highly recommended. After running the tests,
the DB Allocator Plugin should release the allocated database.
2019-05-24 10:59:57 +00:00
**NOTE**: If you killed the maven surefire test preliminary (for example with CTRL-C or `kill -9` command), it will be
good to manually release the allocated database. Please check `dballocator.uri` and add `?operation=report` to the end of the URL.
Find your DB in the GUI and release it manually.
2019-03-19 10:41:42 +00:00
Below is a just a sample of implemented profiles. In order to get a full list, please invoke (`mvn help:all-profiles -pl testsuite/integration-arquillian | grep -- db-allocator-db-`):
2019-05-24 10:59:57 +00:00
* `db-allocator-db-postgres` - for testing with Postgres 9.6.x
* `db-allocator-db-mysql` - for testing with MySQL 5.7