KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > distribution > A_bankRead


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_bankRead.java,v 1.2 2005/02/03 12:16:09 coqp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.distribution;
27
28 import javax.rmi.PortableRemoteObject JavaDoc;
29 import org.objectweb.jonas.jtests.beans.bank.Manager;
30 import org.objectweb.jonas.jtests.beans.bank.ManagerHome;
31 import org.objectweb.jonas.jtests.util.JTestCase;
32
33 public abstract class A_bankRead extends JTestCase {
34
35     protected static final int OP_READ = 1;
36     protected static final int OP_MOVE = 2;
37     protected static final int OP_CREATE = 3;
38     protected static final int OP_REMOVE = 4;
39     protected static final int OP_ONEMOVE = 5;
40     protected static final int OP_READTX = 6;
41     protected static final int OP_ONEMOVETX = 7;
42     protected static final int OP_MOVETO = 8;
43
44     static final int initialValue = 1000;
45     static final int accountNb = 20;
46
47     protected static ManagerHome home = null;
48     protected static Manager manager = null;
49     public static boolean threadfail;
50
51     public A_bankRead(String JavaDoc name) {
52         super(name);
53     }
54
55     public abstract String JavaDoc getManagerHomeName();
56     public abstract boolean getPrefetch();
57
58     protected void setUp() {
59         super.setUp();
60         try {
61             if (home == null) {
62                 useBeans("bank", false);
63                 home = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(getManagerHomeName()), ManagerHome.class);
64             }
65             if (manager == null) {
66                 manager = home.create(initialValue, getPrefetch());
67             }
68             // Initializes the test by creating accounts
69
manager.createAll(accountNb);
70             threadfail = false;
71         } catch (Exception JavaDoc e) {
72             fail("Exception raised in setup: " + e);
73         }
74     }
75
76     protected void tearDown() throws Exception JavaDoc {
77         super.tearDown();
78         if (threadfail && manager != null) {
79             manager.reinitAll();
80             manager.remove();
81             manager = null;
82         }
83     }
84     public void ope(int action, int accmin, int accmax, int loops, int threads) throws Exception JavaDoc {
85         ope(action, accmin, accmax, loops, threads, 10, true);
86     }
87
88     public void ope(int action, int accmin, int accmax, int loops, int threads, int amount) throws Exception JavaDoc {
89         ope(action, accmin, accmax, loops, threads, amount, true);
90     }
91
92     /**
93      * generic operation.
94      * @param accmin min range for account nb
95      * @param accmax max range for account nb
96      * @param loops nb of loop in each thread
97      * @param threads nb of threads running the same operations
98      */

99     public void ope(int action, int accmin, int accmax, int loops, int threads, int amount, boolean verify) throws Exception JavaDoc {
100
101         // Set transaction timeout in the server (global value!)
102
if (amount > 10) {
103             stopTxAt(20);
104         }
105
106         // Create and start all threads
107
A_thread[] t_thr = new A_thread[threads];
108         for (int i = 0; i < threads; i++) {
109             t_thr[i] = new A_thread(getManagerHomeName(), i, ictx, action, accmin, accmax, loops, amount, getPrefetch());
110             t_thr[i].start();
111         }
112
113         // Wait end of all threads
114
for (int p = 0; p < threads; p++) {
115             t_thr[p].join();
116         }
117
118         // Check if all threads run ok
119
if (threadfail) {
120             fail("Error in a thread");
121         }
122         if (verify) {
123             stopTxAt(600);
124             if (!manager.checkAll()) {
125                 threadfail = true; // to reinit the database
126
fail("Bad global state");
127             }
128         }
129     }
130
131
132     public void testCheckAll() throws Exception JavaDoc {
133         if (!manager.checkAll()) {
134             fail("Bad state in database");
135         }
136     }
137
138     /**
139      * Operation= read
140      * min range for account nb = 0
141      * max range for account nb = 9
142      * nb of loop in each thread = 1
143      * nb of threads running the same operations = 1
144      * no verification
145      * @throws Exception
146      */

147     public void testBasicRead() throws Exception JavaDoc {
148         ope(OP_READ, 0, 9, 1, 1, 10, false);
149     }
150     
151     /**
152      * Operation= read in transaction
153      * min range for account nb = 0
154      * max range for account nb = 9
155      * nb of loop in each thread = 1
156      * nb of threads running the same operations = 1
157      * no verification
158      * @throws Exception
159      */

