001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_bank.java 4125 2004-01-30 14:22:00Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.stests.bank;
027:
028: import javax.rmi.PortableRemoteObject;
029: import org.objectweb.jonas.stests.util.JTestCase;
030:
031: public abstract class A_bank extends JTestCase {
032:
033: protected static final int OP_READ = 1;
034: protected static final int OP_MOVE = 2;
035: protected static final int OP_CREATE = 3;
036: protected static final int OP_REMOVE = 4;
037: protected static final int OP_ONEMOVE = 5;
038: protected static final int OP_READTX = 6;
039: protected static final int OP_ONEMOVETX = 7;
040: protected static final int OP_MOVETO = 8;
041:
042: static final int initialValue = 1000;
043: static final int accountNb = 20;
044:
045: protected static ManagerHome home = null;
046: protected static Manager manager = null;
047: public static boolean threadfail;
048:
049: public A_bank(String name) {
050: super (name);
051: }
052:
053: public abstract String getManagerHomeName();
054:
055: public abstract boolean getPrefetch();
056:
057: protected void setUp() throws Exception {
058: super .setUp();
059: if (home == null) {
060: useBeans("bank");
061: home = (ManagerHome) PortableRemoteObject.narrow(ictx
062: .lookup(getManagerHomeName()), ManagerHome.class);
063: }
064: if (manager == null) {
065: manager = home.create(initialValue, getPrefetch());
066: }
067: // Initializes the test by creating accounts
068: manager.createAll(accountNb);
069: threadfail = false;
070: }
071:
072: protected void tearDown() throws Exception {
073: super .tearDown();
074: if (threadfail && manager != null) {
075: manager.reinitAll();
076: manager.remove();
077: manager = null;
078: }
079: }
080:
081: public void ope(int action, int accmin, int accmax, int loops,
082: int threads) throws Exception {
083: ope(action, accmin, accmax, loops, threads, 10, true);
084: }
085:
086: public void ope(int action, int accmin, int accmax, int loops,
087: int threads, int amount) throws Exception {
088: ope(action, accmin, accmax, loops, threads, amount, true);
089: }
090:
091: /**
092: * generic operation.
093: * @param accmin min range for account nb
094: * @param accmax max range for account nb
095: * @param loops nb of loop in each thread
096: * @param threads nb of threads running the same operations
097: */
098: public void ope(int action, int accmin, int accmax, int loops,
099: int threads, int amount, boolean verify) throws Exception {
100:
101: // Set transaction timeout in the server (global value!)
102: stopTxAt(20);
103:
104: // Create and start all threads
105: A_thread[] t_thr = new A_thread[threads];
106: for (int i = 0; i < threads; i++) {
107: t_thr[i] = new A_thread(getManagerHomeName(), i, ictx,
108: action, accmin, accmax, loops, amount,
109: 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 && !manager.checkAll()) {
123: threadfail = true; // to reinit the database
124: fail("Bad global state");
125: }
126: }
127:
128: public void testBasicRead() throws Exception {
129: ope(OP_READ, 0, 9, 1, 1, 10, false);
130: }
131:
132: public void testPrefetch() throws Exception {
133: ope(OP_READ, 0, 9, 50, 8);
134: }
135:
136: public void testDeadlock() throws Exception {
137: ope(OP_MOVETO, 3, 5, 1, 2, 20);
138: }
139:
140: public void testSameAccount() throws Exception {
141: ope(OP_MOVETO, 2, 2, 10, 1, 10);
142: }
143:
144: public void testMultiSameAccount() throws Exception {
145: ope(OP_MOVETO, 6, 6, 1, 10, 10);
146: }
147:
148: public void testBasicReadTx() throws Exception {
149: ope(OP_READTX, 0, 9, 1, 1, 10, false);
150: }
151:
152: public void testLongRead() throws Exception {
153: ope(OP_READ, 0, 9, 100, 1);
154: }
155:
156: public void testLongReadTx() throws Exception {
157: ope(OP_READTX, 0, 9, 100, 1);
158: }
159:
160: public void testMultiRead() throws Exception {
161: ope(OP_READ, 0, 9, 1, 10);
162: }
163:
164: public void testMultiReadTx() throws Exception {
165: ope(OP_READTX, 0, 9, 1, 10);
166: }
167:
168: public void testMultiShortReadTx() throws Exception {
169: ope(OP_READTX, 0, 9, 10, 10);
170: }
171:
172: public void testMultiOneMove() throws Exception {
173: ope(OP_ONEMOVE, 0, 5, 1, 20);
174: }
175:
176: public void testTh3OneMoveTx() throws Exception {
177: ope(OP_ONEMOVETX, 0, 5, 100, 3);
178: }
179:
180: public void testTh5OneMoveTx() throws Exception {
181: ope(OP_ONEMOVETX, 0, 5, 100, 5);
182: }
183:
184: public void testTh7OneMoveTx() throws Exception {
185: ope(OP_ONEMOVETX, 0, 5, 100, 7);
186: }
187:
188: public void testMultiOneMoveTx() throws Exception {
189: ope(OP_ONEMOVETX, 0, 5, 1, 20);
190: }
191:
192: /**
193: * This test is also used for perf measures
194: * => DO NOT CHANGE ARG VALUES
195: */
196: public void testMultiLongRead() throws Exception {
197: ope(OP_READ, 0, 9, 200, 12);
198: }
199:
200: /**
201: * This test is also used for perf measures
202: * => DO NOT CHANGE ARG VALUES
203: */
204: public void testMultiLongReadTx() throws Exception {
205: ope(OP_READTX, 0, 19, 200, 12, 1);
206: }
207:
208: /**
209: * This test is also used for perf measures
210: * => DO NOT CHANGE ARG VALUES
211: */
212: public void testMultiLongOneMove() throws Exception {
213: ope(OP_ONEMOVE, 0, 19, 200, 12, 1);
214: }
215:
216: /**
217: * This test is also used for perf measures
218: * => DO NOT CHANGE ARG VALUES
219: */
220: public void testMultiLongOneMoveTx() throws Exception {
221: ope(OP_ONEMOVETX, 0, 19, 200, 12, 1);
222: }
223:
224: }
|