1 package org.jgroups.tests; 2 3 import java.io.InputStream ; 4 import java.net.HttpURLConnection ; 5 import java.net.URL ; 6 7 13 public class StressTester implements Runnable 14 { 15 private URL url; 16 private String name; 17 18 StressTester(URL url, String name) 19 { 20 this.url = url; 21 this.name = name; 22 } 23 24 public void run() 25 { 26 System.out.println(name + " starting"); 27 28 String cookie = null; 29 int count = 0; 30 while (true) 31 { 32 count++; 33 34 try 35 { 36 HttpURLConnection conn = (HttpURLConnection ) url.openConnection(); 37 if (cookie != null) 38 conn.addRequestProperty("Cookie", cookie); 39 conn.connect(); 40 41 int rc = conn.getResponseCode(); 42 43 if (cookie == null) 44 { 45 String header = conn.getHeaderField("Set-Cookie"); 46 if (header != null) 47 { 48 int semi = header.indexOf(';'); 49 if (semi > 0) 50 { 51 cookie = header.substring(0, semi); 52 } 53 else 54 { 55 cookie = header; 56 } 57 } 58 } 59 InputStream is = conn.getInputStream(); 60 while (is.read() != -1) { 61 ; 62 } 63 is.close(); 64 65 if (rc != 200 || count % 1000 == 0) 66 { 67 StringBuffer sb = new StringBuffer (name); 68 sb.append('-'); 69 sb.append(count); 70 sb.append('-'); 71 sb.append(rc); 72 sb.append('-'); 73 sb.append(cookie); 74 System.out.println(sb.toString()); 75 } 76 } 77 catch (Exception e) 78 { 79 System.out.println(e.getMessage()); 80 } 81 82 } 83 } 84 85 95 public static void main(String [] args) 96 { 97 try 98 { 99 int threadCount = Integer.parseInt(args[0]); 100 101 int serverCount = args.length - 1; 102 103 URL [] urls = new URL [serverCount]; 104 for (int i = 1; i < args.length; i++) 105 { 106 urls[i -1] = new URL ("http://" + args[i] + "/jbento-httpsession/SetListOfString16"); 107 } 108 109 110 for (int i = 0; i < threadCount; i++) 111 { 112 StressTester tester = new StressTester(urls[i % serverCount], "Thread"+i); 113 Thread t = new Thread (tester); 114 t.start(); 115 } 116 } 117 catch (Exception e) 118 { 119 e.printStackTrace(); 120 } 121 } 122 123 } 124 | Popular Tags |