diff --git a/integration-tests/jpa-postgresql-withxml/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java b/integration-tests/jpa-postgresql-withxml/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java deleted file mode 100644 index 7928216825aaff..00000000000000 --- a/integration-tests/jpa-postgresql-withxml/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.it.jpa.postgresql; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.quarkus.test.junit.nativeimage.NativeBuildOutputExtension; - -@ExtendWith(NativeBuildOutputExtension.class) -@QuarkusIntegrationTest -public class ImageMetricsITCase { - @Test - public void verifyImageMetrics() { - NativeBuildOutputExtension buildOutput = new NativeBuildOutputExtension(); - buildOutput.verifyImageMetrics(); - } -} diff --git a/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.0/image-metrics.properties b/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.0/image-metrics.properties deleted file mode 100644 index 5968543202550e..00000000000000 --- a/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.0/image-metrics.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=88215776 -image_details.total_bytes.tolerance=3 -analysis_results.types.reachable=20556 -analysis_results.types.reachable.tolerance=3 -analysis_results.methods.reachable=101602 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=30176 -analysis_results.fields.reachable.tolerance=3 -analysis_results.types.reflection=6585 -analysis_results.types.reflection.tolerance=3 -analysis_results.methods.reflection=4556 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=147 -analysis_results.fields.reflection.tolerance=3 -analysis_results.types.jni=63 -analysis_results.types.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=70 -analysis_results.fields.jni.tolerance=3 diff --git a/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.1/image-metrics.properties b/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.1/image-metrics.properties deleted file mode 100644 index 89afefa176b668..00000000000000 --- a/integration-tests/jpa-postgresql-withxml/src/test/resources/image-metrics/23.1/image-metrics.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=94415680 -image_details.total_bytes.tolerance=3 -analysis_results.types.reachable=20867 -analysis_results.types.reachable.tolerance=3 -analysis_results.methods.reachable=103028 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=30098 -analysis_results.fields.reachable.tolerance=3 -analysis_results.types.reflection=6705 -analysis_results.types.reflection.tolerance=3 -analysis_results.methods.reflection=4551 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=170 -analysis_results.fields.reflection.tolerance=3 -analysis_results.types.jni=61 -analysis_results.types.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=60 -analysis_results.fields.jni.tolerance=2 \ No newline at end of file diff --git a/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java b/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java deleted file mode 100644 index 7598509c8bb62e..00000000000000 --- a/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/ImageMetricsITCase.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.quarkus.it.jpa.postgresql; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.quarkus.test.junit.nativeimage.NativeBuildOutputExtension; - -@ExtendWith(NativeBuildOutputExtension.class) -@QuarkusIntegrationTest -public class ImageMetricsITCase { - - @Test - public void verifyImageMetrics() { - NativeBuildOutputExtension buildOutput = new NativeBuildOutputExtension(); - buildOutput.verifyImageMetrics(); - } -} diff --git a/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.0/image-metrics.properties b/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.0/image-metrics.properties deleted file mode 100644 index 440f53540d8a98..00000000000000 --- a/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.0/image-metrics.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=79712248 -image_details.total_bytes.tolerance=3 -analysis_results.types.reachable=19625 -analysis_results.types.reachable.tolerance=3 -analysis_results.methods.reachable=97338 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=27443 -analysis_results.fields.reachable.tolerance=3 -analysis_results.types.reflection=6128 -analysis_results.types.reflection.tolerance=3 -analysis_results.methods.reflection=4374 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=176 -analysis_results.fields.reflection.tolerance=3 -analysis_results.types.jni=63 -analysis_results.types.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=70 -analysis_results.fields.jni.tolerance=3 diff --git a/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.1/image-metrics.properties b/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.1/image-metrics.properties deleted file mode 100644 index 94cb7d716f262e..00000000000000 --- a/integration-tests/jpa-postgresql/src/test/resources/image-metrics/23.1/image-metrics.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=85866808 -image_details.total_bytes.tolerance=3 -analysis_results.types.reachable=19853 -analysis_results.types.reachable.tolerance=3 -analysis_results.methods.reachable=98606 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=27389 -analysis_results.fields.reachable.tolerance=3 -analysis_results.types.reflection=6232 -analysis_results.types.reflection.tolerance=3 -analysis_results.methods.reflection=4367 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=201 -analysis_results.fields.reflection.tolerance=3 -analysis_results.types.jni=61 -analysis_results.types.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=60 -analysis_results.fields.jni.tolerance=2 \ No newline at end of file diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/ImageMetricsITCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/ImageMetricsITCase.java deleted file mode 100644 index 527b3d840c87d7..00000000000000 --- a/integration-tests/main/src/test/java/io/quarkus/it/main/ImageMetricsITCase.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.it.main; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.quarkus.test.junit.nativeimage.NativeBuildOutputExtension; - -@ExtendWith(NativeBuildOutputExtension.class) -@QuarkusIntegrationTest -public class ImageMetricsITCase { - @Test - public void verifyImageMetrics() { - NativeBuildOutputExtension buildOutput = new NativeBuildOutputExtension(); - buildOutput.verifyImageMetrics(); - } -} diff --git a/integration-tests/main/src/test/resources/image-metrics/23.0/image-metrics.properties b/integration-tests/main/src/test/resources/image-metrics/23.0/image-metrics.properties deleted file mode 100644 index 2da98333835da4..00000000000000 --- a/integration-tests/main/src/test/resources/image-metrics/23.0/image-metrics.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=138255480 -image_details.total_bytes.tolerance=3 -analysis_results.types.reachable=29952 -analysis_results.types.reachable.tolerance=3 -analysis_results.methods.reachable=149162 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=44103 -analysis_results.fields.reachable.tolerance=3 -analysis_results.types.reflection=8927 -analysis_results.types.reflection.tolerance=3 -analysis_results.methods.reflection=7136 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=445 -analysis_results.fields.reflection.tolerance=3 -analysis_results.types.jni=64 -analysis_results.types.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=70 -analysis_results.fields.jni.tolerance=1 diff --git a/integration-tests/main/src/test/resources/image-metrics/23.1/image-metrics.properties b/integration-tests/main/src/test/resources/image-metrics/23.1/image-metrics.properties deleted file mode 100644 index 1afdbb1d431fdc..00000000000000 --- a/integration-tests/main/src/test/resources/image-metrics/23.1/image-metrics.properties +++ /dev/null @@ -1,24 +0,0 @@ -# Properties file used by ImageMetricsITCase -image_details.total_bytes=147268552 -image_details.total_bytes.tolerance=3 -# TODO: Switch to using analysis_results.types.reachable key once we drop support for GraalVM 22.3.0 -analysis_results.classes.reachable=30415 -analysis_results.classes.reachable.tolerance=3 -analysis_results.methods.reachable=151296 -analysis_results.methods.reachable.tolerance=3 -analysis_results.fields.reachable=44325 -analysis_results.fields.reachable.tolerance=3 -# TODO: Switch to using analysis_results.types.reflection key once we drop support for GraalVM 22.3.0 -analysis_results.classes.reflection=9118 -analysis_results.classes.reflection.tolerance=3 -analysis_results.methods.reflection=7688 -analysis_results.methods.reflection.tolerance=3 -analysis_results.fields.reflection=496 -analysis_results.fields.reflection.tolerance=3 -# TODO: Switch to using analysis_results.types.jni key once we drop support for GraalVM 22.3.0 -analysis_results.classes.jni=62 -analysis_results.classes.jni.tolerance=1 -analysis_results.methods.jni=55 -analysis_results.methods.jni.tolerance=1 -analysis_results.fields.jni=62 -analysis_results.fields.jni.tolerance=2 diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/nativeimage/NativeBuildOutputExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/nativeimage/NativeBuildOutputExtension.java deleted file mode 100644 index 8d73517a359d4c..00000000000000 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/nativeimage/NativeBuildOutputExtension.java +++ /dev/null @@ -1,147 +0,0 @@ -package io.quarkus.test.junit.nativeimage; - -import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Locale; -import java.util.Properties; - -import jakarta.json.Json; -import jakarta.json.JsonObject; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -import io.quarkus.deployment.pkg.steps.GraalVM; - -/** - * This is a general utility to assert via - * unit testing how many classes, methods, objects etc. have been included in a native-image. - *
- * For detailed information and explanations on the build output, visit - * the upstream GraalVM - * documentation. - */ -public class NativeBuildOutputExtension implements BeforeAllCallback { - - private static final String IMAGE_METRICS_TEST_PROPERTIES = "image-metrics.properties"; - private static final String IMAGE_METRICS_DIR = "image-metrics"; - private final JsonObject buildOutput; - private static GraalVM.Version mandrelVersion; - - public NativeBuildOutputExtension() { - this.buildOutput = getBuildOutput(); - } - - public void verifyImageMetrics() { - String version = mandrelVersion.getMajorMinorAsString(); - String propertiesFileName = IMAGE_METRICS_DIR + "/" + version + "/" + IMAGE_METRICS_TEST_PROPERTIES; - verifyImageMetrics(propertiesFileName); - } - - public void verifyImageMetrics(String propertiesFileName) { - /* - * Allow users to skip this kind of tests by setting env variable QUARKUS_NATIVE_IT_SKIP_VERIFY_IMAGE_METRICS to true - */ - boolean skipVerifyImageMetrics = Boolean.parseBoolean(System.getenv("QUARKUS_NATIVE_IT_SKIP_VERIFY_IMAGE_METRICS")); - Assumptions.assumeFalse(skipVerifyImageMetrics, - "Environment variable QUARKUS_NATIVE_IT_SKIP_VERIFY_IMAGE_METRICS is set. Skipping image metrics verification."); - - Properties properties = getProperties(propertiesFileName); - - Assertions.assertAll(properties.entrySet().stream().map(entry -> () -> { - var key = (String) entry.getKey(); - var value = (String) entry.getValue(); - if (key.endsWith(".tolerance")) { - return; - } - String[] keyParts = key.split("\\."); - String tolerance = properties.getProperty(key + ".tolerance"); - assert tolerance != null : "tolerance not defined for " + key; - assertValueWithinRange(Integer.parseInt(value), Integer.parseInt(tolerance), keyParts); - })); - } - - private Properties getProperties(String propertiesFileName) { - Properties properties = new Properties(); - try { - InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(propertiesFileName); - Assumptions.assumeTrue(resourceAsStream != null, - "Could not find properties file matching the Mandrel version being used: " + propertiesFileName); - properties.load(resourceAsStream); - } catch (IOException e) { - Assertions.fail("Could not load properties from " + propertiesFileName, e); - } - return properties; - } - - private void assertValueWithinRange(int expectedValue, int tolerancePercentage, String... key) { - JsonObject currentObject = buildOutput; - for (int i = 0; i < key.length - 1; i++) { - currentObject = currentObject.getJsonObject(key[i]); - } - String lastKey = key[key.length - 1]; - int actualValue = currentObject.getInt(lastKey); - Assertions.assertTrue(isNumberWithinRange(expectedValue, actualValue, tolerancePercentage), - "Expected " + String.join(".", key) + " to be within range [" + expectedValue + " +- " + tolerancePercentage - + "%] but was " + actualValue); - } - - private boolean isNumberWithinRange(int expectedNumberOfClasses, int actualNumberOfClasses, int tolerancePercentage) { - final int lowerBound = expectedNumberOfClasses - (expectedNumberOfClasses * tolerancePercentage / 100); - final int upperBound = expectedNumberOfClasses + (expectedNumberOfClasses * tolerancePercentage / 100); - return actualNumberOfClasses >= lowerBound && actualNumberOfClasses <= upperBound; - } - - private static JsonObject getBuildOutput() { - final Path buildOutputPath = getBuildOutputPath(); - try (InputStream inputStream = Files.newInputStream(buildOutputPath)) { - return Json.createReader(inputStream).readObject(); - } catch (Exception e) { - throw new RuntimeException("Could not load build output", e); - } - } - - private static Path getBuildOutputPath() { - final Path buildDirectory = locateNativeImageBuildDirectory(); - final File[] buildOutput = buildDirectory.toFile().listFiles((dir, name) -> name.toLowerCase(Locale.ROOT) - .endsWith("-build-output-stats.json")); - Assertions.assertNotNull(buildOutput, "Could not identify the native image build output"); - Assertions.assertEquals(1, buildOutput.length, "Could not identify the native image build output"); - return buildOutput[0].toPath(); - } - - private static Path locateNativeImageBuildDirectory() { - Path buildPath = Paths.get("target"); - final File[] files = buildPath.toFile().listFiles((dir, name) -> name.toLowerCase(Locale.ROOT) - .endsWith("-native-image-source-jar")); - Assertions.assertNotNull(files, "Could not identify the native image build directory"); - Assertions.assertEquals(1, files.length, "Could not identify the native image build directory"); - return files[0].toPath(); - } - - @Override - public void beforeAll(ExtensionContext extensionContext) throws Exception { - mandrelVersion = getMandrelVersion(extensionContext); - } - - private GraalVM.Version getMandrelVersion(ExtensionContext context) { - Properties quarkusArtifactProperties = readQuarkusArtifactProperties(context); - String fullVersion = quarkusArtifactProperties.getProperty("metadata.graalvm.version.full"); - try { - return GraalVM.Version.of(fullVersion.lines()); - } catch (NumberFormatException e) { - System.out.println( - "WARNING: Unable to determine the GraalVM version with which the native binary was built. metadata.graalvm.version.full = " - + fullVersion); - return GraalVM.Version.CURRENT; - } - } -}