KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > session > SessionTestCase


1 /**
2  * SessionTestServerServiceTestCase.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis WSDL2Java emitter.
6  */

7 package test.wsdl.session;
8
9 /**
10  * Class SessionTestCase
11  */

12 public class SessionTestCase extends junit.framework.TestCase {
13
14     /**
15      * Constructor SessionTestCase
16      * @param name
17      */

18     public SessionTestCase(java.lang.String JavaDoc name) {
19         super(name);
20     }
21
22     /**
23      * Method test1SessionTestDoSomething
24      */

25     public void test1SessionTestDoSomething() {
26         // Threads array
27
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 JavaDoc 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 JavaDoc 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     /**
55      * Class SessionTest
56      */

57     public class SessionTest extends Thread JavaDoc {
58         /**
59          * run the thread until done.
60          */

61         public void run() {
62             try {
63                 // Create an instance of the Web service interface.
64
SessionTestServerServiceLocator wsloc =
65                         new SessionTestServerServiceLocator();
66                 SessionTestServer ws = wsloc.getSessionTest();
67
68                 // Maintain sessions for test calls.
69
((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 JavaDoc e) {
82                 e.printStackTrace();
83             }
84             // checkout
85
synchronized (lock) {
86                 count--;
87                 lock.notifyAll();
88             }
89         }
90     }
91
92     /** Field lock */
93     private static Object JavaDoc lock = new Object JavaDoc();
94
95     /** Field testLock */
96     private static Object JavaDoc testLock = new Object JavaDoc();
97
98     /** Field NO_OF_THREADS */
99     private static final int NO_OF_THREADS = 3;
100
101     /** Field NO_OF_CALLS */
102     private static final int NO_OF_CALLS = 6;
103
104     /** Field numThreads */
105     private static int numThreads = NO_OF_THREADS;
106
107     /** Field count */
108     private static int count = NO_OF_THREADS;
109
110     /** Field failed */
111     private static int failed = 0;
112
113     /** Field succeeded */
114     private static int succeeded = 0;
115
116     /**
117      * Main entry point for the application.
118      * Takes number of threads as argument.
119      *
120      * @param args
121      *
122      * @throws Exception
123      */

124     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
125         numThreads = count = Integer.parseInt(args[0]);
126         SessionTestCase testCase = new SessionTestCase("SessionTestCase");
127         testCase.test1SessionTestDoSomething();
128     }
129 }
130
Popular Tags