Methods Summary |
---|
private void | antcall(java.lang.String taskName)Call the selected ant task.
CallTarget callee;
callee = (CallTarget) getProject().createTask("antcall");
callee.setOwningTarget(getOwningTarget());
callee.setTaskName(getTaskName());
callee.setLocation(getLocation());
callee.init();
callee.setTarget(taskName);
callee.execute();
|
private void | callStart(java.lang.String startTarget)Call the start server task
if (startTarget == null) {
return;
}
// Execute the ant target
new Thread(new TaskRunnable(startTarget)).start();
if (! startTarget.equals(tcpServerTarget))
return;
// try a ping for the TCP server
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
}
try {
sendOnSocket("ping\r\n");
// if no exception, return
System.out.println("RunAxisFunctionalTestsTask.callStart successfully pinged server.");
return;
} catch (Exception ex) {
// loop & try again
}
}
// NOTREACHED since the while loop returns if it successfully pings
|
private void | callStop()Call the stop server task
try {
// first, stop the tcp server
if (tcpServerTarget != null) {
sendOnSocket("quit\r\n");
}
// second, and more involvedly, stop the http server
// Try connecting in case the server is already stopped.
if (httpServerTarget != null) {
URL url = new URL("http://localhost:8080/");
try {
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
readFully(connection);
connection.disconnect();
} catch (IOException e) {
// Server is not running. Make this task a no-op.
System.out.println("Error from HTTP read: " + e);
return;
}
}
// Call the target that stops the server
antcall(httpStopTarget);
// Wait a few ms more (just to make sure)
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new BuildException("Interruption during sleep", e);
}
/*
// Continuously try calling the test URL until it fails
while (true) {
System.out.println("Trying localhost:8080...");
try {
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
this.readFully(connection);
connection.disconnect();
} catch (IOException e) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException ee) {
throw new BuildException("Interruption during sleep", ee);
}
}
// Wait a few ms more (just to be sure !)
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new BuildException("Interruption during sleep", e);
}
*/
System.out.println("RunAxisFunctionalTestsTask.callStop successfully sent quit message.");
} catch (Exception ex) {
// ignore; if socket not there, presume dead already
}
|
private void | callTests()Call the run tests target
antcall(testTarget);
|
public void | execute()Executes the task.
try {
callStart(tcpServerTarget);
callStart(httpServerTarget);
callTests();
} finally {
// Make sure we stop the server
callStop();
}
|
static void | readFully(java.net.HttpURLConnection connection)Read all the contents that are to be read
// finish reading it to prevent (harmless) server-side exceptions
BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
byte[] buffer = new byte[256];
while((is.read(buffer)) > 0) {}
is.close();
|
private void | sendOnSocket(java.lang.String str)Make a socket to the url, and send the given string
if (url == null)
return;
Socket sock = null;
try {
sock = new Socket(url.getHost(), url.getPort());
sock.getOutputStream().write(new String(str).getBytes());
// get a single byte response
int i = sock.getInputStream().read();
} catch (Exception ex) {
throw ex;
}/* finally {
if (sock != null) {
try {
sock.close();
} catch (IOException ex) {
// ignore
}
}
}*/
|
public void | setHttpServerTarget(java.lang.String theStartTarget)Sets the target to call to start server 2.
httpServerTarget = theStartTarget;
|
public void | setHttpStopTarget(java.lang.String theStopTarget)Sets the stop target. This is the target which does
a HTTP admin shutdown on the simple server.
httpStopTarget = theStopTarget;
|
public void | setTcpServerTarget(java.lang.String theStartTarget)Sets the target to call to start server 1.
tcpServerTarget = theStartTarget;
|
public void | setTestTarget(java.lang.String theTestTarget)Sets the target to call to run the tests.
testTarget = theTestTarget;
|
public void | setUrl(java.lang.String theUrl)Sets the target URL (just http://host:port)
try {
url = new URL(theUrl);
} catch (MalformedURLException ex) {
System.err.println("Can't make URL from "+theUrl);
}
|