160     public void testBasicReadTx() throws Exception JavaDoc {
161         ope(OP_READTX, 0, 9, 1, 1, 10, false);
162     }
163     /**
164      * Operation= read
165      * min range for account nb = 0
166      * max range for account nb = 9
167      * nb of loop in each thread = 10
168      * nb of threads running the same operations = 3
169      * verification of base's state
170      * @throws Exception
171      */

172     public void test3Readers() throws Exception JavaDoc {
173         ope(OP_READ, 0, 9, 10, 3);
174     }
175     
176     /**
177      * Operation= read
178      * min range for account nb = 0
179      * max range for account nb = 9
180      * nb of loop in each thread = 10
181      * nb of threads running the same operations = 4
182      * verification of base's state
183      * @throws Exception
184      */

185     public void test4Readers() throws Exception JavaDoc {
186         ope(OP_READ, 0, 9, 10, 4);
187     }
188     /**
189      * Operation= read
190      * min range for account nb = 0
191      * max range for account nb = 9
192      * nb of loop in each thread = 10
193      * nb of threads running the same operations = 5
194      * verification of base's state
195      * @throws Exception
196      */

197     public void test5Readers() throws Exception JavaDoc {
198         ope(OP_READ, 0, 9, 10, 5);
199     }
200     /**
201      * Operation= read
202      * min range for account nb = 0
203      * max range for account nb = 9
204      * nb of loop in each thread = 10
205      * nb of threads running the same operations = 8
206      * verification of base's state
207      * @throws Exception
208      */

209     public void test8Readers() throws Exception JavaDoc {
210         ope(OP_READ, 0, 9, 10, 8);
211     }
212     
213     /**
214      * Operation= read in transaction
215      * min range for account nb = 0
216      * max range for account nb = 9
217      * nb of loop in each thread = 10
218      * nb of threads running the same operations = 3
219      * verification of base's state
220      * @throws Exception
221      */

222     public void test3ReadersTx() throws Exception JavaDoc {
223         ope(OP_READTX, 0, 9, 10, 3);
224     }
225     /**
226      * Operation= read in transaction
227      * min range for account nb = 0
228      * max range for account nb = 9
229      * nb of loop in each thread = 10
230      * nb of threads running the same operations = 4
231      * verification of base's state
232      * @throws Exception
233      */

234     public void test4ReadersTx() throws Exception JavaDoc {
235         ope(OP_READTX, 0, 9, 10, 4);
236     }
237     /**
238      * Operation= read in transaction
239      * min range for account nb = 0
240      * max range for account nb = 9
241      * nb of loop in each thread = 10
242      * nb of threads running the same operations = 5
243      * verification of base's state
244      * @throws Exception
245      */

246     public void test5ReadersTx() throws Exception JavaDoc {
247         ope(OP_READTX, 0, 9, 10, 5);
248     }
249
250     /**
251      * Operation= read in transaction
252      * min range for account nb = 0
253      * max range for account nb = 9
254      * nb of loop in each thread = 10
255      * nb of threads running the same operations = 8
256      * verification of base's state
257      * @throws Exception
258      */

259     public void test8ReadersTx() throws Exception JavaDoc {
260         ope(OP_READTX, 0, 9, 10, 8);
261     }
262
263     /**
264      * Operation= read outside transaction
265      * min range for account nb = 0
266      * max range for account nb = 9
267      * nb of loop in each thread = 1
268      * nb of threads running the same operations = 10
269      * verification of base's state
270      * @throws Exception
271      */

272
273     public void testMultiRead() throws Exception JavaDoc {
274         ope(OP_READ, 0, 9, 1, 10);
275     }
276     /**
277      * Operation= read inside transaction
278      * min range for account nb = 0
279      * max range for account nb = 9
280      * nb of loop in each thread = 1
281      * nb of threads running the same operations = 10
282      * verification of base's state
283      * @throws Exception
284      */

285
286     public void testMultiReadTx() throws Exception JavaDoc {
287         ope(OP_READTX, 0, 9, 1, 10);
288     }
289
290     /**
291      * Operation= read inside transaction
292      * min range for account nb = 0
293      * max range for account nb = 9
294      * nb of loop in each thread = 10
295      * nb of threads running the same operations = 10
296      * verification of base's state
297      * @throws Exception
298      */

299
300     public void testMultiShortReadTx() throws Exception JavaDoc {
301         ope(OP_READTX, 0, 9, 10, 10);
302     }
303
304 }
305
Popular Tags