Skip to content

Instantly share code, notes, and snippets.

@rgrig
Created April 9, 2012 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrig/2345296 to your computer and use it in GitHub Desktop.
Save rgrig/2345296 to your computer and use it in GitHub Desktop.
class Benchmark {
public final boolean run() {
if (++iteration == 1) prepare();
if (validateOutput) {
System.setOut(out); // this is where System.out is redefined
out.openLog();
}
try { iterate(); }
finally {
if (validateOutput) {
out.closeLog(); // this sets out.log to null
out.setOut(savedOut);
}
}
}
TeeOutputStream out; // really a TeePritnStream that just forwards to a TeeOutputStream
protected int iteration = 0;
abstract public void prepare();
abstract public void cleanup();
abstract public void iterate();
}
class Tomcat extends Benchmark {
public Tomcat() { controller = new Control(); }
public void prepare() { controller.prepare(); } // starts the server thread
public void cleanup() { controller.cleanup(); } // stops the server thread
public void iterate() {
controller.startIteration(); // tell server (using a http request) to start the webapp "examples"
// ... start client threads, wait until they finish ...
controller.stopIteration(); // tell the server (using a http request) to stop serving the webapp "examples"
}
}
class TeeOutputStream {
private OutputStream log = null;
public void closeLog() { log = null; } // ... plus other stuff
public void write(int b) {
if (log != null) log.write(b);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment