-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @testprofile in native mode #12974
- Loading branch information
Showing
19 changed files
with
629 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
core/runtime/src/main/java/io/quarkus/runtime/ConfigChangeRecorder.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigChangeRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.runtime.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
import io.quarkus.runtime.configuration.ConfigurationRuntimeConfig.BuildTimeMismatchAtRuntime; | ||
|
||
@Recorder | ||
public class ConfigChangeRecorder { | ||
|
||
private static final Logger log = Logger.getLogger(ConfigChangeRecorder.class); | ||
|
||
public void handleConfigChange(ConfigurationRuntimeConfig configurationConfig, Map<String, String> buildTimeConfig) { | ||
Config configProvider = ConfigProvider.getConfig(); | ||
List<String> mismatches = null; | ||
for (Map.Entry<String, String> entry : buildTimeConfig.entrySet()) { | ||
Optional<String> val = configProvider.getOptionalValue(entry.getKey(), String.class); | ||
if (val.isPresent()) { | ||
if (!val.get().equals(entry.getValue())) { | ||
if (mismatches == null) { | ||
mismatches = new ArrayList<>(); | ||
} | ||
mismatches.add( | ||
" - " + entry.getKey() + " was '" + entry.getValue() + "' at build time and is now '" + val.get() | ||
+ "'"); | ||
} | ||
} | ||
} | ||
if (mismatches != null && !mismatches.isEmpty()) { | ||
final String msg = "Build time property cannot be changed at runtime:\n" | ||
+ mismatches.stream().collect(Collectors.joining("\n")); | ||
switch (configurationConfig.buildTimeMismatchAtRuntime) { | ||
case fail: | ||
throw new IllegalStateException(msg); | ||
case warn: | ||
log.warn(msg); | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected " + BuildTimeMismatchAtRuntime.class.getName() + ": " | ||
+ configurationConfig.buildTimeMismatchAtRuntime); | ||
} | ||
|
||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigurationRuntimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.runtime.configuration; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot(name = "configuration", phase = ConfigPhase.RUN_TIME) | ||
public class ConfigurationRuntimeConfig { | ||
|
||
/** | ||
* What should happen if the application is started with a different build time configuration than it was compiled | ||
* against. This may be useful to prevent misconfiguration. | ||
* <p> | ||
* If this is set to {@code warn} the application will warn at start up. | ||
* <p> | ||
* If this is set to {@code fail} the application will fail at start up. | ||
* <p> | ||
* Native tests leveraging<code>@io.quarkus.test.junit.TestProfile</code> are always run with | ||
* {@code quarkus.configuration.build-time-mismatch-at-runtime = fail}. | ||
*/ | ||
@ConfigItem(defaultValue = "warn") | ||
public BuildTimeMismatchAtRuntime buildTimeMismatchAtRuntime; | ||
|
||
public enum BuildTimeMismatchAtRuntime { | ||
warn, | ||
fail | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-integration-tests-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-integration-test-native-config-profile</artifactId> | ||
<name>Quarkus - Integration Tests - Native Configuration Profile</name> | ||
<description>Native Configuration Profile</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-test</id> | ||
<phase/> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native-image-it-main</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<properties> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<configuration> | ||
<configurationProfiles> | ||
<configurationProfile>alt-profile</configurationProfile> | ||
</configurationProfiles> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...fig-profile/src/main/java/io/quarkus/it/nat/test/profile/NativeConfigProfileResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.it.nat.test.profile; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.arc.Arc; | ||
|
||
@Path("/native-config-profile") | ||
public class NativeConfigProfileResource { | ||
|
||
@ConfigProperty(name = "my.config.value") | ||
String myConfigValue; | ||
|
||
@Path("/myConfigValue") | ||
@Produces("text/plain") | ||
@GET | ||
public String myConfigValue() { | ||
return myConfigValue; | ||
} | ||
|
||
@Path("/unused-exists") | ||
@Produces("text/plain") | ||
@GET | ||
public boolean unusedExists() { | ||
return Arc.container().instance(UnusedRemovableBean.class).isAvailable(); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...tive-config-profile/src/main/java/io/quarkus/it/nat/test/profile/UnusedRemovableBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.it.nat.test.profile; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class UnusedRemovableBean { | ||
} |
4 changes: 4 additions & 0 deletions
4
integration-tests/native-config-profile/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
quarkus.arc.remove-unused-beans = none | ||
my.config.value = foo | ||
%bar-profile.my.config.value = bar | ||
%build-profile-change.quarkus.arc.remove-unused-beans = all |
35 changes: 35 additions & 0 deletions
35
...-profile/src/test/java/io/quarkus/it/nat/test/profile/BuiltTimeProfileChangeManualIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.it.nat.test.profile; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
import io.quarkus.test.junit.NativeTestExtension; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
/** | ||
* Run this manually via {@code mvn clean verify -Dnative -Dit.test=BuiltTimeProfileChangeManualITCase} to ensure that | ||
* {@link NativeTestExtension#beforeEach(org.junit.jupiter.api.extension.ExtensionContext)} throws an exception caused | ||
* by an application boot failure. The failure should happen because {@link NativeTestExtension} is setting | ||
* {@code quarkus.configuration.build-time-mismatch-at-runtime = fail} and | ||
* {@link BuildProfileChange#getConfigProfile()} returns a profile name that changes | ||
* {@code quarkus.arc.remove-unused-beans} in {@code application.properties}. | ||
*/ | ||
@NativeImageTest | ||
@TestProfile(BuiltTimeProfileChangeManualIT.BuildProfileChange.class) | ||
@Disabled("Manual testing only") | ||
public class BuiltTimeProfileChangeManualIT { | ||
@Test | ||
public void unusedExists() { | ||
Assertions.fail("Expected to fail in io.quarkus.test.junit.NativeTestExtension.beforeEach(ExtensionContext)"); | ||
} | ||
|
||
public static class BuildProfileChange implements QuarkusTestProfile { | ||
@Override | ||
public String getConfigProfile() { | ||
return "build-profile-change"; | ||
} | ||
} | ||
} |
Oops, something went wrong.