import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* HttpUnit mechanism to test that the servlet manages to handle
* multiple "simultaneous" requests for the default servlet.
* This mechanism only works when the servlet is running in the
* container and is reachable under
* http://localhost:8080/refentry
* <p>The test is then run by hand. Ideally, it would be integrated
* into an automated framework such as Cactus.
* @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
*/
public class TestThreads extends TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static TestSuite suite() {
return new TestSuite(TestThreads.class);
}
public TestThreads(String str) {
super(str);
}
public void testThreads() throws Exception {
String URL1 = new String(
"http://localhost:8080/refentry?RefEntry="
+ "RefEntry-3");
String URL2 = new String(
"http://localhost:8080/refentry?SrchString="
+ "parent");
String URL3 = new String(
"http://localhost:8080/refentry?SrchString="
+ "garbage+in+garbage+out");
System.out.println("\nTestThreads timing");
System.out.println("------------------");
TestClient[] clients = new TestClient[100];
for (int i = 0; i < 100; i++) {
String url;
if ((i % 3) == 0) url = new String(URL3);
else if ((i % 2) == 0) url = new String(URL2);
else url = new String(URL1);
clients[i] = new TestClient(url, i);
clients[i].start();
}
}
} |