Skip to content

Commit

Permalink
Merge pull request quarkusio#45100 from radcortez/fix-45083
Browse files Browse the repository at this point in the history
Use `TestConfig` to load test config instead of property names
  • Loading branch information
radcortez authored Dec 13, 2024
2 parents 805c3f3 + 8f5e156 commit b235baa
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public interface TestConfig {
* When the artifact is a {@code container}, this string is passed right after the {@code docker run} command.
* When the artifact is a {@code native binary}, this string is passed right after the native binary name.
*/
Optional<List<String>> argLine();
Optional<@WithConverter(TrimmedStringConverter.class) List<String>> argLine();

/**
* Additional environment variables to be set in the process that {@code @QuarkusIntegrationTest} launches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class LauncherUtil {
private LauncherUtil() {
}

@Deprecated(forRemoval = true, since = "3.17")
public static Config installAndGetSomeConfig() {
return ConfigProvider.getConfig();
}
Expand Down Expand Up @@ -227,7 +228,6 @@ static void updateConfigForPort(Integer effectivePort) {
if (effectivePort != null) {
System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config
System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager
installAndGetSomeConfig(); // reinitialize the configuration to make sure the actual port is used
System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one
System.setProperty("test.url", TestHTTPResourceManager.getUri());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class TestConfigUtil {
private TestConfigUtil() {
}

@Deprecated(forRemoval = true, since = "3.17")
public static List<String> argLineValue(Config config) {
String strValue = config.getOptionalValue("quarkus.test.arg-line", String.class)
.orElse(config.getOptionalValue("quarkus.test.argLine", String.class) // legacy value
Expand All @@ -37,17 +38,20 @@ public static List<String> argLineValue(Config config) {
return result;
}

@Deprecated(forRemoval = true, since = "3.17")
public static Map<String, String> env(Config config) {
return ((SmallRyeConfig) config).getOptionalValues("quarkus.test.env", String.class, String.class)
.orElse(Collections.emptyMap());
}

@Deprecated(forRemoval = true, since = "3.17")
public static Duration waitTimeValue(Config config) {
return config.getOptionalValue("quarkus.test.wait-time", Duration.class)
.orElseGet(() -> config.getOptionalValue("quarkus.test.jar-wait-time", Duration.class) // legacy value
.orElseGet(() -> Duration.ofSeconds(DEFAULT_WAIT_TIME_SECONDS)));
}

@Deprecated(forRemoval = true, since = "3.17")
public static String integrationTestProfile(Config config) {
return config.getOptionalValue("quarkus.test.integration-test-profile", String.class)
.orElseGet(() -> config.getOptionalValue("quarkus.test.native-image-profile", String.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import jakarta.inject.Inject;

import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.jandex.Index;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand All @@ -49,7 +49,6 @@
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.logging.LoggingSetupRecorder;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.PathTestHelper;
import io.quarkus.test.common.TestClassIndexer;
import io.quarkus.test.common.TestResourceManager;
Expand Down Expand Up @@ -276,9 +275,8 @@ public void accept(String s, String s2) {
} catch (Exception e) {
// use the network the use has specified or else just generate one if none is configured

Config config = LauncherUtil.installAndGetSomeConfig();
Optional<String> networkIdOpt = config
.getOptionalValue("quarkus.test.container.network", String.class);
Optional<String> networkIdOpt = ConfigProvider.getConfig().getOptionalValue("quarkus.test.container.network",
String.class);
if (networkIdOpt.isPresent()) {
networkId = networkIdOpt.get();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.File;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -31,7 +30,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
Expand All @@ -44,11 +43,11 @@

import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.logging.InitialConfigurator;
import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.runtime.logging.JBossVersion;
import io.quarkus.runtime.test.TestHttpEndpointProvider;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.DevServicesContext;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.PropertyTestUtil;
import io.quarkus.test.common.RestAssuredURLManager;
import io.quarkus.test.common.RunCommandLauncher;
Expand All @@ -58,6 +57,7 @@
import io.quarkus.test.common.TestScopeManager;
import io.quarkus.test.junit.callback.QuarkusTestMethodContext;
import io.quarkus.test.junit.launcher.ArtifactLauncherProvider;
import io.smallrye.config.SmallRyeConfig;

public class QuarkusIntegrationTestExtension extends AbstractQuarkusTestWithContextExtension
implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeEachCallback, AfterEachCallback,
Expand Down Expand Up @@ -193,10 +193,10 @@ private QuarkusTestExtensionState doProcessStart(Properties quarkusArtifactPrope

String artifactType = getArtifactType(quarkusArtifactProperties);

Config config = LauncherUtil.installAndGetSomeConfig();
String testProfile = TestConfigUtil.integrationTestProfile(config);
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
TestConfig testConfig = config.getConfigMapping(TestConfig.class);
boolean isDockerLaunch = isContainer(artifactType)
|| (isJar(artifactType) && "test-with-native-agent".equals(testProfile));
|| (isJar(artifactType) && "test-with-native-agent".equals(testConfig.integrationTestProfile()));

ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult = handleDevServices(context,
isDockerLaunch);
Expand Down Expand Up @@ -269,20 +269,19 @@ public void close() throws Throwable {
});
additionalProperties.putAll(resourceManagerProps);

ArtifactLauncher<?> launcher = null;
ArtifactLauncher<?> launcher;
String testHost = System.getProperty("quarkus.http.test-host");
if ((testHost != null) && !testHost.isEmpty()) {
launcher = new TestHostLauncher();
} else {
Duration waitDuration = TestConfigUtil.waitTimeValue(config);
String target = TestConfigUtil.runTarget(config);
// try to execute a run command published by an extension if it exists. We do this so that extensions that have a custom run don't have to create any special artifact type
launcher = RunCommandLauncher.tryLauncher(devServicesLaunchResult.getCuratedApplication().getQuarkusBootstrap(),
target, waitDuration);
target, testConfig.waitTime());
if (launcher == null) {
ServiceLoader<ArtifactLauncherProvider> loader = ServiceLoader.load(ArtifactLauncherProvider.class);
for (ArtifactLauncherProvider launcherProvider : loader) {
if (launcherProvider.supportsArtifactType(artifactType, testProfile)) {
if (launcherProvider.supportsArtifactType(artifactType, testConfig.integrationTestProfile())) {
launcher = launcherProvider.create(
new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context,
requiredTestClass,
Expand Down Expand Up @@ -378,7 +377,7 @@ private void throwBootFailureException() {

private boolean isCallbacksEnabledForIntegrationTests() {
return Optional.ofNullable(System.getProperty(ENABLED_CALLBACKS_PROPERTY)).map(Boolean::parseBoolean)
.or(() -> LauncherUtil.installAndGetSomeConfig().getOptionalValue(ENABLED_CALLBACKS_PROPERTY, Boolean.class))
.or(() -> ConfigProvider.getConfig().getOptionalValue(ENABLED_CALLBACKS_PROPERTY, Boolean.class))
.orElse(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Properties;
import java.util.ServiceLoader;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
Expand All @@ -26,16 +26,16 @@
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;

import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.runtime.logging.JBossVersion;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.TestConfigUtil;
import io.quarkus.test.common.TestResourceManager;
import io.quarkus.test.junit.launcher.ArtifactLauncherProvider;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
import io.quarkus.test.junit.main.QuarkusMainLauncher;
import io.quarkus.test.junit.util.CloseAdaptor;
import io.smallrye.config.SmallRyeConfig;

public class QuarkusMainIntegrationTestExtension extends AbstractQuarkusTestWithContextExtension
implements BeforeEachCallback, AfterEachCallback, ParameterResolver {
Expand Down Expand Up @@ -157,13 +157,13 @@ private ArtifactLauncher.LaunchResult doProcessStart(ExtensionContext context, S

testResourceManager.inject(context.getRequiredTestInstance());

Config config = LauncherUtil.installAndGetSomeConfig();
String testProfile = TestConfigUtil.integrationTestProfile(config);
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
TestConfig testConfig = config.getConfigMapping(TestConfig.class);

ArtifactLauncher<?> launcher = null;
ServiceLoader<ArtifactLauncherProvider> loader = ServiceLoader.load(ArtifactLauncherProvider.class);
for (ArtifactLauncherProvider launcherProvider : loader) {
if (launcherProvider.supportsArtifactType(artifactType, testProfile)) {
if (launcherProvider.supportsArtifactType(artifactType, testConfig.integrationTestProfile())) {
launcher = launcherProvider.create(
new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context, requiredTestClass,
devServicesLaunchResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import java.util.OptionalInt;
import java.util.ServiceLoader;

import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.deployment.images.ContainerImages;
import io.quarkus.deployment.util.FileUtil;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.DefaultDockerContainerLauncher;
import io.quarkus.test.common.DockerContainerArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.TestConfigUtil;
import io.smallrye.config.SmallRyeConfig;

public class DockerContainerLauncherProvider implements ArtifactLauncherProvider {
Expand All @@ -38,6 +39,7 @@ public DockerContainerArtifactLauncher create(CreateContext context) {
String containerImage = context.quarkusArtifactProperties().getProperty("metadata.container-image");
boolean pullRequired = Boolean
.parseBoolean(context.quarkusArtifactProperties().getProperty("metadata.pull-required", "false"));
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
if ((containerImage != null) && !containerImage.isEmpty()) {
DockerContainerArtifactLauncher launcher;
ServiceLoader<DockerContainerArtifactLauncher> loader = ServiceLoader.load(DockerContainerArtifactLauncher.class);
Expand All @@ -47,7 +49,6 @@ public DockerContainerArtifactLauncher create(CreateContext context) {
} else {
launcher = new DefaultDockerContainerLauncher();
}
SmallRyeConfig config = (SmallRyeConfig) LauncherUtil.installAndGetSomeConfig();
launcherInit(context, launcher, config, containerImage, pullRequired, Optional.empty(), volumeMounts(config),
Collections.emptyList());
return launcher;
Expand All @@ -59,10 +60,8 @@ public DockerContainerArtifactLauncher create(CreateContext context) {
// adding a volume mapping pointing to the build output directory,
// and then instructing the java process to run the run jar,
// along with the native image agent arguments and any other additional parameters.
SmallRyeConfig config = (SmallRyeConfig) LauncherUtil.installAndGetSomeConfig();
String testProfile = TestConfigUtil.integrationTestProfile(config);

if ("test-with-native-agent".equals(testProfile)) {
TestConfig testConfig = config.getConfigMapping(TestConfig.class);
if ("test-with-native-agent".equals(testConfig.integrationTestProfile())) {
DockerContainerArtifactLauncher launcher = new DefaultDockerContainerLauncher();
Optional<String> entryPoint = Optional.of("java");
Map<String, String> volumeMounts = new HashMap<>(volumeMounts(config));
Expand All @@ -83,13 +82,14 @@ public DockerContainerArtifactLauncher create(CreateContext context) {
private void launcherInit(CreateContext context, DockerContainerArtifactLauncher launcher, SmallRyeConfig config,
String containerImage, boolean pullRequired, Optional<String> entryPoint, Map<String, String> volumeMounts,
List<String> programArgs) {
TestConfig testConfig = config.getConfigMapping(TestConfig.class);
launcher.init(new DefaultDockerInitContext(
config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT),
config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT),
TestConfigUtil.waitTimeValue(config),
TestConfigUtil.integrationTestProfile(config),
TestConfigUtil.argLineValue(config),
TestConfigUtil.env(config),
testConfig.waitTime(),
testConfig.integrationTestProfile(),
testConfig.argLine().orElse(List.of()),
testConfig.env(),
context.devServicesLaunchResult(),
containerImage,
pullRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import java.util.OptionalInt;
import java.util.ServiceLoader;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.DefaultJarLauncher;
import io.quarkus.test.common.JarArtifactLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.TestConfigUtil;
import io.smallrye.config.SmallRyeConfig;

public class JarLauncherProvider implements ArtifactLauncherProvider {

Expand All @@ -40,14 +40,15 @@ public JarArtifactLauncher create(CreateContext context) {
launcher = new DefaultJarLauncher();
}

Config config = LauncherUtil.installAndGetSomeConfig();
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
TestConfig testConfig = config.getConfigMapping(TestConfig.class);
launcher.init(new DefaultJarInitContext(
config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT),
config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT),
TestConfigUtil.waitTimeValue(config),
TestConfigUtil.integrationTestProfile(config),
TestConfigUtil.argLineValue(config),
TestConfigUtil.env(config),
testConfig.waitTime(),
testConfig.integrationTestProfile(),
testConfig.argLine().orElse(List.of()),
testConfig.env(),
context.devServicesLaunchResult(),
context.buildOutputDirectory().resolve(pathStr)));
return launcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import java.util.OptionalInt;
import java.util.ServiceLoader;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.DefaultNativeImageLauncher;
import io.quarkus.test.common.LauncherUtil;
import io.quarkus.test.common.NativeImageLauncher;
import io.quarkus.test.common.TestConfigUtil;
import io.smallrye.config.SmallRyeConfig;

public class NativeImageLauncherProvider implements ArtifactLauncherProvider {
@Override
Expand All @@ -38,14 +38,15 @@ public NativeImageLauncher create(CreateContext context) {
launcher = new DefaultNativeImageLauncher();
}

Config config = LauncherUtil.installAndGetSomeConfig();
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
TestConfig testConfig = config.getConfigMapping(TestConfig.class);
launcher.init(new NativeImageLauncherProvider.DefaultNativeImageInitContext(
config.getValue("quarkus.http.test-port", OptionalInt.class).orElse(DEFAULT_PORT),
config.getValue("quarkus.http.test-ssl-port", OptionalInt.class).orElse(DEFAULT_HTTPS_PORT),
TestConfigUtil.waitTimeValue(config),
TestConfigUtil.integrationTestProfile(config),
TestConfigUtil.argLineValue(config),
TestConfigUtil.env(config),
testConfig.waitTime(),
testConfig.nativeImageProfile(),
testConfig.argLine().orElse(List.of()),
testConfig.env(),
context.devServicesLaunchResult(),
System.getProperty("native.image.path"),
config.getOptionalValue("quarkus.package.output-directory", String.class).orElse(null),
Expand Down

0 comments on commit b235baa

Please sign in to comment.