File: SessionTestCase.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (129 lines) | stat: -rw-r--r-- 3,728 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * SessionTestServerServiceTestCase.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis WSDL2Java emitter.
 */
package test.wsdl.session;

/**
 * Class SessionTestCase
 */
public class SessionTestCase extends junit.framework.TestCase {

    /**
     * Constructor SessionTestCase
     * @param name
     */
    public SessionTestCase(java.lang.String name) {
        super(name);
    }

    /**
     * Method test1SessionTestDoSomething
     */
    public void test1SessionTestDoSomething() {
        // Threads array
        SessionTest[] clients = new SessionTest[numThreads];

        for (int i = 0; i < numThreads; i++) {
            clients[i] = new SessionTest();
        }
        for (int j = 0; j < numThreads; j++) {
            clients[j].start();
            try {
                Thread.currentThread().sleep(150);
            } catch (InterruptedException e) {
                System.out.println("Threads interrupted");
            }
        }
        try {
            synchronized (lock) {
                while (count != 0) {
                    lock.wait();
                }
            }
        } catch (InterruptedException ie) {
            System.out.println("Threads interrupted");
        }
        System.out.println("Succeeded " + succeeded + " times.");
        System.out.println("Failed " + failed + " times.");
        assertTrue("found session failures", (failed == 0));
    }

    /**
     * Class SessionTest
     */
    public class SessionTest extends Thread {
        /**
         * run the thread until done.
         */
        public void run() {
            try {
                // Create an instance of the Web service interface.
                SessionTestServerServiceLocator wsloc =
                        new SessionTestServerServiceLocator();
                SessionTestServer ws = wsloc.getSessionTest();

                // Maintain sessions for test calls.
                ((org.apache.axis.client.Stub) ws).setMaintainSession(true);
                for (int i = 0; i < NO_OF_CALLS; i++) {
                    if (ws.doSomething() == false) {
                        synchronized (testLock) {
                            failed++;
                        }
                    } else {
                        synchronized (testLock) {
                            succeeded++;
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            // checkout
            synchronized (lock) {
                count--;
                lock.notifyAll();
            }
        }
    }

    /** Field lock           */
    private static Object lock = new Object();

    /** Field testLock           */
    private static Object testLock = new Object();

    /** Field NO_OF_THREADS           */
    private static final int NO_OF_THREADS = 3;

    /** Field NO_OF_CALLS           */
    private static final int NO_OF_CALLS = 6;

    /** Field numThreads           */
    private static int numThreads = NO_OF_THREADS;

    /** Field count           */
    private static int count = NO_OF_THREADS;

    /** Field failed           */
    private static int failed = 0;

    /** Field succeeded           */
    private static int succeeded = 0;

    /**
     * Main entry point for the application.
     * Takes number of threads as argument.
     *
     * @param args
     *
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        numThreads = count = Integer.parseInt(args[0]);
        SessionTestCase testCase = new SessionTestCase("SessionTestCase");
        testCase.test1SessionTestDoSomething();
    }
}