Skip to content

Commit

Permalink
Fix Picocli warns and native execution and startup
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Sep 26, 2024
1 parent 8387845 commit e4831ff
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.qe.picocli;

import static java.util.concurrent.CompletableFuture.runAsync;

import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
Expand All @@ -15,12 +13,10 @@ public class HelloWorldIT {

@QuarkusApplication
static final RestService app = new RestService()
.withProperty("quarkus.args", "helloWorld -n " + NAME)
.setAutoStart(false);
.withProperty("quarkus.args", "helloWorld -n " + NAME);

@Test
public void verifyHelloWorldFormatted() {
runAsync(app::start);
String expectedOutput = String.format("Hello %s!", NAME);
app.logs().assertContains(expectedOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import static io.quarkus.runtime.util.StringUtil.hyphenate;
import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings;
import static io.quarkus.test.utils.AwaitilityUtils.untilIsTrue;
import static io.quarkus.test.utils.TestExecutionProperties.isThisCliApp;
import static io.quarkus.test.utils.TestExecutionProperties.isThisStartedCliApp;
import static io.quarkus.test.utils.TestExecutionProperties.rememberThisAppStarted;
import static io.quarkus.test.utils.TestExecutionProperties.rememberThisCliAppStopped;
import static org.junit.jupiter.api.Assertions.fail;

import java.nio.file.Path;
Expand Down Expand Up @@ -221,6 +225,22 @@ public void start() {
return;
}

// our FW tries to start each auto-started service twice
// I won't dare to change it until I have time to fix issues that I caused, but
// TODO: we should figure out why BaseService:start is called more than once
// once from the io.quarkus.test.bootstrap.QuarkusScenarioBootstrap.launchService
// and once from the io.quarkus.test.bootstrap.QuarkusScenarioBootstrap.beforeEach
// it doesn't matter for normal apps, but CLI app can launch and stop
// so it won't be running on the next "start()"
// so here, I am making sure that we remember the first start
if (isThisStartedCliApp(context)) {
return;
} else {
// we always need to remember this in case during the build we
// recognize this is a CLI app, which happens later
rememberThisAppStarted(context);
}

Log.debug(this, "Starting service (%s)", getDisplayName());
onPreStartActions.forEach(a -> a.handle(this));
doStart();
Expand Down Expand Up @@ -307,6 +327,11 @@ public void init(ManagedResourceBuilder managedResourceBuilder) {
}

public void restart() {
if (isThisCliApp(context)) {
// don't do that on the call to 'stop()'
// it could result in repeated start of the application
rememberThisCliAppStopped(context);
}
managedResource.restart();
}

Expand Down Expand Up @@ -352,6 +377,9 @@ private boolean isRunningOrFailed() {
}

private void waitUntilServiceIsStarted() {
if (isThisCliApp(this.context)) {
return;
}
try {
Duration startupCheckInterval = getConfiguration()
.getAsDuration(SERVICE_STARTUP_CHECK_POLL_INTERVAL, SERVICE_STARTUP_CHECK_POLL_INTERVAL_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.lang3.ArrayUtils;

import io.quarkus.test.configuration.PropertyLookup;
import io.quarkus.test.utils.TestExecutionProperties;

public class ProdLocalhostQuarkusApplicationManagedResource extends LocalhostQuarkusApplicationManagedResource {

Expand Down Expand Up @@ -57,6 +58,7 @@ private String[] extractQuarkusArgs(List<String> systemProperties) {
if (property.contains(QUARKUS_ARGS_PROPERTY_NAME)) {
propertiesIt.remove();
args = property.replace("-D" + QUARKUS_ARGS_PROPERTY_NAME + "=", "").split(" ");
TestExecutionProperties.rememberThisIsCliApp(this.getContext());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.test.utils;

import io.quarkus.test.bootstrap.Service;
import io.quarkus.test.bootstrap.ServiceContext;
import io.quarkus.test.configuration.PropertyLookup;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;

Expand All @@ -14,6 +15,8 @@ public final class TestExecutionProperties {
private static final String DEFAULT_SERVICE_NAME = "quarkus_test_framework";
private static final String DEFAULT_BUILD_NUMBER = "777-default";
private static final TestExecutionProperties INSTANCE = new TestExecutionProperties();
private static final String CLI_APP_PROPERTY_KEY = "ts-internal.is-cli-app";
private static final String APP_STARTED_KEY = "ts-internal.app-started";

private final String serviceName;
private final String buildNumber;
Expand Down Expand Up @@ -56,4 +59,24 @@ public static String getBuildNumber() {
public static boolean useManagementSsl(Service service) {
return service.getProperty(MANAGEMENT_INTERFACE_ENABLED).map(Boolean::parseBoolean).orElse(false);
}

public static void rememberThisIsCliApp(ServiceContext context) {
context.put(CLI_APP_PROPERTY_KEY, Boolean.TRUE.toString());
}

public static boolean isThisCliApp(ServiceContext context) {
return Boolean.parseBoolean(context.get(CLI_APP_PROPERTY_KEY));
}

public static boolean isThisStartedCliApp(ServiceContext context) {
return isThisCliApp(context) && Boolean.parseBoolean(context.get(APP_STARTED_KEY));
}

public static void rememberThisAppStarted(ServiceContext context) {
context.put(APP_STARTED_KEY, Boolean.TRUE.toString());
}

public static void rememberThisCliAppStopped(ServiceContext context) {
context.put(APP_STARTED_KEY, Boolean.FALSE.toString());
}
}

0 comments on commit e4831ff

Please sign in to comment.