001: package org.jgroups.tests;
002:
003: import java.io.InputStream;
004: import java.net.HttpURLConnection;
005: import java.net.URL;
006:
007: /**
008: * Test driver for testing JGroups-based HttpSession replication.
009: *
010: * @author Brian Stansberry
011: * @version $Id: StressTester.java,v 1.4 2006/09/07 18:35:29 belaban Exp $
012: */
013: public class StressTester implements Runnable {
014: private URL url;
015: private String name;
016:
017: StressTester(URL url, String name) {
018: this .url = url;
019: this .name = name;
020: }
021:
022: public void run() {
023: System.out.println(name + " starting");
024:
025: String cookie = null;
026: int count = 0;
027: while (true) {
028: count++;
029:
030: try {
031: HttpURLConnection conn = (HttpURLConnection) url
032: .openConnection();
033: if (cookie != null)
034: conn.addRequestProperty("Cookie", cookie);
035: conn.connect();
036:
037: int rc = conn.getResponseCode();
038:
039: if (cookie == null) {
040: String header = conn.getHeaderField("Set-Cookie");
041: if (header != null) {
042: int semi = header.indexOf(';');
043: if (semi > 0) {
044: cookie = header.substring(0, semi);
045: } else {
046: cookie = header;
047: }
048: }
049: }
050: InputStream is = conn.getInputStream();
051: while (is.read() != -1) {
052: ;
053: }
054: is.close();
055:
056: if (rc != 200 || count % 1000 == 0) {
057: StringBuffer sb = new StringBuffer(name);
058: sb.append('-');
059: sb.append(count);
060: sb.append('-');
061: sb.append(rc);
062: sb.append('-');
063: sb.append(cookie);
064: System.out.println(sb.toString());
065: }
066: } catch (Exception e) {
067: System.out.println(e.getMessage());
068: }
069:
070: }
071: }
072:
073: /**
074: * Args are:
075: *
076: * 0) # of client threads to create
077: * 1) hostname:port of node 0; e.g 192.168.1.164:8080
078: * 2) hostname:port of node 1
079: * x) and so on for as many servers as there are
080: *
081: * @param args
082: */
083: public static void main(String[] args) {
084: try {
085: int threadCount = Integer.parseInt(args[0]);
086:
087: int serverCount = args.length - 1;
088:
089: URL[] urls = new URL[serverCount];
090: for (int i = 1; i < args.length; i++) {
091: urls[i - 1] = new URL("http://" + args[i]
092: + "/jbento-httpsession/SetListOfString16");
093: }
094:
095: for (int i = 0; i < threadCount; i++) {
096: StressTester tester = new StressTester(urls[i
097: % serverCount], "Thread" + i);
098: Thread t = new Thread(tester);
099: t.start();
100: }
101: } catch (Exception e) {
102: e.printStackTrace();
103: }
104: }
105:
106: }
|