OpenJDK / portola / portola
changeset 42010:13940eebb34f
8165500: TestJpsJar shouldn't jar all test.classpath directories
Summary: Refactor test to better handle errors
Reviewed-by: sspitsyn
author | dsamersoff |
---|---|
date | Tue, 25 Oct 2016 14:49:48 +0300 |
parents | 86b8dcbbe5a4 |
children | 94bbcefde876 e63749e2c454 |
files | test/lib/jdk/test/lib/apps/LingeredApp.java |
diffstat | 1 files changed, 47 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/test/lib/jdk/test/lib/apps/LingeredApp.java Mon Oct 24 09:12:40 2016 +0200 +++ b/test/lib/jdk/test/lib/apps/LingeredApp.java Tue Oct 25 14:49:48 2016 +0300 @@ -67,13 +67,14 @@ public class LingeredApp { private static final long spinDelay = 1000; - private static final int appWaitTime = 100; - private final String lockFileName; private long lockCreationTime; - private Process appProcess; private final ArrayList<String> storedAppOutput; + protected Process appProcess; + protected static final int appWaitTime = 100; + protected final String lockFileName; + /* * Drain child process output, store it into string array */ @@ -255,14 +256,10 @@ } /** - * Run the app - * - * @param vmArguments - * @throws IOException + * Analyze an environment and prepare a command line to + * run the app, app name should be added explicitly */ - public void runApp(List<String> vmArguments) - throws IOException { - + public List<String> runAppPrepare(List<String> vmArguments) { // We should always use testjava or throw an exception, // so we can't use JDKToolFinder.getJDKTool("java"); // that falls back to compile java on error @@ -303,28 +300,52 @@ String classpath = System.getProperty("test.class.path"); cmd.add((classpath == null) ? "." : classpath); - cmd.add(this.getAppName()); - cmd.add(lockFileName); + return cmd; + } - // Reporting + /** + * Assemble command line to a printable string + */ + public void printCommandLine(List<String> cmd) { + // A bit of verbosity StringBuilder cmdLine = new StringBuilder(); for (String strCmd : cmd) { cmdLine.append("'").append(strCmd).append("' "); } - // A bit of verbosity System.out.println("Command line: [" + cmdLine.toString() + "]"); + } + + public void startGobblerPipe() { + // Create pipe reader for process, and read stdin and stderr to array of strings + InputGobbler gb = new InputGobbler(appProcess.getInputStream(), storedAppOutput); + gb.start(); + } + + /** + * Run the app. + * + * @param vmArguments + * @throws IOException + */ + public void runApp(List<String> vmArguments) + throws IOException { + + List<String> cmd = runAppPrepare(vmArguments); + + cmd.add(this.getAppName()); + cmd.add(lockFileName); + + printCommandLine(cmd); ProcessBuilder pb = new ProcessBuilder(cmd); // we don't expect any error output but make sure we are not stuck on pipe // pb.redirectErrorStream(false); + // ProcessBuilder.start can throw IOException pb.redirectError(ProcessBuilder.Redirect.INHERIT); - appProcess = pb.start(); - // Create pipe reader for process, and read stdin and stderr to array of strings - InputGobbler gb = new InputGobbler(appProcess.getInputStream(), storedAppOutput); - gb.start(); + startGobblerPipe(); } /** @@ -334,10 +355,14 @@ */ public void stopApp() throws IOException { deleteLock(); - waitAppTerminate(); - int exitcode = appProcess.exitValue(); - if (exitcode != 0) { - throw new IOException("LingeredApp terminated with non-zero exit code " + exitcode); + // The startApp() of the derived app can throw + // an exception before the LA actually starts + if (appProcess != null) { + waitAppTerminate(); + int exitcode = appProcess.exitValue(); + if (exitcode != 0) { + throw new IOException("LingeredApp terminated with non-zero exit code " + exitcode); + } } }