Java Reference
In-Depth Information
Note There should also be a bonus directory in the root directory named src - examples . This has not
previously been described anywhere in the topic, but it contains sample code for many of the topics dis-
cussed in the topic that are not part of the project itself.
Figure 9-12. Tree structure for the development project so far
The test package contains our multithreaded test harness. Testing your application with
multiple clients is a must. We will use our test harness to simulate a group of users all vying
voraciously for database access.
In the test package are two classes. One called DBTester , which extends Thread and simu-
lates the client that attempts to rent and return DVDs. The other, called DBTestRunner , it
spawns multiple DBTester test threads, waits for them to finish running, and then reports on
their success (or failure).
Since the test package is in a different directory structure from our standard source, we
must compile it separately. To do this, we can change into the test directory and run the fol-
lowing command:
javac -cp ..\classes -d ..\classes sampleproject\test\*.java
Listing 9-1 shows the test client code. Unlike the real application, we have chosen to
directly connect to the RMI DvdConnector or the sockets DvdConnector just to show how this
could be done. To simplify the connection code, we have commented out one of the two net-
work connector import statements.
Listing 9-1. DBTester.java
package sampleproject.test;
import sampleproject.db.*;
import java.util.Date;
Search WWH ::




Custom Search