From 5ad4ad67c0d195cc5f10e521a1d184b6877fb0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Fri, 22 Mar 2024 11:51:40 +0100 Subject: [PATCH] Fix remote DEV tests after breaking package config changes --- .../qe/QuickstartUsingUsingUberJarIT.java | 3 +- .../test/java/io/quarkus/qe/TodoDemoIT.java | 3 +- pom.xml | 3 ++ ...usScenarioContainerExecutionCondition.java | 6 +-- ...evModeTestsInNativeExecutionCondition.java | 41 +++++++++++++++++++ .../quarkus/model/QuarkusProperties.java | 20 ++++++--- ...ondition.QuarkusScenarioExecutionCondition | 3 +- .../src/main/resources/build-time-list | 3 ++ .../src/main/resources/Dockerfile.legacy-jar | 2 +- 9 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/DisableDevModeTestsInNativeExecutionCondition.java diff --git a/examples/external-applications/src/test/java/io/quarkus/qe/QuickstartUsingUsingUberJarIT.java b/examples/external-applications/src/test/java/io/quarkus/qe/QuickstartUsingUsingUberJarIT.java index c2d4f622c..7b3a1c9c8 100644 --- a/examples/external-applications/src/test/java/io/quarkus/qe/QuickstartUsingUsingUberJarIT.java +++ b/examples/external-applications/src/test/java/io/quarkus/qe/QuickstartUsingUsingUberJarIT.java @@ -15,7 +15,8 @@ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Windows does not support long file paths") public class QuickstartUsingUsingUberJarIT { - @GitRepositoryQuarkusApplication(repo = "https://github.com/quarkusio/quarkus-quickstarts.git", contextDir = "getting-started", mavenArgs = "-Dquarkus.package.type=uber-jar -DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_PLATFORM_VERSION}") + // TODO: drop config key quarkus.package.type when Quarkus is bumped to 3.10 + @GitRepositoryQuarkusApplication(repo = "https://github.com/quarkusio/quarkus-quickstarts.git", contextDir = "getting-started", mavenArgs = "-Dquarkus.package.jar.type=uber-jar -Dquarkus.package.type=uber-jar -DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_PLATFORM_VERSION}") static final RestService app = new RestService(); @Test diff --git a/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java b/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java index 4f992cd78..0dcfac7e6 100644 --- a/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java +++ b/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java @@ -16,7 +16,8 @@ public class TodoDemoIT { private static final String REPO = "https://github.com/quarkusio/todo-demo-app.git"; private static final String DEFAULT_ARGS = "-DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_PLATFORM_VERSION} "; - private static final String UBER = "-Dquarkus.package.type=uber-jar "; + // TODO: drop config key quarkus.package.type when Quarkus is bumped to 3.10 + private static final String UBER = "-Dquarkus.package.type=uber-jar -Dquarkus.package.jar.type=uber-jar "; @GitRepositoryQuarkusApplication(repo = REPO, mavenArgs = DEFAULT_ARGS + UBER) static final RestService app = new RestService(); diff --git a/pom.xml b/pom.xml index 201fec02e..68667336a 100644 --- a/pom.xml +++ b/pom.xml @@ -436,6 +436,7 @@ + ${quarkus.native.enabled} ${project.build.directory}/${project.build.finalName}-runner ${quarkus.package.type} ${quarkus.native.container-build} @@ -448,6 +449,8 @@ + true + native true 5g diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/AbstractQuarkusScenarioContainerExecutionCondition.java b/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/AbstractQuarkusScenarioContainerExecutionCondition.java index af1df3884..241195d29 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/AbstractQuarkusScenarioContainerExecutionCondition.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/AbstractQuarkusScenarioContainerExecutionCondition.java @@ -26,9 +26,9 @@ public abstract class AbstractQuarkusScenarioContainerExecutionCondition impleme + " Linux containers"); public static final String ENV_DOES_NOT_SUPPORT_LINUX_CONTAINERS = "Test class '%s' requires Linux containers, " + "but the environment does not support them"; - private static final Logger LOG = Logger.getLogger(AbstractQuarkusScenarioContainerExecutionCondition.class.getName()); - private static final ConditionEvaluationResult CONDITION_NOT_MATCHED = enabled("This condition should " + static final ConditionEvaluationResult CONDITION_NOT_MATCHED = enabled("This condition should " + "only be applied on test classes annotated with the '@QuarkusScenario' annotation"); + private static final Logger LOG = Logger.getLogger(AbstractQuarkusScenarioContainerExecutionCondition.class.getName()); private static final String LINUX_CONTAINERS_NOT_REQUIRED = "Test class '%s' does not require containers"; private static final String LINUX_CONTAINER_OS_TYPE = "linux"; private static final String PODMAN = "podman"; @@ -109,7 +109,7 @@ private static boolean isPodman() { } } - private static boolean isQuarkusScenario(AnnotatedElement annotatedElement) { + static boolean isQuarkusScenario(AnnotatedElement annotatedElement) { return annotatedElement.isAnnotationPresent(QuarkusScenario.class); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/DisableDevModeTestsInNativeExecutionCondition.java b/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/DisableDevModeTestsInNativeExecutionCondition.java new file mode 100644 index 000000000..296e4828e --- /dev/null +++ b/quarkus-test-core/src/main/java/io/quarkus/test/scenarios/execution/condition/DisableDevModeTestsInNativeExecutionCondition.java @@ -0,0 +1,41 @@ +package io.quarkus.test.scenarios.execution.condition; + +import static io.quarkus.test.scenarios.execution.condition.AbstractQuarkusScenarioContainerExecutionCondition.CONDITION_NOT_MATCHED; +import static io.quarkus.test.services.quarkus.model.QuarkusProperties.isNativePackageType; + +import java.lang.reflect.Modifier; +import java.util.Arrays; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExtensionContext; + +import io.quarkus.test.services.DevModeQuarkusApplication; +import io.quarkus.test.services.RemoteDevModeQuarkusApplication; + +public class DisableDevModeTestsInNativeExecutionCondition implements QuarkusScenarioExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + return context + .getElement() + .filter(AbstractQuarkusScenarioContainerExecutionCondition::isQuarkusScenario) + .map(clazz -> (Class) clazz) + .map(DisableDevModeTestsInNativeExecutionCondition::evaluate) + .orElse(CONDITION_NOT_MATCHED); + } + + private static ConditionEvaluationResult evaluate(Class testClass) { + if (isNativePackageType() && isDevModeTest(testClass)) { + return ConditionEvaluationResult.disabled("DEV mode tests can't be run when native mode is enabled"); + } else { + return ConditionEvaluationResult.enabled("Not a DEV mode test in native mode"); + } + } + + private static boolean isDevModeTest(Class testClass) { + return Arrays.stream(testClass.getDeclaredFields()) + .filter(m -> Modifier.isStatic(m.getModifiers())) + .anyMatch(m -> m.isAnnotationPresent(RemoteDevModeQuarkusApplication.class) + || m.isAnnotationPresent(DevModeQuarkusApplication.class)); + } +} diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java index 416e71972..f0fc1dfa5 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/model/QuarkusProperties.java @@ -14,10 +14,14 @@ public final class QuarkusProperties { public static final PropertyLookup PLATFORM_GROUP_ID = new PropertyLookup("quarkus.platform.group-id", "io.quarkus"); public static final PropertyLookup PLATFORM_VERSION = new PropertyLookup("quarkus.platform.version"); public static final PropertyLookup PLUGIN_VERSION = new PropertyLookup("quarkus-plugin.version"); + public static final PropertyLookup NATIVE_ENABLED = new PropertyLookup("quarkus.native.enabled"); public static final String QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY = "quarkus.analytics.disabled"; public static final PropertyLookup QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP = new PropertyLookup( QUARKUS_ANALYTICS_DISABLED_LOCAL_PROP_KEY, "true"); - public static final String PACKAGE_TYPE_NAME = "quarkus.package.type"; + // TODO: drop ternary operator when Quarkus version is bumped to 3.10 + public static final String PACKAGE_TYPE_NAME = defaultVersionIfEmpty(PLATFORM_VERSION.get()).startsWith("3.9.") + ? "quarkus.package.type" + : "quarkus.package.jar.type"; public static final String MUTABLE_JAR = "mutable-jar"; public static final PropertyLookup PACKAGE_TYPE = new PropertyLookup(PACKAGE_TYPE_NAME); public static final List PACKAGE_TYPE_NATIVE_VALUES = Arrays.asList("native", "native-sources"); @@ -45,19 +49,25 @@ public static boolean disableBuildAnalytics() { } public static boolean isNativePackageType() { - return PACKAGE_TYPE_NATIVE_VALUES.contains(PACKAGE_TYPE.get()); + // TODO: simplify condition when Quarkus version is bumped to 3.10 + return isNativeEnabled() || PACKAGE_TYPE_NATIVE_VALUES.contains(PACKAGE_TYPE.get()); } public static boolean isNativePackageType(ServiceContext context) { - return PACKAGE_TYPE_NATIVE_VALUES.contains(PACKAGE_TYPE.get(context)); + // TODO: simplify condition when Quarkus version is bumped to 3.10 + return isNativeEnabled() || PACKAGE_TYPE_NATIVE_VALUES.contains(PACKAGE_TYPE.get(context)); + } + + public static boolean isNativeEnabled() { + return Boolean.parseBoolean(NATIVE_ENABLED.get()); } public static boolean isLegacyJarPackageType(ServiceContext context) { - return PACKAGE_TYPE_LEGACY_JAR_VALUES.contains(PACKAGE_TYPE.get(context)); + return !isNativeEnabled() && PACKAGE_TYPE_LEGACY_JAR_VALUES.contains(PACKAGE_TYPE.get(context)); } public static boolean isJvmPackageType(ServiceContext context) { - return PACKAGE_TYPE_JVM_VALUES.contains(PACKAGE_TYPE.get(context)); + return !isNativeEnabled() && PACKAGE_TYPE_JVM_VALUES.contains(PACKAGE_TYPE.get(context)); } private static String defaultVersionIfEmpty(String version) { diff --git a/quarkus-test-core/src/main/resources/META-INF/services/io.quarkus.test.scenarios.execution.condition.QuarkusScenarioExecutionCondition b/quarkus-test-core/src/main/resources/META-INF/services/io.quarkus.test.scenarios.execution.condition.QuarkusScenarioExecutionCondition index 59c08aea7..b109c16dd 100644 --- a/quarkus-test-core/src/main/resources/META-INF/services/io.quarkus.test.scenarios.execution.condition.QuarkusScenarioExecutionCondition +++ b/quarkus-test-core/src/main/resources/META-INF/services/io.quarkus.test.scenarios.execution.condition.QuarkusScenarioExecutionCondition @@ -1 +1,2 @@ -io.quarkus.test.scenarios.execution.condition.AnnotationBindingQuarkusScenarioContainerExecutionCondition \ No newline at end of file +io.quarkus.test.scenarios.execution.condition.AnnotationBindingQuarkusScenarioContainerExecutionCondition +io.quarkus.test.scenarios.execution.condition.DisableDevModeTestsInNativeExecutionCondition diff --git a/quarkus-test-core/src/main/resources/build-time-list b/quarkus-test-core/src/main/resources/build-time-list index dc30e5f4a..61f8dd400 100644 --- a/quarkus-test-core/src/main/resources/build-time-list +++ b/quarkus-test-core/src/main/resources/build-time-list @@ -69,7 +69,10 @@ quarkus.resteasy-client-oidc-token-propagation.enabled quarkus.oidc.enabled quarkus.openshift. quarkus.otel.enabled +FIXME: drop next line when Quarkus version is bumped to 3.10 quarkus.package.type +quarkus.package.jar.type +quarkus.native.enabled quarkus.messaging.health.enabled quarkus.messaging.kafka.serializer-autodetection.enabled quarkus.messaging.metrics.enabled diff --git a/quarkus-test-images/src/main/resources/Dockerfile.legacy-jar b/quarkus-test-images/src/main/resources/Dockerfile.legacy-jar index f5593d372..5ecbf942a 100644 --- a/quarkus-test-images/src/main/resources/Dockerfile.legacy-jar +++ b/quarkus-test-images/src/main/resources/Dockerfile.legacy-jar @@ -3,7 +3,7 @@ # # Before building the container image run: # -# ./mvnw package -Dquarkus.package.type=legacy-jar +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar # # Then, build the image with: #