Skip to content

Commit

Permalink
Merge b9eaad7 into c8300b3
Browse files Browse the repository at this point in the history
  • Loading branch information
yersan committed May 29, 2024
2 parents c8300b3 + b9eaad7 commit ba8b99e
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
* @author <a href="mailto:ehugonne@redhat.com">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");
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ba8b99e

Please sign in to comment.