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 { ...@@ -44,12 +44,20 @@ public class ClientServerEvaluationRunner extends Runner {
serverErrNull = true; 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 ( final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_, _JAVA_COMMAND_,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, testInstJar) "-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 ("dislserver."));
command.addAll (propertiesStartingWith ("disl.")); command.addAll (propertiesStartingWith ("disl."));
command.add (_DISL_SERVER_CLASS_.getName ()); command.add (_DISL_SERVER_CLASS_.getName ());
...@@ -62,12 +70,20 @@ public class ClientServerEvaluationRunner extends Runner { ...@@ -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 ( final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_, "-Xms1G", "-Xmx2G", _JAVA_COMMAND_, "-Xms1G", "-Xmx2G",
"-classpath", Runner.classPath (_SHVM_SERVER_JAR_, testInstJar) "-classpath", Runner.classPath (_SHVM_SERVER_JAR_, testInstJar)
); );
if (statusFile != null) {
command.add (String.format (
"-Dserver.status.file=%s", statusFile
));
}
command.addAll (propertiesStartingWith ("dislreserver.")); command.addAll (propertiesStartingWith ("dislreserver."));
command.add (_SHVM_SERVER_CLASS_.getName ()); command.add (_SHVM_SERVER_CLASS_.getName ());
...@@ -108,15 +124,26 @@ public class ClientServerEvaluationRunner extends Runner { ...@@ -108,15 +124,26 @@ public class ClientServerEvaluationRunner extends Runner {
protected void _start ( protected void _start (
final File testInstJar, final File testAppJar final File testInstJar, final File testAppJar
) throws IOException { ) throws IOException {
__server = __startServer (testInstJar); final File serverFile = File.createTempFile ("disl-", ".status");
__shadow = __startShadow (testInstJar); serverFile.deleteOnExit ();
_INIT_TIME_LIMIT_.sleepUninterruptibly (); __server = __startServer (testInstJar, serverFile);
watchFile (serverFile, _INIT_TIME_LIMIT_);
if (! __server.isRunning ()) { if (! __server.isRunning ()) {
throw new IOException ("server failed: "+ __server.getError ()); 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 ()) { if (! __shadow.isRunning ()) {
throw new IOException ("shadow failed: "+ __shadow.getError ()); throw new IOException ("shadow failed: "+ __shadow.getError ());
} }
......
...@@ -41,9 +41,12 @@ public class ClientServerRunner extends Runner { ...@@ -41,9 +41,12 @@ public class ClientServerRunner extends Runner {
protected void _start ( protected void _start (
final File testInstJar, final File testAppJar final File testInstJar, final File testAppJar
) throws IOException { ) 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 ()) { if (! __server.isRunning ()) {
throw new IOException ("server failed: "+ __server.getError ()); throw new IOException ("server failed: "+ __server.getError ());
...@@ -73,27 +76,31 @@ public class ClientServerRunner extends Runner { ...@@ -73,27 +76,31 @@ public class ClientServerRunner extends Runner {
// //
final Job result = new Job (command); return new Job (command).start ();
result.start ();
return result;
} }
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 ( final List <String> command = Lists.newLinkedList (
_JAVA_COMMAND_, _JAVA_COMMAND_,
"-classpath", Runner.classPath (_DISL_SERVER_JAR_, testInstJar) "-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 ("dislserver."));
command.addAll (propertiesStartingWith ("disl.")); command.addAll (propertiesStartingWith ("disl."));
command.add (_DISL_SERVER_CLASS_.getName ()); command.add (_DISL_SERVER_CLASS_.getName ());
// //
final Job result = new Job (command); return new Job (command).start ();
result.start ();
return result;
} }
......
...@@ -74,7 +74,7 @@ final class Job { ...@@ -74,7 +74,7 @@ final class Job {
* @throws IOException * @throws IOException
* if a problem occurs while trying to execute the job command * if a problem occurs while trying to execute the job command
*/ */
public void start () throws IOException { public Job start () throws IOException {
__ensureJobNotStarted(); __ensureJobNotStarted();
// //
...@@ -127,6 +127,7 @@ final class Job { ...@@ -127,6 +127,7 @@ final class Job {
}); });
__waiter.start (); __waiter.start ();
return this;
} }
......
...@@ -7,6 +7,7 @@ import java.io.FileNotFoundException; ...@@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import ch.usi.dag.dislreserver.DiSLREServer; import ch.usi.dag.dislreserver.DiSLREServer;
import ch.usi.dag.dislserver.DiSLServer; import ch.usi.dag.dislserver.DiSLServer;
...@@ -18,6 +19,7 @@ public abstract class Runner { ...@@ -18,6 +19,7 @@ public abstract class Runner {
protected static final Duration _INIT_TIME_LIMIT_ = Duration.of (3, SECONDS); 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 _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 _ENV_JAVA_HOME_ = "JAVA_HOME";
protected static final String _JAVA_COMMAND_ = __getJavaCommand (); protected static final String _JAVA_COMMAND_ = __getJavaCommand ();
...@@ -207,4 +209,14 @@ public abstract class Runner { ...@@ -207,4 +209,14 @@ public abstract class Runner {
return Strings.join (File.pathSeparator, (Object []) paths); 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