Created
April 9, 2012 18:32
-
-
Save rgrig/2345296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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