1 7 package test.wsdl.session; 8 9 12 public class SessionTestCase extends junit.framework.TestCase { 13 14 18 public SessionTestCase(java.lang.String name) { 19 super(name); 20 } 21 22 25 public void test1SessionTestDoSomething() { 26 SessionTest[] clients = new SessionTest[numThreads]; 28 29 for (int i = 0; i < numThreads; i++) { 30 clients[i] = new SessionTest(); 31 } 32 for (int j = 0; j < numThreads; j++) { 33 clients[j].start(); 34 try { 35 Thread.currentThread().sleep(150); 36 } catch (InterruptedException e) { 37 System.out.println("Threads interrupted"); 38 } 39 } 40 try { 41 synchronized (lock) { 42 while (count != 0) { 43 lock.wait(); 44 } 45 } 46 } catch (InterruptedException ie) { 47 System.out.println("Threads interrupted"); 48 } 49 System.out.println("Succeeded " + succeeded + " times."); 50 System.out.println("Failed " + failed + " times."); 51 assertTrue("found session failures", (failed == 0)); 52 } 53 54 57 public class SessionTest extends Thread { 58 61 public void run() { 62 try { 63 SessionTestServerServiceLocator wsloc = 65 new SessionTestServerServiceLocator(); 66 SessionTestServer ws = wsloc.getSessionTest(); 67 68 ((org.apache.axis.client.Stub) ws).setMaintainSession(true); 70 for (int i = 0; i < NO_OF_CALLS; i++) { 71 if (ws.doSomething() == false) { 72 synchronized (testLock) { 73 failed++; 74 } 75 } else { 76 synchronized (testLock) { 77 succeeded++; 78 } 79 } 80 } 81 } catch (Exception e) { 82 e.printStackTrace(); 83 } 84 synchronized (lock) { 86 count--; 87 lock.notifyAll(); 88 } 89 } 90 } 91 92 93 private static Object lock = new Object (); 94 95 96 private static Object testLock = new Object (); 97 98 99 private static final int NO_OF_THREADS = 3; 100 101 102 private static final int NO_OF_CALLS = 6; 103 104 105 private static int numThreads = NO_OF_THREADS; 106 107 108 private static int count = NO_OF_THREADS; 109 110 111 private static int failed = 0; 112 113 114 private static int succeeded = 0; 115 116 124 public static void main(String [] args) throws Exception { 125 numThreads = count = Integer.parseInt(args[0]); 126 SessionTestCase testCase = new SessionTestCase("SessionTestCase"); 127 testCase.test1SessionTestDoSomething(); 128 } 129 } 130 | Popular Tags |