Skip to content

Commit

Permalink
Fix remote DEV tests after breaking package config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Mar 21, 2024
1 parent 6b306f7 commit 86930ff
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<execution>
<configuration>
<systemProperties>
<quarkus.native.enabled>${quarkus.native.enabled}</quarkus.native.enabled>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<quarkus.package.type>${quarkus.package.type}</quarkus.package.type>
<quarkus.native.container-build>${quarkus.native.container-build}</quarkus.native.container-build>
Expand All @@ -454,6 +455,8 @@
</plugins>
</build>
<properties>
<quarkus.native.enabled>true</quarkus.native.enabled>
<!-- TODO: drop next line when Quarkus is bumped to 3.10 -->
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.container-build>true</quarkus.native.container-build>
<quarkus.native.native-image-xmx>5g</quarkus.native.native-image-xmx>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -109,7 +109,7 @@ private static boolean isPodman() {
}
}

private static boolean isQuarkusScenario(AnnotatedElement annotatedElement) {
static boolean isQuarkusScenario(AnnotatedElement annotatedElement) {
return annotatedElement.isAnnotationPresent(QuarkusScenario.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> PACKAGE_TYPE_NATIVE_VALUES = Arrays.asList("native", "native-sources");
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
io.quarkus.test.scenarios.execution.condition.AnnotationBindingQuarkusScenarioContainerExecutionCondition
io.quarkus.test.scenarios.execution.condition.AnnotationBindingQuarkusScenarioContainerExecutionCondition
io.quarkus.test.scenarios.execution.condition.DisableDevModeTestsInNativeExecutionCondition
1 change: 1 addition & 0 deletions quarkus-test-core/src/main/resources/build-time-list
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ quarkus.oidc.enabled
quarkus.openshift.
quarkus.otel.enabled
quarkus.package.type
quarkus.package.jar.type
quarkus.messaging.health.enabled
quarkus.messaging.kafka.serializer-autodetection.enabled
quarkus.messaging.metrics.enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down

0 comments on commit 86930ff

Please sign in to comment.