Fixes the regression in 19 for MariaDB, MySQL and other DBs

databases that are not using an official liquibase type in Database.java could not be seeded anymore because

the liquibase types we use in model-jpa were not indexed and loaded during the build anymore.

Introduces highly needed tests for other databases than postgres, because postgres has an official liquibase databasetype in its list

in database.java and as such differs from nearly all other vendors.

Closes #13389
This commit is contained in:
Dominik Guhr 2022-07-28 13:00:11 +02:00 committed by Hynek Mlnařík
parent 2a926f3e61
commit 059a132476
10 changed files with 68 additions and 4 deletions

View file

@ -490,7 +490,7 @@ jobs:
- name: Run Quarkus Storage Tests - name: Run Quarkus Storage Tests
run: | run: |
./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest,DatabaseOptionsDistTest,JPAStoreDistTest,HotRodStoreDistTest,MixedStoreDistTest | misc/log/trimmer.sh ./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest,MariaDBDistTest#testSuccessful,MySQLDistTest#testSuccessful,DatabaseOptionsDistTest,JPAStoreDistTest,HotRodStoreDistTest,MixedStoreDistTest | misc/log/trimmer.sh
TEST_RESULT=${PIPESTATUS[0]} TEST_RESULT=${PIPESTATUS[0]}
find . -path '*/target/surefire-reports/*.xml' | zip -q reports-quarkus-tests.zip -@ find . -path '*/target/surefire-reports/*.xml' | zip -q reports-quarkus-tests.zip -@
exit $TEST_RESULT exit $TEST_RESULT

View file

