-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6016 from yersan/WFCORE-4919
[WFCORE-4919] Add a timeout parameter starting the embedded Server/Host Controller from ModelParserUtils
- Loading branch information
Showing
1 changed file
with
13 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,16 +31,18 @@ | |
* @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2014 Red Hat, inc. | ||
*/ | ||
public class ModelParserUtils { | ||
// Timeout for the embedded Server / Host Controller to fully start, in seconds. | ||
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, | ||
* reload it, and confirm that the configuration model from the original boot matches the model | ||
* 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"); | ||
|
@@ -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); | ||
|
@@ -78,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); | ||
|
@@ -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); | ||
|
@@ -138,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; | ||
|
@@ -155,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; | ||
|
@@ -191,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; | ||
|