KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > stests > manac > A_read


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: A_read.java,v 1.1 2003/09/15 13:18:27 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.stests.manac;
27
28 import javax.rmi.PortableRemoteObject JavaDoc;
29 import org.objectweb.jonas.stests.util.JTestCase;
30
31 /**
32  * This test suite tests read operations in a multithreading environment.
33  */

34 public abstract class A_read extends JTestCase {
35
36     static final int initialValue = 1000;
37     protected static ManagerHome home = null;
38     protected static Manager manager = null;
39
40     int accounts = 100;
41     int loops = 1;
42     int threads = 1;
43
44     public static boolean threadfail;
45
46     public A_read(String JavaDoc name) {
47         super(name);
48     }
49
50     public abstract String JavaDoc getManagerHomeName();
51
52     protected void setUp() throws Exception JavaDoc {
53         super.setUp();
54         if (home == null) {
55             useBeans("manac");
56             home = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(getManagerHomeName()),
57                                                              ManagerHome.class);
58         }
59         if (manager == null) {
60             manager = home.create(initialValue);
61         }
62         // Initializes the test by creating 20 accounts
63
manager.createAll(20);
64         threadfail = false;
65     }
66
67     protected void tearDown() throws Exception JavaDoc {
68         super.tearDown();
69     }
70
71     /**
72      * Run a multithreaded client test. Common part to all test cases.
73      */

74     public void readac(int accounts, int loops, int threads) throws Exception JavaDoc {
75
76         // Create and start all threads
77
A_readthread[] t_thr = new A_readthread[threads];
78         for (int i = 0; i < threads; i++) {
79             t_thr[i] = new A_readthread(getManagerHomeName(), i, ictx, accounts, loops);
80             t_thr[i].start();
81         }
82
83         // Wait end of all threads
84
for (int p = 0; p < threads; p++) {
85             t_thr[p].join();
86         }
87
88         // Check if all threads run ok
89
if (threadfail) {
90             fail("Error in a thread");
91         }
92     }
93
94     public void testBasic() throws Exception JavaDoc {
95         readac(accounts, loops, threads);
96     }
97
98     public void testConc() throws Exception JavaDoc {
99         int accounts = 10;
100         int threads = 12;
101         int loops = 4;
102         readac(accounts, loops, threads);
103     }
104
105     public void testConcL() throws Exception JavaDoc {
106         int accounts = 5;
107         int threads = 12;
108         int loops = 50;
109         readac(accounts, loops, threads);
110     }
111
112     public void testL100() throws Exception JavaDoc {
113         int loops = 100;
114         readac(accounts, loops, threads);
115     }
116
117     public void testL50T2() throws Exception JavaDoc {
118         int loops = 50;
119         int threads = 2;
120         readac(accounts, loops, threads);
121     }
122
123     public void testL20T5() throws Exception JavaDoc {
124         int loops = 20;
125         int threads = 5;
126         readac(accounts, loops, threads);
127     }
128
129     public void testL10T8() throws Exception JavaDoc {
130         int accounts = 1000;
131         int loops = 10;
132         int threads = 8;
133         readac(accounts, loops, threads);
134     }
135
136 }
137
Popular Tags