Commit f491addf authored by Lubomir Bulej's avatar Lubomir Bulej
Browse files

src-test: deduplicated and regularized the runner classes.

parent dca02fb2
......@@ -377,9 +377,11 @@
<junit haltonfailure="no" haltonerror="no" failureproperty="junit.failure">
<classpath refid="classpath" />
<formatter type="brief" usefile="false" />
<!-- allow properties starting with "-Ddisl." to be passed to tests -->
<!-- allow "disl.", "dislserver.", and "dislreserver." properties to be passed to tests -->
<syspropertyset>
<propertyref prefix="disl" />
<propertyref prefix="disl." />
<propertyref prefix="dislserver." />
<propertyref prefix="dislreserver." />
</syspropertyset>
<batchtest fork="yes">
<fileset dir="${src.test}">
......
......@@ -25,7 +25,7 @@ public class DispatchTest {
r.destroyIfRunningAndFlushOutputs ();
}
r.assertIsSuccessful ();
r.assertEvaluationOut ("evaluation.out.resource");
r.assertShadowOut ("evaluation.out.resource");
r.assertRestOutErrNull ();
}
......
......@@ -26,7 +26,7 @@ public class Dispatch2Test {
}
r.assertIsSuccessful ();
r.assertClientOut ("client.out.resource");
r.assertEvaluationOut ("evaluation.out.resource");
r.assertShadowOut ("evaluation.out.resource");
r.assertRestOutErrNull ();
}
......
......@@ -26,7 +26,7 @@ public class DispatchMPTest {
}
r.assertIsSuccessful ();
r.assertClientOut ("client.out.resource");
r.assertEvaluationOut ("evaluation.out.resource");
r.assertShadowOut ("evaluation.out.resource");
r.assertRestOutErrNull ();
}
......
......@@ -3,373 +3,269 @@ package ch.usi.dag.disl.test.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
public class ClientServerEvaluationRunner {
public class ClientServerEvaluationRunner extends Runner {
private final int WAIT_FOR_INIT_MS = 3000;
private Job __client;
private final int WAIT_FOR_TEST_MS = 60000;
private Job __server;
private final Class <?> c;
private Job client;
private Job server;
private Job evaluation;
private Job __shadow;
private boolean clientOutNull;
private boolean clientErrNull;
private boolean evaluationOutNull;
private boolean shadowOutNull;
private boolean evaluationErrNull;
private boolean shadowErrNull;
private boolean serverOutNull;
private boolean serverErrNull;
public ClientServerEvaluationRunner (final Class <?> c) {
this.c = c;
public ClientServerEvaluationRunner (final Class <?> testClass) {
super (testClass);
clientOutNull = true;
clientErrNull = true;
evaluationOutNull = true;
evaluationErrNull = true;
shadowOutNull = true;
shadowErrNull = true;
serverOutNull = true;
serverErrNull = true;
}
private Job __startServer (final File testInstrJar) throws IOException {
final List <String> serverCommand = newLinkedList (
_JAVA_COMMAND_,
"-cp", makeClassPath (testInstrJar, _DISL_SERVER_JAR_)
);
private String getTestName () {
final String [] packages = this.c.getPackage ().getName ().split ("\\.");
return packages [packages.length - 2];
}
serverCommand.addAll (propertiesStartingWith ("dislserver."));
serverCommand.add (_DISL_SERVER_MAIN_CLASS_.getName ());
//
private void startServer (final String test, final String instrJar)
throws IOException {
final String serverJar = "build/disl-server.jar";
final String serverClass = "ch.usi.dag.dislserver.DiSLServer";
/**
* -cp ${INSTR_LIB}:${DISL_LIB_P}/disl-server.jar \
* ch.usi.dag.dislserver.DiSLServer \ "$@" &
*/
final String [] serverCmd = new String [] {
"java",
"-cp", instrJar + ":" + serverJar,
serverClass
};
server = new Job (serverCmd);
server.execute ();
final Job result = new Job (serverCommand);
result.start ();
return result;
}
private void startEvaluation (final String test, final String instrJar)
throws IOException {
final String evaluationJar = "build/dislre-server.jar";
final String evaluationClass = "ch.usi.dag.dislreserver.DiSLREServer";
/**
* ${JAVA_HOME:+$JAVA_HOME/jre/bin/}java \ -Xms1G -Xmx2G \ -cp
* ${INSTR_LIB}:${DISL_LIB_P}/dislre-server.jar \
* ch.usi.dag.dislreserver.DiSLREServer \ "$@" &
*/
final String [] evaluationCmd = new String [] {
"java",
"-Xms1G", "-Xmx2G",
"-cp", instrJar + ":" + evaluationJar,
evaluationClass
};
evaluation = new Job (evaluationCmd);
evaluation.execute ();
private Job __startShadow (final File testInstrJar) throws IOException {
final List <String> shadowCommand = newLinkedList (
_JAVA_COMMAND_, "-Xms1G", "-Xmx2G",
"-cp", makeClassPath (testInstrJar, _DISL_RE_SERVER_JAR_)
);
shadowCommand.addAll (propertiesStartingWith ("dislreserver."));
shadowCommand.add (_DISL_RE_SERVER_MAIN_CLASS_.getName ());
//
final Job result = new Job (shadowCommand);
result.start ();
return result;
}
private void startClient (final String test, final String instrJar)
throws IOException {
final String cagentLib = "build/libdislagent.so";
final String eagentLib = "build/libdislreagent.so";
final String jagentJar = "build/disl-agent.jar";
final String dispatchJar = "build/dislre-dispatch.jar";
final String xboot = "-Xbootclasspath/a:"
+ jagentJar + ":" + instrJar + ":" + dispatchJar;
/**
* ${JAVA_HOME:+$JAVA_HOME/jre/bin/}java \ -agentpath:${C_AGENT}
* -agentpath:${RE_AGENT} \ -javaagent:${DISL_LIB_P}/disl-agent.jar \
* -Xbootclasspath
* /a:${DISL_LIB_P}/disl-agent.jar:${INSTR_LIB}:${DISL_LIB_P
* }/dislre-dispatch.jar \ "$@"
*/
final String [] clientCmd = new String [] {
"java",
"-agentpath:" + cagentLib,
"-agentpath:" + eagentLib,
"-javaagent:" + jagentJar,
xboot,
"-jar", "build-test/disl-app-" + test + ".jar"
};
client = new Job (clientCmd);
client.execute ();
private Job __startClient (
final File testInstrJar, final File testAppJar
) throws IOException {
final List <String> clientCommand = newLinkedList (
_JAVA_COMMAND_,
String.format ("-agentpath:%s", _DISL_AGENT_LIB_),
String.format ("-agentpath:%s", _DISL_RE_AGENT_LIB_),
String.format ("-javaagent:%s", _DISL_AGENT_JAR_),
String.format ("-Xbootclasspath/a:%s", makeClassPath (
_DISL_AGENT_JAR_, testInstrJar, _DISL_RE_DISPATCH_JAR_
))
);
clientCommand.addAll (propertiesStartingWith ("disl."));
clientCommand.addAll (Arrays.asList (
"-jar", testAppJar.toString ()
));
//
final Job result = new Job (clientCommand);
result.start ();
return result;
}
public void start ()
throws IOException {
final String test = getTestName ();
final String instrJar = "build-test/disl-instr-" + test + ".jar";
@Override
protected void _start (
final File testInstrJar, final File testAppJar
) throws IOException {
__server = __startServer (testInstrJar);
__shadow = __startShadow (testInstrJar);
startServer (test, instrJar);
startEvaluation (test, instrJar);
_INIT_TIME_LIMIT_.softSleep ();
try {
Thread.sleep (WAIT_FOR_INIT_MS);
} catch (final InterruptedException e) {
Thread.interrupted ();
if (! __server.isRunning ()) {
throw new IOException ("server failed: "+ __server.getError ());
}
startClient (test, instrJar);
}
if (! __shadow.isRunning ()) {
throw new IOException ("shadow failed: "+ __shadow.getError ());
}
//
private boolean waitFor (final long milliseconds) {
boolean finished = true;
finished = finished & client.waitFor (milliseconds);
finished = finished & evaluation.waitFor (milliseconds);
finished = finished & server.waitFor (milliseconds);
return finished;
__client = __startClient (testInstrJar, testAppJar);
}
public boolean waitFor () {
return waitFor (WAIT_FOR_TEST_MS);
@Override
protected boolean _waitFor (final Duration duration) {
boolean finished = true;
finished = finished & __client.waitFor (duration);
finished = finished & __server.waitFor (duration);
finished = finished & __shadow.waitFor (duration);
return finished;
}
public void assertIsStarted () {
assertTrue ("client not started", client.isStarted ());
assertTrue ("evaluation not started", evaluation.isStarted ());
assertTrue ("server not started", server.isStarted ());
assertTrue ("client not started", __client.isStarted ());
assertTrue ("server not started", __server.isStarted ());
assertTrue ("shadow not started", __shadow.isStarted ());
}
public void assertIsFinished () {
assertTrue ("client not finished", client.isFinished ());
assertTrue ("evaluation not finished", evaluation.isFinished ());
assertTrue ("server not finished", server.isFinished ());
assertTrue ("client not finished", __client.isFinished ());
assertTrue ("server not finished", __server.isFinished ());
assertTrue ("shadow not finished", __shadow.isFinished ());
}
public void assertIsSuccessful () {
assertTrue ("client not successful", client.isSuccessful ());
assertTrue ("evaluation not successful", evaluation.isSuccessful ());
assertTrue ("server not successful", server.isSuccessful ());
assertTrue ("client failed", __client.isSuccessful ());
assertTrue ("server failed", __server.isSuccessful ());
assertTrue ("shadow failed", __shadow.isSuccessful ());
}
private void writeFile (final String filename, final String str)
throws FileNotFoundException {
PrintWriter out = null;
try {
out = new PrintWriter (filename);
out.print (str);
}
finally {
if(out != null) {
out.close ();
}
}
}
public void destroyIfRunningAndFlushOutputs ()
throws FileNotFoundException, IOException {
if (client != null) {
if (client.isRunning ()) {
client.destroy ();
}
if (!client.isRunning ()) {
writeFile (
String.format ("tmp.%s.client.out.txt", getTestName ()),
client.getOutput ());
}
if (!client.isRunning ()) {
writeFile (
String.format ("tmp.%s.client.err.txt", getTestName ()),
client.getError ());
}
}
if (evaluation != null) {
if (evaluation.isRunning ()) {
evaluation.destroy ();
}
if (!evaluation.isRunning ()) {
writeFile (
String.format ("tmp.%s.evaluation.out.txt", getTestName ()),
evaluation.getOutput ());
}
if (!evaluation.isRunning ()) {
writeFile (
String.format ("tmp.%s.evaluation.err.txt", getTestName ()),
evaluation.getError ());
}
}
if (server != null) {
if (server.isRunning ()) {
server.destroy ();
}
if (!server.isRunning ()) {
writeFile (
String.format ("tmp.%s.server.out.txt", getTestName ()),
server.getOutput ());
}
if (!server.isRunning ()) {
writeFile (
String.format ("tmp.%s.server.err.txt", getTestName ()),
server.getError ());
}
}
public void destroyIfRunningAndFlushOutputs () throws IOException {
_destroyIfRunningAndDumpOutputs (__client, "client");
_destroyIfRunningAndDumpOutputs (__server, "server");
_destroyIfRunningAndDumpOutputs (__shadow, "shadow");
}
private String getResource (final String filename)
throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader (
new InputStreamReader (this.c.getResourceAsStream (filename), "UTF-8"));
final StringBuffer buffer = new StringBuffer ();
for (int c = reader.read (); c != -1; c = reader.read ()) {
buffer.append ((char) c);
}
return buffer.toString ();
} finally {
if(reader != null) {
reader.close ();
}
}
}
public void assertClientOut (final String filename)
throws IOException {
public void assertClientOut (final String fileName) throws IOException {
clientOutNull = false;
assertEquals (
"client out does not match", getResource (filename), client.getOutput ());
"client out does not match",
_readResource (fileName), __client.getOutput ()
);
}
public void assertClientOutNull ()
throws IOException {
public void assertClientOutNull () throws IOException {
clientOutNull = false;
assertEquals ("client out does not match", "", client.getOutput ());
assertEquals ("client out does not match", "", __client.getOutput ());
}
public void assertClientErr (final String filename)
throws IOException {
public void assertClientErr (final String fileName) throws IOException {
clientErrNull = false;
assertEquals (
"client err does not match", getResource (filename), client.getError ());
"client err does not match",
_readResource (fileName), __client.getError ()
);
}
public void assertClientErrNull ()
throws IOException {
public void assertClientErrNull () throws IOException {
clientErrNull = false;
assertEquals ("client err does not match", "", client.getError ());
assertEquals ("client err does not match", "", __client.getError ());
}
public void assertEvaluationOut (final String filename)
throws IOException {
evaluationOutNull = false;
public void assertShadowOut (final String fileName) throws IOException {
shadowOutNull = false;
assertEquals (
"evaluation out does not match", getResource (filename),
evaluation.getOutput ());
"shadow out does not match",
_readResource (fileName), __shadow.getOutput ()
);
}
public void assertEvaluationOutNull ()
throws IOException {
evaluationOutNull = false;
assertEquals ("evaluation out does not match", "", evaluation.getOutput ());
public void assertShadowOutNull () throws IOException {
shadowOutNull = false;
assertEquals ("shadow out does not match", "", __shadow.getOutput ());
}
public void assertEvaluationErr (final String filename)
throws IOException {
evaluationErrNull = false;
public void assertShadowErr (final String fileName) throws IOException {
shadowErrNull = false;
assertEquals (
"evaluation err does not match", getResource (filename),
evaluation.getError ());
"shadow err does not match",
_readResource (fileName), __shadow.getError ()
);
}
public void assertEvaluationrErrNull ()
throws IOException {
evaluationErrNull = false;
assertEquals ("evaluation err does not match", "", evaluation.getError ());
public void assertShadowErrNull () throws IOException {
shadowErrNull = false;
assertEquals ("shadow err does not match", "", __shadow.getError ());
}
public void assertServerOut (final String filename)
throws IOException {
public void assertServerOut (final String fileName) throws IOException {
serverOutNull = false;
assertEquals (
"server out does not match", getResource (filename), server.getOutput ());
"server out does not match",
_readResource (fileName), __server.getOutput ()
);
}
public void assertServerOutNull ()
throws IOException {
serverOutNull = false;
assertEquals ("server out does not match", "", server.getOutput ());
assertEquals ("server out does not match", "", __server.getOutput ());
}
public void assertServerErr (final String filename)
throws IOException {
public void assertServerErr (final String fileName) throws IOException {
serverErrNull = false;
assertEquals (
"server err does not match", getResource (filename), server.getError ());
"server err does not match",
_readResource (fileName), __server.getError ()
);
}
public void assertServerErrNull ()
throws IOException {
public void assertServerErrNull () throws IOException {
serverErrNull = false;
assertEquals ("server err does not match", "", server.getError ());
assertEquals ("server err does not match", "", __server.getError ());
}
public void assertRestOutErrNull ()
throws IOException {
public void assertRestOutErrNull () throws IOException {
if (clientOutNull) {
assertClientOutNull ();
}
if (clientErrNull) {
assertClientErrNull ();
}
if (evaluationOutNull) {
if (shadowOutNull) {
assertClientOutNull ();
}
if (evaluationErrNull) {
if (shadowErrNull) {
assertClientErrNull ();
}
......@@ -382,34 +278,15 @@ public class ClientServerEvaluationRunner {
}
public void verbose ()
throws IOException {
System.out.println ("client-out:");
System.out.println (client.getOutput ());
System.out.println ("client-err:");
System.out.println (client.getError ());
System.out.println ("evaluation-out:");
System.out.println (evaluation.getOutput ());
System.out.println ("evaluation-err:");
System.out.println (evaluation.getError ());
System.out.println ("server-out:");
System.out.println (server.getOutput ());
System.out.println ("server-err:");
System.out.println (server.getError ());
}
public void destroy () {
if (client != null) {