KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > stests > bank > A_bank


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_bank.java,v 1.6 2004/01/30 14:22:00 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

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

95     public void ope(int action, int accmin, int accmax, int loops, int threads, int amount, boolean verify) throws Exception JavaDoc {
96
97         // Set transaction timeout in the server (global value!)
98
stopTxAt(20);
99
100         // Create and start all threads
101
A_thread[] t_thr = new A_thread[threads];
102         for (int i = 0; i < threads; i++) {
103             t_thr[i] = new A_thread(getManagerHomeName(), i, ictx, action, accmin, accmax, loops, amount, getPrefetch());
104             t_thr[i].start();
105         }
106
107         // Wait end of all threads
108
for (int p = 0; p < threads; p++) {
109             t_thr[p].join();
110         }
111
112         // Check if all threads run ok
113
if (threadfail) {
114             fail("Error in a thread");
115         }
116         if (verify && !manager.checkAll()) {
117             threadfail = true; // to reinit the database
118
fail("Bad global state");
119         }
120     }
121
122     public void testBasicRead() throws Exception JavaDoc {
123         ope(OP_READ, 0, 9, 1, 1, 10, false);
124     }
125
126     public void testPrefetch() throws Exception JavaDoc {
127         ope(OP_READ, 0, 9, 50, 8);
128     }
129
130     public void testDeadlock() throws Exception JavaDoc {
131         ope(OP_MOVETO, 3, 5, 1, 2, 20);
132     }
133
134     public void testSameAccount() throws Exception JavaDoc {
135         ope(OP_MOVETO, 2, 2, 10, 1, 10);
136     }
137
138     public void testMultiSameAccount() throws Exception JavaDoc {
139         ope(OP_MOVETO, 6, 6, 1, 10, 10);
140     }
141
142     public void testBasicReadTx() throws Exception JavaDoc {
143         ope(OP_READTX, 0, 9, 1, 1, 10, false);
144     }
145
146     public void testLongRead() throws Exception JavaDoc {
147         ope(OP_READ, 0, 9, 100, 1);
148     }
149
150     public void testLongReadTx() throws Exception JavaDoc {
151         ope(OP_READTX, 0, 9, 100, 1);
152     }
153
154     public void testMultiRead() throws Exception JavaDoc {
155         ope(OP_READ, 0, 9, 1, 10);
156     }
157
158     public void testMultiReadTx() throws Exception JavaDoc {
159         ope(OP_READTX, 0, 9, 1, 10);
160     }
161
162
163     public void testMultiShortReadTx() throws Exception JavaDoc {
164         ope(OP_READTX, 0, 9, 10, 10);
165     }
166
167     public void testMultiOneMove() throws Exception JavaDoc {
168         ope(OP_ONEMOVE, 0, 5, 1, 20);
169     }
170
171     public void testTh3OneMoveTx() throws Exception JavaDoc {
172         ope(OP_ONEMOVETX, 0, 5, 100, 3);
173     }
174
175     public void testTh5OneMoveTx() throws Exception JavaDoc {
176         ope(OP_ONEMOVETX, 0, 5, 100, 5);
177     }
178
179     public void testTh7OneMoveTx() throws Exception JavaDoc {
180         ope(OP_ONEMOVETX, 0, 5, 100, 7);
181     }
182
183     public void testMultiOneMoveTx() throws Exception JavaDoc {
184         ope(OP_ONEMOVETX, 0, 5, 1, 20);
185     }
186
187     /**
188      * This test is also used for perf measures
189      * => DO NOT CHANGE ARG VALUES
190      */

191     public void testMultiLongRead() throws Exception JavaDoc {
192         ope(OP_READ, 0, 9, 200, 12);
193     }
194
195     /**
196      * This test is also used for perf measures
197      * => DO NOT CHANGE ARG VALUES
198      */

199     public void testMultiLongReadTx() throws Exception JavaDoc {
200         ope(OP_READTX, 0, 19, 200, 12, 1);
201     }
202
203     /**
204      * This test is also used for perf measures
205      * => DO NOT CHANGE ARG VALUES
206      */

207     public void testMultiLongOneMove() throws Exception JavaDoc {
208         ope(OP_ONEMOVE, 0, 19, 200, 12, 1);
209     }
210
211     /**
212      * This test is also used for perf measures
213      * => DO NOT CHANGE ARG VALUES
214      */

215     public void testMultiLongOneMoveTx() throws Exception JavaDoc {
216         ope(OP_ONEMOVETX, 0, 19, 200, 12, 1);
217     }
218
219 }
220
Popular Tags