Make GHA Map-JPA base testsuite running with Quarkus
Co-authored-by: Martin Batros <mabartos@redhat.com> Closes #13725
This commit is contained in:
parent
02a69561b5
commit
021189f190
5 changed files with 100 additions and 107 deletions
121
.github/workflows/ci.yml
vendored
121
.github/workflows/ci.yml
vendored
|
@ -200,7 +200,7 @@ jobs:
|
|||
timeout-minutes: 90
|
||||
strategy:
|
||||
matrix:
|
||||
server: ['quarkus', 'quarkus-map', 'quarkus-map-hot-rod']
|
||||
server: ['quarkus', 'quarkus-map', 'quarkus-map-hot-rod', 'quarkus-map-jpa']
|
||||
tests: ['group1','group2','group3']
|
||||
fail-fast: false
|
||||
steps:
|
||||
|
@ -211,8 +211,19 @@ jobs:
|
|||
- name: Check whether HEAD^ contains HotRod storage relevant changes
|
||||
run: echo "GIT_HOTROD_RELEVANT_DIFF=$( git diff --name-only HEAD^ | egrep -ic -e '^model/map-hot-rod|^model/map/|^model/build-processor' )" >> $GITHUB_ENV
|
||||
|
||||
- name: Check whether HotRod storage matrix should be executed
|
||||
if: ${{ endsWith(matrix.server, '-map-hot-rod') && env.GIT_HOTROD_RELEVANT_DIFF == 0 }}
|
||||
run: echo "SHOULD_BE_EXECUTED=false" >> $GITHUB_ENV
|
||||
|
||||
- name: Check whether HEAD^ contains JPA map storage relevant changes
|
||||
run: echo "GIT_MAP_JPA_RELEVANT_DIFF=$( git diff --name-only HEAD^ | egrep -ic -e '^model/map-jpa/|^model/map/|^model/build-processor' )" >> $GITHUB_ENV
|
||||
|
||||
- name: Check whether Map-JPA storage matrix should be executed
|
||||
if: ${{ endsWith(matrix.server, '-map-jpa') && env.GIT_MAP_JPA_RELEVANT_DIFF == 0 }}
|
||||
run: echo "SHOULD_BE_EXECUTED=false" >> $GITHUB_ENV
|
||||
|
||||
- name: Cache Maven packages
|
||||
if: ${{ github.event_name != 'pull_request' || matrix.server != 'quarkus-map-hot-rod' || env.GIT_HOTROD_RELEVANT_DIFF != 0 }}
|
||||
if: ${{ github.event_name != 'pull_request' || env.SHOULD_BE_EXECUTED != 'false' }}
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
|
@ -220,7 +231,7 @@ jobs:
|
|||
restore-keys: cache-1-${{ runner.os }}-m2
|
||||
|
||||
- name: Download built keycloak
|
||||
if: ${{ github.event_name != 'pull_request' || matrix.server != 'quarkus-map-hot-rod' || env.GIT_HOTROD_RELEVANT_DIFF != 0 }}
|
||||
if: ${{ github.event_name != 'pull_request' || env.SHOULD_BE_EXECUTED != 'false' }}
|
||||
id: download-keycloak
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
|
@ -233,23 +244,24 @@ jobs:
|
|||
# ls -lR ~/.m2/repository
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
if: ${{ github.event_name != 'pull_request' || matrix.server != 'quarkus-map-hot-rod' || env.GIT_HOTROD_RELEVANT_DIFF != 0 }}
|
||||
if: ${{ github.event_name != 'pull_request' || env.SHOULD_BE_EXECUTED != 'false' }}
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ env.DEFAULT_JDK_VERSION }}
|
||||
- name: Update maven settings
|
||||
if: ${{ github.event_name != 'pull_request' || matrix.server != 'quarkus-map-hot-rod' || env.GIT_HOTROD_RELEVANT_DIFF != 0 }}
|
||||
if: ${{ github.event_name != 'pull_request' || env.SHOULD_BE_EXECUTED != 'false' }}
|
||||
run: mkdir -p ~/.m2 ; cp .github/settings.xml ~/.m2/
|
||||
- name: Prepare test providers
|
||||
if: ${{ matrix.server == 'quarkus' || matrix.server == 'quarkus-map' }}
|
||||
run: ./mvnw clean install -nsu -B -e -f testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers -Pauth-server-quarkus
|
||||
- name: Run base tests
|
||||
if: ${{ github.event_name != 'pull_request' || matrix.server != 'quarkus-map-hot-rod' || env.GIT_HOTROD_RELEVANT_DIFF != 0 }}
|
||||
if: ${{ github.event_name != 'pull_request' || env.SHOULD_BE_EXECUTED != 'false' }}
|
||||
run: |
|
||||
declare -A PARAMS TESTGROUP
|
||||
PARAMS["quarkus"]="-Pauth-server-quarkus"
|
||||
PARAMS["quarkus-map"]="-Pauth-server-quarkus -Pmap-storage -Dpageload.timeout=90000"
|
||||
PARAMS["quarkus-map-hot-rod"]="-Pauth-server-quarkus -Pmap-storage,map-storage-hot-rod -Dpageload.timeout=90000"
|
||||
PARAMS["quarkus-map-jpa"]="-Pauth-server-quarkus -Pmap-storage,map-storage-jpa -Dpageload.timeout=90000"
|
||||
TESTGROUP["group1"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.(a[abc]|ad[a-l]|[^a-q]).*]" # Tests alphabetically before admin tests and those after "r"
|
||||
TESTGROUP["group2"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.(ad[^a-l]|a[^a-d]|b).*]" # Admin tests and those starting with "b"
|
||||
TESTGROUP["group3"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.([c-q]).*]" # All the rest
|
||||
|
@ -351,103 +363,6 @@ jobs:
|
|||
path: reports-${{ matrix.server }}-base-tests-${{ matrix.tests }}.zip
|
||||
if-no-files-found: ignore
|
||||
|
||||
test-posgres:
|
||||
name: Base testsuite (postgres)
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 80
|
||||
strategy:
|
||||
matrix:
|
||||
server: ['undertow-map-jpa']
|
||||
tests: ['group1','group2','group3']
|
||||
fail-fast: false
|
||||
|
||||
services:
|
||||
# Label used to access the service container
|
||||
postgres:
|
||||
# Docker Hub image
|
||||
image: postgres
|
||||
env:
|
||||
# Provide env variables for the image
|
||||
POSTGRES_DB: keycloak
|
||||
POSTGRES_USER: keycloak
|
||||
POSTGRES_PASSWORD: pass
|
||||
# Set health checks to wait until postgres has started
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
# Maps tcp port 5432 on service container to the host
|
||||
- 5432:5432
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Check whether HEAD^ contains JPA map storage relevant changes
|
||||
run: echo "GIT_MAP_JPA_RELEVANT_DIFF=$( git diff --name-only HEAD^ | egrep -ic -e '^model/map-jpa/|^model/map/|^model/build-processor' )" >> $GITHUB_ENV
|
||||
|
||||
- name: Cache Maven packages
|
||||
if: ${{ github.event_name != 'pull_request' || env.GIT_MAP_JPA_RELEVANT_DIFF != 0 }}
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: cache-2-${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: cache-1-${{ runner.os }}-m2
|
||||
|
||||
- name: Download built keycloak
|
||||
if: ${{ github.event_name != 'pull_request' || env.GIT_MAP_JPA_RELEVANT_DIFF != 0 }}
|
||||
id: download-keycloak
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: ~/.m2/repository/org/keycloak/
|
||||
name: keycloak-artifacts.zip
|
||||
|
||||
- uses: actions/setup-java@v3
|
||||
if: ${{ github.event_name != 'pull_request' || env.GIT_MAP_JPA_RELEVANT_DIFF != 0 }}
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ env.DEFAULT_JDK_VERSION }}
|
||||
- name: Update maven settings
|
||||
if: ${{ github.event_name != 'pull_request' || env.GIT_MAP_JPA_RELEVANT_DIFF != 0 }}
|
||||
run: mkdir -p ~/.m2 ; cp .github/settings.xml ~/.m2/
|
||||
|
||||
- name: Run base tests
|
||||
if: ${{ github.event_name != 'pull_request' || env.GIT_MAP_JPA_RELEVANT_DIFF != 0 }}
|
||||
run: |
|
||||
declare -A PARAMS TESTGROUP
|
||||
PARAMS["undertow-map-jpa"]="-Pmap-storage,map-storage-jpa -Dpageload.timeout=90000"
|
||||
TESTGROUP["group1"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.(a[abc]|ad[a-l]|[^a-q]).*]" # Tests alphabetically before admin tests and those after "r"
|
||||
TESTGROUP["group2"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.(ad[^a-l]|a[^a-d]|b).*]" # Admin tests and those starting with "b"
|
||||
TESTGROUP["group3"]="-Dtest=!**.crossdc.**,!**.cluster.**,%regex[org.keycloak.testsuite.([c-q]).*]" # All the rest
|
||||
|
||||
./mvnw clean install -nsu -B ${PARAMS["${{ matrix.server }}"]} ${TESTGROUP["${{ matrix.tests }}"]} -f testsuite/integration-arquillian/tests/base/pom.xml | misc/log/trimmer.sh
|
||||
|
||||
TEST_RESULT=${PIPESTATUS[0]}
|
||||
find . -path '*/target/surefire-reports/*.xml' | zip -q reports-${{ matrix.server }}-base-tests-${{ matrix.tests }}.zip -@
|
||||
exit $TEST_RESULT
|
||||
|
||||
- name: Analyze Test and/or Coverage Results
|
||||
uses: runforesight/foresight-test-kit-action@v1.3.0
|
||||
if: always() && github.repository == 'keycloak/keycloak'
|
||||
with:
|
||||
api_key: ${{ secrets.FORESIGHT_API_KEY }}
|
||||
test_format: JUNIT
|
||||
test_framework: JUNIT
|
||||
test_path: 'testsuite/integration-arquillian/tests/base/target/surefire-reports/*.xml'
|
||||
|
||||
- name: Base test reports
|
||||
uses: actions/upload-artifact@v3
|
||||
if: failure()
|
||||
with:
|
||||
name: reports-${{ matrix.server }}-base-tests-${{ matrix.tests }}
|
||||
retention-days: 14
|
||||
path: reports-${{ matrix.server }}-base-tests-${{ matrix.tests }}.zip
|
||||
if-no-files-found: ignore
|
||||
|
||||
### Tests: Quarkus distribution
|
||||
|
||||
quarkus-test-cluster:
|
||||
|
|
|
@ -837,10 +837,9 @@ mvn clean install -f testsuite/integration-arquillian/tests/base \
|
|||
|
||||
### Running tests with JPA Map storage
|
||||
|
||||
Run PostgreSQL database:
|
||||
```shell
|
||||
podman run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_USER=keycloak -e POSTGRES_DB=keycloak -d postgres:13.2
|
||||
```
|
||||
By default tests with `map-storage-jpa` profile spawns a new Postgres container
|
||||
with each test execution. Default image used is "postgres:alpine". To spawn different
|
||||
version, it can be used "keycloak.map.storage.postgres.docker.image" system property.
|
||||
|
||||
Execute tests:
|
||||
```shell
|
||||
|
@ -848,6 +847,25 @@ mvn clean install -f testsuite/integration-arquillian/tests/base \
|
|||
-Pmap-storage,map-storage-jpa
|
||||
```
|
||||
|
||||
It's also possible to configure tests to connect to an external database, it might be useful
|
||||
for debugging purposes as the database is not removed after the testsuite run. On the other hand
|
||||
it'll require manual cleaning between two runs.
|
||||
|
||||
PostgreSQL database can be started e.g. by following command:
|
||||
```shell
|
||||
podman run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_USER=keycloak -e POSTGRES_DB=keycloak -d postgres:alpine
|
||||
```
|
||||
|
||||
To run the tests without spawning the container for you, execute tests with the following command:
|
||||
```shell
|
||||
mvn clean install -f testsuite/integration-arquillian/tests/base \
|
||||
-Pmap-storage,map-storage-jpa \
|
||||
-Dpostgres.start-container=false \
|
||||
-Dkeycloak.map.storage.connectionsJpa.url=<jdbc_url> \
|
||||
-Dkeycloak.map.storage.connectionsJpa.user=<user> \
|
||||
-Dkeycloak.map.storage.connectionsJpa.password=<password>
|
||||
```
|
||||
|
||||
### Running tests with HotRod Map storage
|
||||
|
||||
By default, Base testsuite with `map-storage-hotrod` profile spawn a new Infinispan container
|
||||
|
|
|
@ -112,6 +112,11 @@
|
|||
<artifactId>testcontainers</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
@ -810,6 +815,9 @@
|
|||
|
||||
<profile>
|
||||
<id>map-storage-jpa</id>
|
||||
<properties>
|
||||
<postgres.start-container>true</postgres.start-container>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -831,6 +839,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<postgres.start-container>${postgres.start-container}</postgres.start-container>
|
||||
|
||||
<keycloak.map.storage.connectionsJpa.url>${keycloak.map.storage.connectionsJpa.url}</keycloak.map.storage.connectionsJpa.url>
|
||||
<keycloak.map.storage.connectionsJpa.user>${keycloak.map.storage.connectionsJpa.user}</keycloak.map.storage.connectionsJpa.user>
|
||||
<keycloak.map.storage.connectionsJpa.password>${keycloak.map.storage.connectionsJpa.password}</keycloak.map.storage.connectionsJpa.password>
|
||||
|
|
|
@ -67,6 +67,7 @@ public class KeycloakArquillianExtension implements LoadableExtension {
|
|||
.observer(AppServerTestEnricher.class)
|
||||
.observer(CrossDCTestEnricher.class)
|
||||
.observer(HotRodStoreTestEnricher.class)
|
||||
.observer(PostgresContainerTestEnricher.class)
|
||||
.observer(H2TestEnricher.class);
|
||||
builder
|
||||
.service(TestExecutionDecider.class, MigrationTestExecutionDecider.class)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2022 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.keycloak.testsuite.arquillian;
|
||||
|
||||
import org.jboss.arquillian.container.spi.event.StartSuiteContainers;
|
||||
import org.jboss.arquillian.core.api.annotation.Observes;
|
||||
import org.jboss.arquillian.test.spi.event.suite.AfterSuite;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
|
||||
public class PostgresContainerTestEnricher {
|
||||
|
||||
private static final Boolean START_CONTAINER = Boolean.valueOf(System.getProperty("postgres.start-container", "false"));
|
||||
private static final String POSTGRES_DOCKER_IMAGE_NAME = System.getProperty("keycloak.map.storage.postgres.docker.image", "postgres:alpine");
|
||||
private static final PostgreSQLContainer POSTGRES_CONTAINER = new PostgreSQLContainer(POSTGRES_DOCKER_IMAGE_NAME);
|
||||
private static final String POSTGRES_DB_USER = System.getProperty("keycloak.map.storage.connectionsJpa.user", "keycloak");
|
||||
private static final String POSTGRES_DB_PASSWORD = System.getProperty("keycloak.map.storage.connectionsJpa.password", "pass");
|
||||
|
||||
public void beforeContainerStarted(@Observes(precedence = 1) StartSuiteContainers event) {
|
||||
if (START_CONTAINER) {
|
||||
POSTGRES_CONTAINER
|
||||
.withDatabaseName("keycloak")
|
||||
.withUsername(POSTGRES_DB_USER)
|
||||
.withPassword(POSTGRES_DB_PASSWORD)
|
||||
.start();
|
||||
|
||||
System.setProperty("keycloak.map.storage.connectionsJpa.url", POSTGRES_CONTAINER.getJdbcUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public void afterSuite(@Observes(precedence = 4) AfterSuite event) {
|
||||
if (START_CONTAINER) {
|
||||
POSTGRES_CONTAINER.stop();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue