From bd5636133e20ee51e9ec388f19674ce63b6fde39 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Mon, 11 May 2026 13:40:39 -0400 Subject: [PATCH 1/3] fix: adding aot compiliation to quarkus tests closes: #48846 Signed-off-by: Steve Hawkins --- .github/workflows/ci.yml | 4 +- .../it/cli/dist/HelpCommandDistTest.java | 28 ++++++++ .../it/utils/RawKeycloakDistribution.java | 67 ++++++++++++++----- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd674226c33..7004856fc90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -302,8 +302,8 @@ jobs: run: | declare -A PARAMS PARAMS["win"]="-Dkc.quarkus.tests.groups=win" - PARAMS["zip-slow"]="-Dkc.quarkus.tests.groups=slow" - PARAMS["zip-fast"]='-Dkc.quarkus.tests.groups=!slow' + PARAMS["zip-slow"]="-Dkc.quarkus.tests.groups=slow -Dkc.quarkus.tests.aot=true" + PARAMS["zip-fast"]='-Dkc.quarkus.tests.groups=!slow -Dkc.quarkus.tests.aot=true' PARAMS["storage"]="-Ptest-database" PARAMS["smoke"]="-Dkc.quarkus.tests.groups=smoke" diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/HelpCommandDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/HelpCommandDistTest.java index 8571f68fdd4..acdcd272419 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/HelpCommandDistTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/HelpCommandDistTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.stream.Stream; import org.keycloak.it.junit5.extension.CLIResult; import org.keycloak.it.junit5.extension.DistributionTest; @@ -42,6 +43,11 @@ import io.quarkus.test.junit.main.Launch; import org.apache.commons.io.FileUtils; import org.approvaltests.Approvals; +import org.approvaltests.core.ApprovalFailureReporter; +import org.approvaltests.reporters.intellij.IntelliJReporter; +import org.approvaltests.reporters.linux.LinuxDiffReporter; +import org.approvaltests.reporters.macosx.MacDiffReporter; +import org.approvaltests.reporters.windows.WindowsDiffReporter; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -223,8 +229,30 @@ private void assertHelp(CLIResult cliResult) { .replace("data\\log\\", "data/log/") .replace("\r\n", "\n"); } + + if (output.startsWith("Appending additional Java properties to JAVA_OPTS")) { + output = output.substring(output.indexOf("\n") + 1); + } try { + // on failure with java 25, the intellijreporter seems to work, but really just throws + // an exception later - https://github.com/approvals/ApprovalTests.Java/issues/800 + if (IntelliJReporter.findJetBrainsIdes().equals("")) { + Stream.of(WindowsDiffReporter.INSTANCE, LinuxDiffReporter.INSTANCE, MacDiffReporter.INSTANCE).forEach(reporter -> { + var reporters = reporter.getReporters(); + for (int i = 0; i < reporters.length; i++) { + if (reporters[i] instanceof IntelliJReporter) { + reporters[i] = new ApprovalFailureReporter() { + + @Override + public boolean report(String received, String approved) { + return false; + } + }; + } + } + }); + } Approvals.verify(output); } catch (Error cause) { if ("true".equals(System.getenv(REPLACE_EXPECTED))) { diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java index 7a3701e226c..fc750e23122 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -67,7 +68,6 @@ import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers; import io.quarkus.deployment.util.FileUtil; -import io.quarkus.deployment.util.IoUtil; import io.quarkus.fs.util.ZipUtils; import io.restassured.RestAssured; import org.apache.commons.io.FileUtils; @@ -78,7 +78,9 @@ import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; +import static org.keycloak.quarkus.runtime.Environment.KC_CONFIG_BUILT; import static org.keycloak.quarkus.runtime.Environment.LAUNCH_MODE; +import static org.keycloak.quarkus.runtime.Environment.LAUNCH_MODE_EXIT_BEFORE_BOOTSTRAP; import static org.keycloak.quarkus.runtime.Environment.isWindows; public final class RawKeycloakDistribution implements KeycloakDistribution { @@ -114,6 +116,13 @@ public RawKeycloakDistribution(boolean debug, boolean manualStop, boolean enable this.removeBuildOptionsAfterBuild = removeBuildOptionsAfterBuild; this.requestPort = requestPort; this.distPath = prepareDistribution(); + if (reCreate) { + try { + preInitH2(distPath); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } this.outputConsumer = new DefaultOutputConsumer(); } @@ -167,6 +176,8 @@ private CLIResult invoke(String script, List arguments) throws IOExcepti builder.environment().put("DEBUG_SUSPEND", "y"); }*/ + addAOTEnvVars(); + builder.environment().putAll(envVars); Process proc = builder.start(); @@ -545,7 +556,6 @@ private Path prepareDistribution() { ZipUtils.unzip(distFile.toPath(), distRootPath); FileUtils.copyDirectory(dPath.resolve("conf").toFile(), dPath.resolve("conf-bak").toFile()); FileUtils.copyDirectory(dPath.resolve("lib").resolve("quarkus").toFile(), dPath.resolve("quarkus-bak").toFile()); - preInitH2(dPath); postInit(dPath); } @@ -564,29 +574,43 @@ private Path prepareDistribution() { } private void preInitH2(Path dPath) throws IOException { - LOG.info("Creating pre-initialized database for reuse"); ProcessHandle.current().info().command().ifPresent(command -> { - ProcessBuilder pb = new ProcessBuilder(List.of(command, "-D" + LAUNCH_MODE + "=" + Environment.LAUNCH_MODE_EXIT_BEFORE_BOOTSTRAP, - "-Dkc.home.dir=" + dPath.toFile().getAbsolutePath(), "-Dkc.config.built=true", - "-Dkc.db=dev-file", "-jar", dPath.resolve("lib").resolve("quarkus-run.jar").toFile().getAbsolutePath(), "start-dev")); - try { - Process dbInit = pb.start(); - if (!dbInit.waitFor(30, TimeUnit.SECONDS)) { - throw new RuntimeException("Pre-initialized db process did not exit"); + Runtime.Version runtimeVersion = Runtime.version(); + boolean useAot = false; + if (Boolean.getBoolean("kc.quarkus.tests.aot")) { + String version = String.valueOf(runtimeVersion.version().get(0)); + if (Integer.parseInt(version) < 25) { + throw new AssertionError("AOT requested, but the java version is less than 25"); } - if (dbInit.exitValue() != 0) { - throw new RuntimeException("Could not create pre-initialized db, exit code %s: %s".formatted(dbInit.exitValue(), new String(IoUtil.readBytes(dbInit.getErrorStream())))); + useAot = true; + + if (envVars.containsKey("JAVA_OPTS_APPEND")) { + throw new AssertionError("the raw dist marked as recreate should not have JAVA_OPTS_APPEND set"); + } + File aotFile = getAotFile(dPath); + // TODO: we know for certain that the test java is 25+, so we'll set it here + envVars.put("JAVA", ProcessHandle.current().info().command().orElseThrow()); + envVars.put("JAVA_OPTS_APPEND", "-Xlog:aot -XX:AOTCacheOutput=\"%s\"".formatted(aotFile.getAbsolutePath())); + } + + LOG.infof("Creating pre-initialized database %sfor reuse", useAot ? "and aot cache ":""); + + try { + CLIResult result = invoke(SCRIPT_CMD, List.of("start-dev", "-D%s=%s".formatted(LAUNCH_MODE, LAUNCH_MODE_EXIT_BEFORE_BOOTSTRAP), "-D%s=true".formatted(KC_CONFIG_BUILT))); + if (result.exitCode() != 0) { + throw new RuntimeException("Could not create pre-initialized db, exit code %s: %s".formatted(result.exitCode(), new String(result.getErrorOutput()))); } } catch (IOException e) { - throw new RuntimeException(e); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException(e); + throw new UncheckedIOException(e); } }); FileUtils.copyDirectory(dPath.resolve("data").resolve("h2").toFile(), dPath.resolve("h2-bak").toFile()); } + private File getAotFile(Path dPath) { + return dPath.resolve("app.aot").toFile(); + } + private void postInit(Path dPath) { if (System.getProperty("product") != null) { // JDBC drivers might be excluded if running as a product build @@ -641,12 +665,23 @@ private void startServer(List arguments) throws Exception { if (debug) { builder.environment().put("DEBUG_SUSPEND", "y"); } + + addAOTEnvVars(); builder.environment().putAll(envVars); keycloak = builder.start(); } + private void addAOTEnvVars() { + File aotFile = getAotFile(getDistPath()); + if (aotFile.exists() && !envVars.containsKey("JAVA_OPTS_APPEND")) { + // TODO: we know for certain that the test java is 25+, so we'll set it here + envVars.put("JAVA", ProcessHandle.current().info().command().orElseThrow()); + envVars.put("JAVA_OPTS_APPEND", "-XX:AOTCache=\"%s\"".formatted(aotFile.getAbsolutePath())); + } + } + @Override public void setManualStop(boolean manualStop) { this.manualStop = manualStop; From 3f9d82b8684c1393698da9f9ae569ec971423f1a Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Tue, 12 May 2026 17:43:06 -0400 Subject: [PATCH 2/3] Update quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michal Vavřík <43821672+michalvavrik@users.noreply.github.com> Signed-off-by: Steven Hawkins --- .../java/org/keycloak/it/utils/RawKeycloakDistribution.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java index fc750e23122..b213873bee9 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java @@ -589,7 +589,7 @@ private void preInitH2(Path dPath) throws IOException { } File aotFile = getAotFile(dPath); // TODO: we know for certain that the test java is 25+, so we'll set it here - envVars.put("JAVA", ProcessHandle.current().info().command().orElseThrow()); + envVars.put("JAVA", command); envVars.put("JAVA_OPTS_APPEND", "-Xlog:aot -XX:AOTCacheOutput=\"%s\"".formatted(aotFile.getAbsolutePath())); } From 2599caf934c68052db03000f55bcbc935ccdf12b Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Wed, 13 May 2026 06:18:32 -0400 Subject: [PATCH 3/3] Update quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java Co-authored-by: Pedro Ruivo Signed-off-by: Steven Hawkins --- .../java/org/keycloak/it/utils/RawKeycloakDistribution.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java index b213873bee9..5d7d293bd6f 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/RawKeycloakDistribution.java @@ -578,8 +578,7 @@ private void preInitH2(Path dPath) throws IOException { Runtime.Version runtimeVersion = Runtime.version(); boolean useAot = false; if (Boolean.getBoolean("kc.quarkus.tests.aot")) { - String version = String.valueOf(runtimeVersion.version().get(0)); - if (Integer.parseInt(version) < 25) { + if (Runtime.version().feature() < 25) { throw new AssertionError("AOT requested, but the java version is less than 25"); } useAot = true;