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_read.java 3287 2003-09-15 13:18:27Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.stests.manac;
027:
028: import javax.rmi.PortableRemoteObject;
029: import org.objectweb.jonas.stests.util.JTestCase;
030:
031: /**
032: * This test suite tests read operations in a multithreading environment.
033: */
034: public abstract class A_read extends JTestCase {
035:
036: static final int initialValue = 1000;
037: protected static ManagerHome home = null;
038: protected static Manager manager = null;
039:
040: int accounts = 100;
041: int loops = 1;
042: int threads = 1;
043:
044: public static boolean threadfail;
045:
046: public A_read(String name) {
047: super (name);
048: }
049:
050: public abstract String getManagerHomeName();
051:
052: protected void setUp() throws Exception {
053: super .setUp();
054: if (home == null) {
055: useBeans("manac");
056: home = (ManagerHome) PortableRemoteObject.narrow(ictx
057: .lookup(getManagerHomeName()), ManagerHome.class);
058: }
059: if (manager == null) {
060: manager = home.create(initialValue);
061: }
062: // Initializes the test by creating 20 accounts
063: manager.createAll(20);
064: threadfail = false;
065: }
066:
067: protected void tearDown() throws Exception {
068: super .tearDown();
069: }
070:
071: /**
072: * Run a multithreaded client test. Common part to all test cases.
073: */
074: public void readac(int accounts, int loops, int threads)
075: throws Exception {
076:
077: // Create and start all threads
078: A_readthread[] t_thr = new A_readthread[threads];
079: for (int i = 0; i < threads; i++) {
080: t_thr[i] = new A_readthread(getManagerHomeName(), i, ictx,
081: accounts, loops);
082: t_thr[i].start();
083: }
084:
085: // Wait end of all threads
086: for (int p = 0; p < threads; p++) {
087: t_thr[p].join();
088: }
089:
090: // Check if all threads run ok
091: if (threadfail) {
092: fail("Error in a thread");
093: }
094: }
095:
096: public void testBasic() throws Exception {
097: readac(accounts, loops, threads);
098: }
099:
100: public void testConc() throws Exception {
101: int accounts = 10;
102: int threads = 12;
103: int loops = 4;
104: readac(accounts, loops, threads);
105: }
106:
107: public void testConcL() throws Exception {
108: int accounts = 5;
109: int threads = 12;
110: int loops = 50;
111: readac(accounts, loops, threads);
112: }
113:
114: public void testL100() throws Exception {
115: int loops = 100;
116: readac(accounts, loops, threads);
117: }
118:
119: public void testL50T2() throws Exception {
120: int loops = 50;
121: int threads = 2;
122: readac(accounts, loops, threads);
123: }
124:
125: public void testL20T5() throws Exception {
126: int loops = 20;
127: int threads = 5;
128: readac(accounts, loops, threads);
129: }
130:
131: public void testL10T8() throws Exception {
132: int accounts = 1000;
133: int loops = 10;
134: int threads = 8;
135: readac(accounts, loops, threads);
136: }
137:
138: }
|