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_readthread.java 3287 2003-09-15 13:18:27Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.stests.manac;
027:
028: import java.rmi.RemoteException;
029: import javax.ejb.RemoveException;
030: import javax.naming.Context;
031: import javax.rmi.PortableRemoteObject;
032:
033: /**
034: * Stress Test with read only operations
035: * @author Philippe Durieux
036: */
037: public class A_readthread extends Thread {
038: String managerName;
039: String name;
040: int accounts;
041: int loops;
042: Context ictx;
043:
044: public A_readthread(String mName, int num, Context ictx,
045: int accounts, int loops) {
046: managerName = mName;
047: name = managerName + "_readac_" + num;
048: setName(name);
049: this .ictx = ictx;
050: this .accounts = accounts;
051: this .loops = loops;
052: }
053:
054: /**
055: * random returns an integer between 0 and max - 1
056: */
057: private int random(int max) throws RemoteException {
058: double d = Math.random();
059: int ret = (int) (max * d);
060: return ret;
061: }
062:
063: public void run() {
064:
065: // Create a session bean
066: ManagerHome mgrHome = null;
067: Manager mgr = null;
068: try {
069: mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx
070: .lookup(managerName), ManagerHome.class);
071: mgr = mgrHome.create(F_read.initialValue);
072: } catch (Exception e) {
073: System.out.println("Cannot Create Session:" + e);
074: return;
075: }
076:
077: try {
078:
079: // Choose the 4 accounts randomly
080: int d1 = random(accounts);
081: int d2 = random(accounts);
082: int c1 = random(accounts);
083: int c2 = random(accounts);
084: // Set these accounts in session bean
085: mgr.setAccounts(d1, d2, c1, c2);
086:
087: // main loop
088: boolean ok = true;
089: for (int i = 0; i < loops; i++) {
090: int minval = mgr.readBalances();
091: if (minval < 0) {
092: System.out.println("Bad read value " + minval);
093: F_read.threadfail = true;
094: break;
095: }
096: }
097: // delete Session
098: mgr.remove();
099: } catch (RemoteException e) {
100: System.out.println("Thread " + name + " : " + e);
101: F_read.threadfail = true;
102: } catch (RemoveException e) {
103: System.out.println("Thread " + name
104: + " Cannot remove session: " + e);
105: F_read.threadfail = true;
106: }
107: }
108: }
|