@ -25,6 +25,11 @@ import java.util.Optional;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import org.keycloak.config.StorageOptions; import org.keycloak.config.StorageOptions;
/***
* Checks if JPA is enabled either for the legacy or the new store.
*
* Returns true if the legacy store is used or the new store is used with storage==jpa
*/
public class IsJpaStoreEnabled implements BooleanSupplier { public class IsJpaStoreEnabled implements BooleanSupplier {
@Override @Override

View file

@ -23,6 +23,9 @@ import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvi
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
/**
* Checks if the legacy store is enabled. returns true if no storage=... is set. Returns false otherwise.
*/
public class IsLegacyStoreEnabled implements BooleanSupplier { public class IsLegacyStoreEnabled implements BooleanSupplier {
@Override @Override

View file

@ -127,7 +127,6 @@ import io.quarkus.vertx.http.deployment.FilterBuildItem;
import org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck; import org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck;
import org.keycloak.quarkus.runtime.storage.database.jpa.NamedJpaConnectionProviderFactory; import org.keycloak.quarkus.runtime.storage.database.jpa.NamedJpaConnectionProviderFactory;
import org.keycloak.quarkus.runtime.storage.database.jpa.QuarkusJpaMapStorageProviderFactory;
import org.keycloak.quarkus.runtime.themes.FlatClasspathThemeResourceProviderFactory; import org.keycloak.quarkus.runtime.themes.FlatClasspathThemeResourceProviderFactory;
import org.keycloak.representations.provider.ScriptProviderDescriptor; import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.representations.provider.ScriptProviderMetadata; import org.keycloak.representations.provider.ScriptProviderMetadata;
@ -471,10 +470,15 @@ class KeycloakProcessor {
} }
@BuildStep(onlyIf = IsJpaStoreEnabled.class, onlyIfNot = IsLegacyStoreEnabled.class) @BuildStep(onlyIf = IsJpaStoreEnabled.class, onlyIfNot = IsLegacyStoreEnabled.class)
void indexJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) { void indexNewJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-map-jpa")); indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-map-jpa"));
} }
@BuildStep(onlyIf = IsLegacyStoreEnabled.class)
void indexLegacyJpaStore(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-jpa"));
}
@Record(ExecutionTime.STATIC_INIT) @Record(ExecutionTime.STATIC_INIT)
@BuildStep @BuildStep
void initializeFilter(BuildProducer<FilterBuildItem> filters, KeycloakRecorder recorder) { void initializeFilter(BuildProducer<FilterBuildItem> filters, KeycloakRecorder recorder) {

View file

@ -87,6 +87,10 @@
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId> <artifactId>mariadb</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View file

@ -23,6 +23,7 @@ import org.keycloak.it.utils.KeycloakDistribution;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MariaDBContainer; import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.DockerImageName;
@ -95,15 +96,19 @@ public class DatabaseContainer {
private GenericContainer<?> createContainer() { private GenericContainer<?> createContainer() {
String POSTGRES_IMAGE = System.getProperty("kc.db.postgresql.container.image", "postgres:alpine"); String POSTGRES_IMAGE = System.getProperty("kc.db.postgresql.container.image", "postgres:alpine");
String MARIADB_IMAGE = System.getProperty("kc.db.mariadb.container.image", "mariadb:10.5.9"); String MARIADB_IMAGE = System.getProperty("kc.db.mariadb.container.image", "mariadb:10.5.9");
String MYSQL_IMAGE = System.getProperty("kc.db.mysql.container.image", "mysql:latest");
DockerImageName POSTGRES = DockerImageName.parse(POSTGRES_IMAGE).asCompatibleSubstituteFor("postgres"); DockerImageName POSTGRES = DockerImageName.parse(POSTGRES_IMAGE).asCompatibleSubstituteFor("postgres");
DockerImageName MARIADB = DockerImageName.parse(MARIADB_IMAGE).asCompatibleSubstituteFor("mariadb"); DockerImageName MARIADB = DockerImageName.parse(MARIADB_IMAGE).asCompatibleSubstituteFor("mariadb");
DockerImageName MYSQL = DockerImageName.parse(MYSQL_IMAGE).asCompatibleSubstituteFor("mysql");
switch (alias) { switch (alias) {
case "postgres": case "postgres":
return configureJdbcContainer(new PostgreSQLContainer(POSTGRES)); return configureJdbcContainer(new PostgreSQLContainer(POSTGRES));
case "mariadb": case "mariadb":
return configureJdbcContainer(new MariaDBContainer(MARIADB)); return configureJdbcContainer(new MariaDBContainer(MARIADB));
case "mysql":
return configureJdbcContainer(new MySQLContainer(MYSQL));
case "infinispan": case "infinispan":
return configureInfinispanUser(new GenericContainer("quay.io/infinispan/server:12.1.7.Final")) return configureInfinispanUser(new GenericContainer("quay.io/infinispan/server:12.1.7.Final"))
.withExposedPorts(11222); .withExposedPorts(11222);

View file

@ -0,0 +1,16 @@
/*
* Copyright 2021 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.
*/

View file

@ -0,0 +1,16 @@
/*
* Copyright 2021 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.
*/

View file

@ -18,10 +18,11 @@
package org.keycloak.it.storage.database.dist; package org.keycloak.it.storage.database.dist;
import org.keycloak.it.junit5.extension.CLITest; import org.keycloak.it.junit5.extension.CLITest;
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.WithDatabase; import org.keycloak.it.junit5.extension.WithDatabase;
import org.keycloak.it.storage.database.MariaDBTest; import org.keycloak.it.storage.database.MariaDBTest;
@CLITest @DistributionTest(removeBuildOptionsAfterBuild = true)
@WithDatabase(alias = "mariadb") @WithDatabase(alias = "mariadb")
public class MariaDBDistTest extends MariaDBTest { public class MariaDBDistTest extends MariaDBTest {

View file

@ -0,0 +1,10 @@
package org.keycloak.it.storage.database.dist;
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.WithDatabase;
import org.keycloak.it.storage.database.MySQLTest;
@DistributionTest(removeBuildOptionsAfterBuild = true)
@WithDatabase(alias = "mysql")
public class MySQLDistTest extends MySQLTest {
}