From 7db065b2fcb3007aa8c2fc88844049b31c8e1bfa Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Wed, 29 May 2024 11:09:10 +0100 Subject: [PATCH 1/2] [WFCORE-4919] Add a timeout parameter starting the embedded Server/Host Controller from ModelParserUtils Jira issue: https://issues.redhat.com/browse/WFCORE-4919 --- .../java/org/jboss/as/test/shared/ModelParserUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java b/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java index e3962dd6394..c45aa2ae24e 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java @@ -31,6 +31,8 @@ * @author Emmanuel Hugonnet (c) 2014 Red Hat, inc. */ public class ModelParserUtils { + // Timeout for the embedded Server / Host Controller to fully start, in seconds. + private final static long EMBEDDED_FULLY_STARTED_TIMEOUT = TimeoutUtil.adjust(5*60); /** * Tests the ability to boot an admin-only server using the given config, persist the config, @@ -51,7 +53,7 @@ public static ModelNode standaloneXmlTest(File originalConfig, File jbossHome) t CLIWrapper cli = new CLIWrapper(false); try { - String line = "embed-server --admin-only=true --server-config=" + originalConfig.getName() + " --std-out=echo --jboss-home=" + jbossHome.getCanonicalPath(); + String line = "embed-server --admin-only=true --server-config=" + originalConfig.getName() + " --std-out=echo --jboss-home=" + jbossHome.getCanonicalPath() + " --timeout=" + EMBEDDED_FULLY_STARTED_TIMEOUT; cli.sendLine(line); assertProcessState(cli, ControlledProcessState.State.RUNNING.toString(), TimeoutUtil.adjust(30000), false); ModelNode firstResult = readResourceTree(cli); @@ -95,7 +97,7 @@ private static ModelNode hostControllerTest(final File originalConfig, final Fil CLIWrapper cli = new CLIWrapper(false); try { String configType = hostXml ? "--host-config=" : "--domain-config="; - String line = "embed-host-controller " + configType + originalConfig.getName() + " --std-out=echo --jboss-home=" + target.getCanonicalPath(); + String line = "embed-host-controller " + configType + originalConfig.getName() + " --std-out=echo --jboss-home=" + target.getCanonicalPath() + " --timeout=" + EMBEDDED_FULLY_STARTED_TIMEOUT; cli.sendLine(line); assertProcessState(cli, ControlledProcessState.State.RUNNING.toString(), TimeoutUtil.adjust(30000), true); ModelNode firstResult = readResourceTree(cli); From b9eaad72042ea5d88f16936423acdc2b43dc8af1 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Wed, 29 May 2024 11:15:28 +0100 Subject: [PATCH 2/2] [WFCORE-4919] Minor formatting fixes, minor improvements for code readbility --- .../as/test/shared/ModelParserUtils.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java b/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java index c45aa2ae24e..c08fcf43df8 100644 --- a/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java +++ b/testsuite/shared/src/main/java/org/jboss/as/test/shared/ModelParserUtils.java @@ -32,7 +32,7 @@ */ public class ModelParserUtils { // Timeout for the embedded Server / Host Controller to fully start, in seconds. - private final static long EMBEDDED_FULLY_STARTED_TIMEOUT = TimeoutUtil.adjust(5*60); + private static final long EMBEDDED_FULLY_STARTED_TIMEOUT = TimeoutUtil.adjust(5*60); /** * Tests the ability to boot an admin-only server using the given config, persist the config, @@ -40,9 +40,9 @@ public class ModelParserUtils { * from the reload. * * @param originalConfig the config file to use - * @param jbossHome directory to use as $JBOSS_HOME + * @param jbossHome directory to use as $JBOSS_HOME * @return the configuration model read after the reload - * @throws Exception + * @throws Exception if an error occurs */ public static ModelNode standaloneXmlTest(File originalConfig, File jbossHome) throws Exception { File serverDir = new File(jbossHome, "standalone"); @@ -80,9 +80,9 @@ public static ModelNode standaloneXmlTest(File originalConfig, File jbossHome) t * from the reload. * * @param originalConfig the config file to use for the host model - * @param jbossHome directory to use as $JBOSS_HOME + * @param jbossHome directory to use as $JBOSS_HOME * @return the host subtree from the configuration model read after the reload - * @throws Exception + * @throws Exception if an error occurs */ public static ModelNode hostXmlTest(final File originalConfig, File jbossHome) throws Exception { return hostControllerTest(originalConfig, jbossHome, true); @@ -140,15 +140,15 @@ private static ModelNode pruneDomainModel(ModelNode model, boolean forHost) { * from the reload. * * @param originalConfig the config file to use for the domain model - * @param jbossHome directory to use as $JBOSS_HOME + * @param jbossHome directory to use as $JBOSS_HOME * @return the configuration model read after the reload, excluding the host subtree - * @throws Exception + * @throws Exception if an error occurs */ public static ModelNode domainXmlTest(File originalConfig, File jbossHome) throws Exception { return hostControllerTest(originalConfig, jbossHome, false); } - private static void assertProcessState(CLIWrapper cli, String expected, int timeout, boolean forHost) throws IOException, InterruptedException { + private static void assertProcessState(CLIWrapper cli, String expected, int timeout, boolean forHost) throws InterruptedException { long done = timeout < 1 ? 0 : System.currentTimeMillis() + timeout; StringBuilder historyBuf = new StringBuilder(); String state = null; @@ -157,8 +157,7 @@ private static void assertProcessState(CLIWrapper cli, String expected, int time state = forHost ? getHostState(cli) : getServerState(cli); historyBuf.append(state).append("\n"); } catch (Exception ignored) { - // - historyBuf.append(ignored.toString()).append("--").append(cli.readOutput()).append("\n"); + historyBuf.append(ignored).append("--").append(cli.readOutput()).append("\n"); } if (expected.equals(state)) { return; @@ -193,7 +192,7 @@ private static String getHostState(CLIWrapper cli) throws IOException { private static ModelNode readResourceTree(CLIWrapper cli) { cli.sendLine("/:read-resource(recursive=true)"); ModelNode response = ModelNode.fromString(cli.readOutput()); - assertTrue(response.toString(), SUCCESS.equals(response.get(OUTCOME).asString())); + assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString()); ModelNode firstResult = response.get(RESULT); assertTrue(response.toString(), firstResult.isDefined()); return firstResult;