Java Reference
In-Depth Information
When the client has finished running, the test harness will want to know how many suc-
cessful and unsuccessful bookings were made. So we have a number of getters to provide that
information.
public int getSuccessfulRentals() {
return successfulRentals;
}
public int getOutOfStock() {
return outOfStock;
}
public int getTimeouts() {
return timeouts;
}
Finally, we want to display information on what is happening while the test is running;
however, we do not want to use the standard logger as it can make the resultant screen output
hard to decipher. In a larger test environment we would probably consider creating our own
log Formatter , but this is overkill for this chapter, so we have opted to create a pretend logger
instead. This provides a very simple logging facility, and if we later decided to change to using
the JDK's logger, we would only need to change the definition of our log variable.
private class PretendLogger {
void info(String logInformation) {
System.out.format("%tT %s%n", new Date(), logInformation);
}
}
}
The test harness code is very simple—all it needs to do is to create multiple clients, run
them, wait until they have finished, and then display some statistics. The code for this is dis-
played in Listing 9-2.
Listing 9-2. DBTestRunner
package sampleproject.test;
import java.util.Calendar;
public class DBTestRunner {
private int numberOfClients = 4; // how many test clients we will start
private int rentalsPerClient = 2; // number of rentals each client will make
private String dvdUpc = "32725349302"; // the DVD they will rent
private DBTester[] clients = null; // an array of the test clients
Search WWH ::




Custom Search