Commit 7a3ff2d0 authored by Lubomir Bulej's avatar Lubomir Bulej

Job: return self from start() method.

Runner: added utility method for watching a file.
ClientServerRunner: detect DiSL server readiness, speeding up test execution.
ClientServerEvaluationServer: detect DiSL and Shadow VM server readiness, speeding up test execution.
parent b5e9627f
......@@ -44,12 +44,20 @@ public class ClientServerEvaluationRunner extends Runner {
serverErrNull = true;
}
private Job __startServer (final File testInstJar) throws IOException {
private Job __startServer (
final File testInstJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, testInstJar)
);
if (statusFile != null) {
command.add (String.format (
"-Dserver.status.file=%s", statusFile
));
}
command.addAll (propertiesStartingWith ("dislserver."));
command.addAll (propertiesStartingWith ("disl."));
command.add (_DISL_SERVER_CLASS_.getName ());
......@@ -62,12 +70,20 @@ public class ClientServerEvaluationRunner extends Runner {
}
private Job __startShadow (final File testInstJar) throws IOException {
private Job __startShadow (
final File testInstJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_, "-Xms1G", "-Xmx2G",
"-classpath", Runner.classPath (_SHVM_SERVER_JAR_, testInstJar)
);
if (statusFile != null) {
command.add (String.format (
"-Dserver.status.file=%s", statusFile
));
}
command.addAll (propertiesStartingWith ("dislreserver."));
command.add (_SHVM_SERVER_CLASS_.getName ());
......@@ -108,15 +124,26 @@ public class ClientServerEvaluationRunner extends Runner {
protected void _start (
final File testInstJar, final File testAppJar
) throws IOException {
__server = __startServer (testInstJar);
__shadow = __startShadow (testInstJar);
final File serverFile = File.createTempFile ("disl-", ".status");
serverFile.deleteOnExit ();
_INIT_TIME_LIMIT_.sleepUninterruptibly ();
__server = __startServer (testInstJar, serverFile);
watchFile (serverFile, _INIT_TIME_LIMIT_);
if (! __server.isRunning ()) {
throw new IOException ("server failed: "+ __server.getError ());
}
//
final File shadowFile = File.createTempFile ("shvm-", ".status");
shadowFile.deleteOnExit ();
__shadow = __startShadow (testInstJar, shadowFile);
watchFile (shadowFile, _INIT_TIME_LIMIT_);
if (! __shadow.isRunning ()) {
throw new IOException ("shadow failed: "+ __shadow.getError ());
}
......
......@@ -41,9 +41,12 @@ public class ClientServerRunner extends Runner {
protected void _start (
final File testInstJar, final File testAppJar
) throws IOException {
__server = __startServer (testInstJar);
final File serverFile = File.createTempFile ("disl-", ".status");
serverFile.deleteOnExit ();
_INIT_TIME_LIMIT_.sleepUninterruptibly ();
__server = __startServer (testInstJar, serverFile);
watchFile (serverFile, _INIT_TIME_LIMIT_);
if (! __server.isRunning ()) {
throw new IOException ("server failed: "+ __server.getError ());
......@@ -73,27 +76,31 @@ public class ClientServerRunner extends Runner {
//
final Job result = new Job (command);
result.start ();
return result;
return new Job (command).start ();
}
private Job __startServer (final File testInstJar) throws IOException {
private Job __startServer (
final File testInstJar, final File statusFile
) throws IOException {
final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, testInstJar)
);
if (statusFile != null) {
command.add (String.format (
"-Dserver.status.file=%s", statusFile
));
}
command.addAll (propertiesStartingWith ("dislserver."));
command.addAll (propertiesStartingWith ("disl."));
command.add (_DISL_SERVER_CLASS_.getName ());
//
final Job result = new Job (command);
result.start ();
return result;
return new Job (command).start ();
}
......
......@@ -74,7 +74,7 @@ final class Job {
* @throws IOException
* if a problem occurs while trying to execute the job command
*/
public void start () throws IOException {
public Job start () throws IOException {
__ensureJobNotStarted();
//
......@@ -127,6 +127,7 @@ final class Job {
});
__waiter.start ();
return this;
}
......
......@@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import ch.usi.dag.dislreserver.DiSLREServer;
import ch.usi.dag.dislserver.DiSLServer;
......@@ -18,6 +19,7 @@ public abstract class Runner {
protected static final Duration _INIT_TIME_LIMIT_ = Duration.of (3, SECONDS);
protected static final Duration _TEST_TIME_LIMIT_ = Duration.of (60, SECONDS);
protected static final Duration _WATCH_DELAY_ = Duration.of (100, TimeUnit.MILLISECONDS);
protected static final String _ENV_JAVA_HOME_ = "JAVA_HOME";
protected static final String _JAVA_COMMAND_ = __getJavaCommand ();
......@@ -207,4 +209,14 @@ public abstract class Runner {
return Strings.join (File.pathSeparator, (Object []) paths);
}
static boolean watchFile (final File file, final Duration duration) {
final long watchEnd = System.nanoTime () + duration.to (TimeUnit.NANOSECONDS);
while (file.exists () && System.nanoTime () < watchEnd) {
_WATCH_DELAY_.sleepUninterruptibly ();
}
return file.exists ();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment