Skip to content

Commit

Permalink
[WFCORE-5917] Add test case and allow it to be executed in dash shell
Browse files Browse the repository at this point in the history
  • Loading branch information
yersan committed Jan 25, 2024
1 parent a9ac274 commit 7c5135d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ fi
# clean server opts
for var in $SERVER_OPTS
do
if [ "${var//"-Djboss.server.base.dir"/}" != "${var}" ]; then
SERVER_OPTS="${SERVER_OPTS//$var/}"
v=`echo "${var}" | sed 's/-Djboss.server.base.dir//g'`
if [ "${v}" != "${var}" ]; then
SERVER_OPTS=`echo "${SERVER_OPTS}" | sed "s|${var}||g"`
fi
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ public boolean isAlive() {
return delegate.isAlive();
}

@Override
public ProcessHandle toHandle() {
checkStatus();
return delegate.toHandle();
}

@Override
public String toString() {
return getCommandString(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.stream.Collectors;

import jakarta.json.JsonObject;

Expand Down Expand Up @@ -88,11 +92,46 @@ void testScript(final ScriptProcess script) throws InterruptedException, Timeout
// seem to work when a directory has a space. An error indicating the trailing quote cannot be found. Removing
// the `\ parts and just keeping quotes ends in the error shown in JDK-8215398.
Assume.assumeFalse(TestSuiteEnvironment.isWindows() && env.containsKey("GC_LOG") && script.getScript().toString().contains(" "));
script.start(STANDALONE_CHECK, env, ServerHelper.DEFAULT_SERVER_JAVA_OPTS);

// Test WFCORE-5917 by adding the jboss.server.base.dir argument
// Due to WFCORE-6684, skip this verification if there are whitespaces in the home directory
if (!script.getContainerHome().toString().contains(" ")) {
List<String> args = new ArrayList<>(Arrays.asList(ServerHelper.DEFAULT_SERVER_JAVA_OPTS));
Path sbdPath = script.getContainerHome().resolve("standalone");
args.add("-Djboss.server.base.dir=" + sbdPath);
script.start(STANDALONE_CHECK, env, args.toArray(String[]::new));
} else {
script.start(STANDALONE_CHECK, env, ServerHelper.DEFAULT_SERVER_JAVA_OPTS);
}

Assert.assertNotNull("The process is null and may have failed to start.", script);
Assert.assertTrue("The process is not running and should be", script.isAlive());

// test WFCORE-5917
if (!script.getContainerHome().toString().contains(" ")) {
ProcessHandle handle = script.toHandle();
List<ProcessHandle> children = handle.children().collect(Collectors.toList());
Assert.assertEquals("The standalone process should have started one single process.", 1, children.size());
ProcessHandle serverProcess = children.get(0);
Optional<String> commandLine = serverProcess.info().commandLine();
Assert.assertFalse("Server process launch command is not available", commandLine.isEmpty());
String[] serverArgs = commandLine.get().split("\\s+");
int occurrences = 0;
for (int i = 0; i < serverArgs.length; i++) {
if ( !serverArgs[i].contains("-Djboss.server.base.dir=") ) {
continue;
}
occurrences++;
for (int j = i+1; j <serverArgs.length; j++) {
if (serverArgs[i].equals(serverArgs[j])){
occurrences++;
break;
}
}
}
Assert.assertEquals("Found duplicate server jboss.server.base.dir argument in the server launch command. Launch command is " + commandLine.get(), 1, occurrences);
}

if (env.containsKey("MODULE_OPTS")) {
final List<JsonObject> lines = ServerHelper.readLogFileFromModel("json.log");
Assert.assertEquals("Expected 2 lines found " + lines.size(), 2, lines.size());
Expand Down

0 comments on commit 7c5135d

Please sign in to comment.