User: schaefera
Date: 02/04/16 22:07:24
Modified: src/main/org/jboss/test/banknew/test Tag: Branch_2_4
BankMarathonTestCase.java BankStressTestCase.java
Log:
Redesigned the banknew example therefore to a create separation between
the Entity Bean (CMP) and the Session Beans (Business Logic).
The test cases are redesigned but not finished yet.
Revision Changes Path
No revision
No revision
1.1.2.3 +251 -436
jbosstest/src/main/org/jboss/test/banknew/test/Attic/BankMarathonTestCase.java
Index: BankMarathonTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/banknew/test/Attic/BankMarathonTestCase.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- BankMarathonTestCase.java 15 Apr 2002 04:28:15 -0000 1.1.2.2
+++ BankMarathonTestCase.java 17 Apr 2002 05:07:24 -0000 1.1.2.3
@@ -4,24 +4,29 @@
*/
package org.jboss.test.banknew.test;
-import java.util.*;
-import java.lang.reflect.*;
-import javax.ejb.*;
-import javax.naming.*;
-import javax.management.*;
-import org.jboss.test.banknew.ejbeans.AccountBean;
-import org.jboss.test.banknew.ejbeans.BankBean;
-import org.jboss.test.banknew.ejbeans.CustomerBean;
-import org.jboss.test.banknew.ejbeans.TellerBean;
-import org.jboss.test.banknew.interfaces.Account;
+import java.rmi.RemoteException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import javax.ejb.CreateException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
import org.jboss.test.banknew.interfaces.AccountData;
-import org.jboss.test.banknew.interfaces.AccountHome;
-import org.jboss.test.banknew.interfaces.Bank;
-import org.jboss.test.banknew.interfaces.BankHome;
-import org.jboss.test.banknew.interfaces.Customer;
-import org.jboss.test.banknew.interfaces.CustomerHome;
-import org.jboss.test.banknew.interfaces.Teller;
-import org.jboss.test.banknew.interfaces.TellerHome;
+import org.jboss.test.banknew.interfaces.AccountSession;
+import org.jboss.test.banknew.interfaces.AccountSessionHome;
+import org.jboss.test.banknew.interfaces.BankData;
+import org.jboss.test.banknew.interfaces.BankSession;
+import org.jboss.test.banknew.interfaces.BankSessionHome;
+import org.jboss.test.banknew.interfaces.Constants;
+import org.jboss.test.banknew.interfaces.CustomerData;
+import org.jboss.test.banknew.interfaces.CustomerSession;
+import org.jboss.test.banknew.interfaces.CustomerSessionHome;
+import org.jboss.test.banknew.interfaces.TellerSession;
+import org.jboss.test.banknew.interfaces.TellerSessionHome;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -32,226 +37,154 @@
import org.apache.log4j.Category;
/**
- *
- * @see <related>
- * @author Author: d_jencks among many others
- * @version $Revision: 1.1.2.2 $
+ * Marathon test case to test JBoss under moderate utilization for
+ * a long time (hours or days) to see if there is a memory leak or
+ * other long time exceptions
+ *
+ * @see <related>
+ * @author Author: Andreas Schaefer
+ * @version $Revision: 1.1.2.3 $
*/
public class BankMarathonTestCase
extends JBossTestCase
{
// Constants -----------------------------------------------------
- public static final int DEFAULT_DURATION = 1 * 60 * 60 * 1000; // 1 hour
+ public static final int DEFAULT_DURATION = Constants.ONE_DAY; // 1 Day (24
hours)
// Attributes ----------------------------------------------------
private int mIndex = 1;
private int mCount;
private Exception mException;
private boolean mExit = false;
+ private Context mContext;
+ private final Object mLock = new Object();
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- public BankMarathonTestCase(String name)
- {
- super(name);
- System.out.println( "AS BankMarathonTestCase(), name: " + name );
+ public BankMarathonTestCase( String pName ) {
+ super( pName );
+ System.out.println( "AS BankMarathonTestCase(), name: " + pName );
}
// Public --------------------------------------------------------
- public void testTeller()
- throws Exception
- {
- System.out.println( "AS testTeller()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- Teller teller = home.create();
-
- BankHome bankHome = (BankHome)new InitialContext().lookup( BankBean.JNDI_NAME
);
- Bank bank = bankHome.create();
-
- log.info("Acquire customers");
- Customer marc = teller.getCustomer("Marc");
- Customer rickard = teller.getCustomer("Rickard");
-
- log.info("Acquire accounts");
- Account from = teller.getAccount(marc, 200);
- Account to = teller.getAccount(rickard, 200);
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- log.info("Transfer money");
-
- long start = System.currentTimeMillis();
- int iter = 10;
- for (int i = 0; i < iter; i++)
- teller.transfer(from, to, 50);
- long end = System.currentTimeMillis();
- getLog().info("Average call time: "+((end - start) / (iter*6)));
-
- log.info("Show balance");
- AccountHome accountHome = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
- Collection accts = accountHome.findAll();
- Iterator enum = accts.iterator();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- AccountData data = acct.getData();
- log.info(data.getId()+"("+data.getOwnerId()+"):"+data.getBalance());
- acct.withdraw(data.getBalance()); // Clear
- }
-
- teller.remove();
- System.out.println( "AS testTeller() ends" );
- }
- public void testBank()
- throws Exception
- {
- System.out.println( "AS testBank()" );
- log.info("Get code");
- BankHome bankHome = (BankHome)new InitialContext().lookup( BankBean.JNDI_NAME
);
-
- Bank bank = bankHome.create();
-
- log.info("Bank id="+bank.getId());
- bank.remove();
- System.out.println( "AS testBank() ends" );
- }
-
-/* public void testCustomer()
- throws Exception
- {
- log.info("Customer test----------------------------------");
-
- log.info("Create Customer");
- CustomerHome customerHome = (CustomerHome)new InitialContext().lookup(
"Customer");
- Account from, to;
- try
- {
- from = accountHome.findByPrimaryKey("Marc");
- from.deposit(200);
- } catch (FinderException e)
- {
- from = accountHome.create("Marc", 200);
- }
-
- try
- {
- to = accountHome.findByPrimaryKey("Rickard");
- } catch (FinderException e)
- {
- to = accountHome.create("Rickard", 0);
- }
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- log.info("Transfer money");
- TellerHome home = (TellerHome)new InitialContext().lookup( "Teller");
- Teller teller = home.create();
-
- long start = System.currentTimeMillis();
- for (int i = 0; i < 100; i++)
- teller.transfer(from, to, 50);
- teller.remove();
-
- log.info("Show balance");
- Iterator enum = accountHome.findAll();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- log.info(acct.getPrimaryKey()+":"+acct.getBalance());
- acct.withdraw(acct.getBalance()); // Clear
- }
- log.info("Teller test done----------------------------------");
- }
-*/
-
- public void testEntityCreation()
- throws Exception
- {
- System.out.println( "AS BankMarathonTestCase.testEntityCreation()" );
-
- TellerHome lHome = (TellerHome) new InitialContext().lookup(
TellerBean.JNDI_NAME );
- final Teller lTeller = lHome.create();
- final Object lLock = new Object();
+ /**
+ * Checks if the environment of test is working
+ **/
+ public void testEnvironment()
+ throws Exception
+ {
+ // Get all session home interfaces first
+ System.out.println( "AS testEnvironment()" );
+// Context lContext = new InitialContext();
+
+ BankSessionHome lBankHome = (BankSessionHome) mContext.lookup(
BankSessionHome.JNDI_NAME );
+ CustomerSessionHome lCustomerHome = (CustomerSessionHome) mContext.lookup(
CustomerSessionHome.JNDI_NAME );
+ AccountSessionHome lAccountHome = (AccountSessionHome) mContext.lookup(
AccountSessionHome.JNDI_NAME );
+ TellerSessionHome lTellerHome = (TellerSessionHome) mContext.lookup(
TellerSessionHome.JNDI_NAME );
+
+ // Create a session bean by default
+ BankSession lBank = lBankHome.create();
+ CustomerSession lCustomer = lCustomerHome.create();
+ AccountSession lAccount = lAccountHome.create();
+ TellerSession lTeller = lTellerHome.create();
+
+ // Create a bank the root of everything
+ BankData lBankData = lBank.createBank( "Andy's TestBank", "12345 XMass
Avenue, New JBoss, GA" );
+
+ // Check all the methods on teller inteface because that
+ // is what we are here working with primarly
+ CustomerData lCustomerData = lTeller.createCustomer( lBankData.getId(),
"One", 100 );
+ CustomerData lCustomerData2 = lTeller.getCustomer( lCustomerData.getId() );
+ Collection lCustomers = lTeller.getCustomers( lBankData.getId() );
+
+ AccountData lAccountData = lTeller.createAccount( lCustomerData.getId(),
Constants.SAVING, 150 );
+ AccountData lAccountData2 = lTeller.getAccount( lCustomerData.getId(),
Constants.SAVING );
+ AccountData lAccountData3 = lTeller.getAccount( lAccountData.getId() );
+ AccountData lAccountData4 = lTeller.getAccount( lCustomerData.getId(),
Constants.CHECKING );
+ Collection lAccounts = lTeller.getAccounts( lCustomerData.getId() );
+
+ lTeller.deposit( lAccountData4.getId(), 75 );
+ lTeller.withdraw( lAccountData3.getId(), 63 );
+ lTeller.transfer( lAccountData4.getId(), lAccountData3.getId(), 52 );
+
+ lTeller.removeAccount( lAccountData4.getId() );
+ lTeller.removeAccount( lAccountData.getId() );
+ lTeller.removeCustomer( lCustomerData.getId() );
+
+ lBank.removeBank( lBankData.getId() );
+ System.out.println( "AS testEnvironment() ends" );
+ }
+
+ /**
+ * Marathon test which will:
+ * - set up test environment (creating bank, customers and accounts)
+ * - create test thread
+ * - create or lookup a customer
+ * - create or look up the accounts
+ * - do (a list of):
+ * - withdraw
+ * - transfer (within customer's accounts or with other customer)
+ * - deposit
+ * - maybe the account is deleted
+ * - maybe the customer is deleted
+ * - maybe the transactions are listed
+ *
+ * A thread represents a teller (either person (can create and delete
+ * customer and accounts or a electronic one) which loops other many
+ * business interactions, each loop represents a single business inter-
+ * action. Therefore each task will sleep and each business interaction
+ * as well. Currently this is complete random but it would be also possible
+ * to test crunch times by applying a trend
+ **/
+ public void testMarathon()
+ throws Exception
+ {
+ System.out.println( "AS BankMarathonTestCase.testMarathon()" );
+ // Setup the environment
+ setupBank();
mCount = getThreadCount();
+ mExit = false;
final int lIterationCount = getIterationCount();
- getLog().info("Start test. "+getThreadCount()+ " threads,
"+getIterationCount()+" iterations");
+ getLog().info(
+ "Start marathon: " + getThreadCount() +
+ " threads, " + getIterationCount() + " iterations"
+ );
System.out.println("Start test. "+getThreadCount()+ " threads,
"+getIterationCount()+" iterations");
long lStart = System.currentTimeMillis();
- mExit = false;
for( int i = 0; i < getThreadCount(); i++ ) {
final int lThreadNr = i;
Thread.sleep( 1000 );
System.out.println( "AS testMultiThread() create new long thread: " + i );
new Thread(
- new Runnable() {
- public void run() {
- int k = 0;
- System.out.println( "Thread.run(), exit: " + mExit );
- Random lRandom = new Random();
- Category lLog = Category.getInstance( getClass().getName() );
- Customer lOne = null;
- Customer lTwo = null;
- Account lAccountOne = null;
- Account lAccountTwo = null;
- while( !mExit && mException == null ) {
- int lIteration = lRandom.nextInt( lIterationCount ) + 1;
- System.out.println( "Loop, exit: " + mExit + ", iteration: " +
lIteration );
- try {
- for( int j = 0; j < lIteration ; j++ ) {
- if( mException != null || mExit ) {
- break;
- }
- if( j % 5 == 0 ) {
- lOne = lTeller.getCustomer( "One" + lThreadNr + "" +
( k++ ) );
- lTwo = lTeller.getCustomer( "Two" + lThreadNr + "" +
k );
- lAccountOne = lTeller.getAccount( lOne, 50 );
- lAccountTwo = lTeller.getAccount( lTwo, 25 );
- }
-/*
- int lValue = lRandom.nextInt(
- (int) lFrom.getBalance()
- );
- lTeller.transfer( lFrom, lTo, lValue );
- lTeller.transfer( lTo, lFrom, lValue );
-*/
- lTeller.transfer( lAccountOne, lAccountTwo, 50 );
- lTeller.transfer( lAccountTwo, lAccountOne, 50 );
- Thread.sleep( lRandom.nextInt( 1000 ) );
- }
- }
- catch( Exception e ) {
- e.printStackTrace();
- mException = e;
- }
- }
- synchronized( lLock ) {
- System.out.println( "AS testMultiThread() lock" );
- mCount--;
- lLog.info("Only "+mCount+" left");
- lLock.notifyAll();
- System.out.println( "AS testMultiThread() lock ends" );
- }
- }
- }
+ new RegularTeller()
).start();
}
- synchronized( lLock ) {
- System.out.println( "LBSTC, duration: " + getDuration() );
- Thread.sleep( getDuration() ); // Wait for a given period of time
+ int lMinutes = (int) ( getDuration() / ( Constants.ONE_MINUTE ) ) + 1;
+ synchronized( mLock ) {
+ // Loop over a minute period sleep time to ensure
+ // that when an exception is thrown this threads
+ // terminate itself, too.
+ for( int i = 0; i < lMinutes; i++ ) {
+ Thread.sleep( Constants.ONE_MINUTE );
+ // Ensure that not a thread is waiting to get the lock
+ // to remove him from the list of running threads which
+ // could end this loop (mCount == 0)
+ mLock.wait();
+ if( mException != null || mCount == 0 ) {
+ // Exception found then terminate test
+ break;
+ }
+ }
mExit = true; // Switch flag to exit all running threads
while( mCount > 0 ) { // Check until all threads exited
System.out.println( "AS testMultiThread() lock wait !!" );
- lLock.wait();
+ mLock.wait();
}
}
@@ -275,267 +208,149 @@
);
System.out.println( "AS testMultiThread() ends" );
}
-
- public void testMultiThread2()
+
+ protected void setUp()
throws Exception
{
- System.out.println( "AS testMultiThread2()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- final Teller teller = home.create();
-
- log.info("Acquire customers");
-
- final Customer marc = teller.getCustomer("Marc");
- final Customer rickard = teller.getCustomer("Rickard");
-
- final Object lock = new Object();
-
+ System.out.println( "AS setUp()" );
+ mContext = new InitialContext();
- mCount = getThreadCount();
- final int lIterationCount = getIterationCount();
- getLog().info("Start test. "+getThreadCount()+ " threads,
"+getIterationCount()+" iterations");
- long start = System.currentTimeMillis();
-
- for (int i = 0; i < getThreadCount(); i++)
- {
- Thread.sleep(500); // Wait between each client
- new Thread(new Runnable()
- {
- Category log = Category.getInstance(getClass().getName());
-
- public void run()
- {
- try
- {
-
- Account from = teller.createAccount(marc, 50);
- Account to = teller.createAccount(rickard, 0);
-
- for (int j = 0; j < lIterationCount; j++)
- {
- if (mException != null) break;
-
- teller.transfer(from,to,50);
- teller.transfer(from,to,-50);
-// Thread.currentThread().yield();
-// log.debug(mIndex++);
- }
- } catch (Exception e)
- {
- mException = e;
- }
-
- synchronized(lock)
- {
- mCount--;
- log.info("Only "+mCount+" left");
- lock.notifyAll();
- }
+ getLog().info("Remove accounts and customers");
+ BankSessionHome lBankHome = (BankSessionHome) mContext.lookup(
BankSessionHome.JNDI_NAME );
+ CustomerSessionHome lCustomerHome = (CustomerSessionHome) mContext.lookup(
CustomerSessionHome.JNDI_NAME );
+ AccountSessionHome lAccountHome = (AccountSessionHome) mContext.lookup(
AccountSessionHome.JNDI_NAME );
+ BankSession lBankSession = lBankHome.create();
+ Collection lBanks = lBankSession.getBanks();
+ Iterator i = lBanks.iterator();
+ while( i.hasNext() ) {
+ BankData lBank = (BankData) i.next();
+ // Get all customers
+ CustomerSession lCustomerSession = lCustomerHome.create();
+ Collection lCustomers = lCustomerSession.getCustomers( lBank.getId() );
+ Iterator j = lCustomers.iterator();
+ while( j.hasNext() ) {
+ CustomerData lCustomer = (CustomerData) j.next();
+ // Get all accounts
+ AccountSession lAccountSession = lAccountHome.create();
+ Collection lAccounts = lAccountSession.getAccounts( lCustomer.getId() );
+ Iterator k = lAccounts.iterator();
+ while( k.hasNext() ) {
+ AccountData lAccount = (AccountData) k.next();
+ lAccountSession.removeAccount( lAccount.getId() );
}
- }).start();
- }
-
- synchronized(lock)
- {
- while(mCount>0)
- {
- lock.wait();
+ lCustomerSession.removeCustomer( lCustomer.getId() );
}
+ lBankSession.removeBank( lBank.getId() );
}
-
- if (mException != null) throw mException;
-
- long end = System.currentTimeMillis();
-
- getLog().info("Time:"+(end-start));
- getLog().info("Avg.
time/call(ms):"+((end-start)/(getThreadCount()*getIterationCount()*6)));
- System.out.println( "AS testMultiThread2() ends" );
+ System.out.println( "AS setUp() ends" );
}
- public void testTransaction()
+ protected int getDuration() {
+ return Integer.getInteger(
+ "jbosstest.duration",
+ DEFAULT_DURATION
+ ).intValue();
+ }
+
+ public void setupBank()
throws Exception
{
- System.out.println( "AS testTransaction()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- Teller teller = home.create();
-
- log.info("Acquire customers");
- Customer marc = teller.getCustomer("Marc");
- log.info("Marc acquired");
- Customer rickard = teller.getCustomer("Rickard");
- log.info("Rickard acquired");
-
- log.info("Acquire accounts");
- Account from = teller.getAccount(marc, 50);
- Account to = teller.getAccount(rickard, 0);
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- log.info("Transfer money");
- teller.transfer(from, to, 50);
- log.info("Transfer done");
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+"("+from.getOwnerId()+"):"+from.getBalance());
- log.info(to.getPrimaryKey()+"("+to.getOwnerId()+"):"+to.getBalance());
-
- teller.remove();
-
- System.out.println( "AS testTransaction() ends" );
+ //AS ToDo
+ BankData lBank = getBankSession().createBank( "Andy's TestBank", "12345 XMass
Avenue, New JBoss, GA" );
+ CustomerData lCustomer = getCustomerSession().createCustomer( lBank.getId(),
"test", 100 );
}
-
- public void testTransfer()
- throws Exception
+
+ public static Test suite() throws Exception
{
- System.out.println( "AS testTransfer()" );
-
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- Teller teller = home.create();
-
- log.info("Acquire customers");
- Customer marc = teller.getCustomer("Marc");
- log.info("Marc acquired");
- Customer rickard = teller.getCustomer("Rickard");
- log.info("Rickard acquired");
-
- log.info("Acquire accounts");
- Account from = teller.getAccount(marc, 50*getIterationCount());
- Account to = teller.getAccount(rickard, 0);
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- getLog().info("Transfer money");
- long start = System.currentTimeMillis();
- teller.transferTest(from, to, 50, getIterationCount());
- long end = System.currentTimeMillis();
- getLog().info("Transfer done");
- getLog().info("Total time(ms):"+(end-start));
- getLog().info("Avg. time/call(ms):"+((end-start)/(getIterationCount()*2)));
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- teller.remove();
- System.out.println( "AS testTransfer() ends" );
+ return getDeploySetup( BankMarathonTestCase.class, "banknew.jar" );
}
- public void testReadOnly()
- throws Exception
+ private BankSession getBankSession()
+ throws CreateException, RemoteException, NamingException
{
- System.out.println( "AS testReadOnly()" );
-
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- Teller teller = home.create();
-
- log.info("Acquire customers");
- Customer marc = teller.getCustomer("Marc");
- log.info("Marc acquired");
- Customer rickard = teller.getCustomer("Rickard");
- log.info("Rickard acquired");
-
- log.info("Acquire accounts");
- Account from = teller.getAccount(marc, 50*getIterationCount());
- Account to = teller.getAccount(rickard, 0);
-
- getLog().info("Do read calls");
- long start = System.currentTimeMillis();
- for (int i = 0; i < getIterationCount(); i++)
- {
- marc.getName();
- from.getBalance();
- rickard.getName();
- to.getBalance();
- }
- long end = System.currentTimeMillis();
-
- getLog().info("Calls done");
- getLog().info("Total time(ms):"+(end-start));
- getLog().info("Avg. time/call(ms):"+((end-start)/(getIterationCount()*4)));
-
- teller.remove();
- System.out.println( "AS testReadOnly() ends" );
+ return ( (BankSessionHome) mContext.lookup( BankSessionHome.JNDI_NAME )
).create();
}
- public void testPassivation()
- throws Exception
+ private CustomerSession getCustomerSession()
+ throws CreateException, RemoteException, NamingException
{
- System.out.println( "AS testPassivation()" );
- // Create a bunch of customers, to test passivation
-
- CustomerHome home = (CustomerHome)new InitialContext().lookup(
CustomerBean.JNDI_NAME );
-
- getLog().info("Create customers");
-
- for (int i = 0; i < getIterationCount(); i++)
- home.create(i+"", "Smith_"+i);
- log.info("Customers created");
-
- System.out.println( "AS testPassivation() ends" );
+ return ( (CustomerSessionHome) mContext.lookup( CustomerSessionHome.JNDI_NAME
) ).create();
}
- public void testFinder()
- throws Exception
+ private AccountSession getAccountSession()
+ throws CreateException, RemoteException, NamingException
{
- System.out.println( "AS testFinder()" );
- //create some accounts
- testPassivation();
- AccountHome home = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
-
- getLog().info("Get large accounts");
- Iterator enum = home.findLargeAccounts(-1).iterator();
- while (enum.hasNext())
- {
- Account acct = (Account)enum.next();
- log.info(acct.getOwnerId()+":"+acct.getBalance());
- }
- System.out.println( "AS testFinder() ends" );
+ return ( (AccountSessionHome) mContext.lookup( AccountSessionHome.JNDI_NAME )
).create();
}
-
- protected void setUp()
- throws Exception
+
+ class RegularTeller
+ implements Runnable
{
- System.out.println( "AS setUp()" );
- getLog().info("Remove accounts");
- {
- AccountHome home = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
- Collection accounts = home.findAll();
- Iterator enum = accounts.iterator();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- log.info("Removing "+acct.getPrimaryKey());
- acct.remove();
+ public void run() {
+ int k = 0;
+ Random lRandom = new Random();
+ Category lLog = Category.getInstance( getClass().getName() );
+ System.out.println( "Thread.run(), exit: " + mExit );
+
+ try {
+
+ // Get bank first
+ Collection lBanks = getBankSession().getBanks();
+ System.out.println( "RegularTeller.run(), banks: " + lBanks );
+ BankData lBank = (BankData) lBanks.iterator().next();
+ while( !mExit && mException == null ) {
+ CustomerData lCustomer = null;
+ if( lRandom.nextInt( 100 ) < 10 ) {
+ lCustomer = getCustomerSession().createCustomer( lBank.getId(),
"test", 100 );
+ System.out.println( "RegularTeller.run(), new " + lCustomer );
+ } else {
+ List lCustomers = (List) getBankSession().getCustomers(
lBank.getId() );
+ System.out.println( "RegularTeller.run(), # of customers: " +
lCustomers.size() );
+ lCustomer = (CustomerData) lCustomers.get( lRandom.nextInt(
lCustomers.size() ) );
+ }
+ }
+ /*
+ Customer lOne = null;
+ Customer lTwo = null;
+ Account lAccountOne = null;
+ Account lAccountTwo = null;
+ while( !mExit && mException == null ) {
+ int lIteration = lRandom.nextInt( lIterationCount ) + 1;
+ System.out.println( "Loop, exit: " + mExit + ", iteration: " +
lIteration );
+ try {
+ for( int j = 0; j < lIteration ; j++ ) {
+ if( mException != null || mExit ) {
+ break;
+ }
+ if( j % 5 == 0 ) {
+ lOne = lTeller.getCustomer( "One" + lThreadNr + "" + ( k++
) );
+ lTwo = lTeller.getCustomer( "Two" + lThreadNr + "" + k );
+ lAccountOne = lTeller.getAccount( lOne, 50 );
+ lAccountTwo = lTeller.getAccount( lTwo, 25 );
+ }
+ lTeller.transfer( lAccountOne, lAccountTwo, 50 );
+ lTeller.transfer( lAccountTwo, lAccountOne, 50 );
+ Thread.sleep( lRandom.nextInt( 1000 ) );
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ mException = e;
+ }
+ }
+ */
}
- }
- getLog().info("Remove customers");
- {
- CustomerHome home = (CustomerHome)new InitialContext().lookup(
CustomerBean.JNDI_NAME );
- Collection customers = home.findAll();
- Iterator enum = customers.iterator();
- while(enum.hasNext())
- {
- Customer cust = (Customer)enum.next();
- log.info("Removing "+cust.getPrimaryKey());
- cust.remove();
+ catch( Exception e ) {
+ e.printStackTrace();
+ mException = e;
+ }
+
+ synchronized( mLock ) {
+ mCount--;
+ lLog.info("Only "+mCount+" left");
+ System.out.println("Only "+mCount+" left");
+ mLock.notifyAll();
}
}
- System.out.println( "AS setUp() ends" );
- }
-
- protected int getDuration() {
- return Integer.getInteger(
- "jbosstest.duration",
- DEFAULT_DURATION
- ).intValue();
- }
-
- public static Test suite() throws Exception
- {
- return getDeploySetup( BankMarathonTestCase.class, "banknew.jar" );
}
}
1.1.2.3 +97 -126
jbosstest/src/main/org/jboss/test/banknew/test/Attic/BankStressTestCase.java
Index: BankStressTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/banknew/test/Attic/BankStressTestCase.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- BankStressTestCase.java 15 Apr 2002 04:28:15 -0000 1.1.2.2
+++ BankStressTestCase.java 17 Apr 2002 05:07:24 -0000 1.1.2.3
@@ -4,24 +4,24 @@
*/
package org.jboss.test.banknew.test;
-import java.util.*;
-import java.lang.reflect.*;
-import javax.ejb.*;
-import javax.naming.*;
-import javax.management.*;
-import org.jboss.test.banknew.ejbeans.AccountBean;
-import org.jboss.test.banknew.ejbeans.BankBean;
-import org.jboss.test.banknew.ejbeans.CustomerBean;
-import org.jboss.test.banknew.ejbeans.TellerBean;
-import org.jboss.test.banknew.interfaces.Account;
+import java.util.Collection;
+import java.util.Iterator;
+// import java.lang.reflect.*;
+// import javax.ejb.*;
+import javax.naming.InitialContext;
+// import javax.management.*;
import org.jboss.test.banknew.interfaces.AccountData;
-import org.jboss.test.banknew.interfaces.AccountHome;
-import org.jboss.test.banknew.interfaces.Bank;
-import org.jboss.test.banknew.interfaces.BankHome;
-import org.jboss.test.banknew.interfaces.Customer;
-import org.jboss.test.banknew.interfaces.CustomerHome;
-import org.jboss.test.banknew.interfaces.Teller;
-import org.jboss.test.banknew.interfaces.TellerHome;
+import org.jboss.test.banknew.interfaces.AccountSession;
+import org.jboss.test.banknew.interfaces.AccountSessionHome;
+import org.jboss.test.banknew.interfaces.BankData;
+import org.jboss.test.banknew.interfaces.BankSession;
+import org.jboss.test.banknew.interfaces.BankSessionHome;
+import org.jboss.test.banknew.interfaces.Constants;
+import org.jboss.test.banknew.interfaces.CustomerData;
+import org.jboss.test.banknew.interfaces.CustomerSession;
+import org.jboss.test.banknew.interfaces.CustomerSessionHome;
+import org.jboss.test.banknew.interfaces.TellerSession;
+import org.jboss.test.banknew.interfaces.TellerSessionHome;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -35,7 +35,7 @@
*
* @see <related>
* @author Author: d_jencks among many others
- * @version $Revision: 1.1.2.2 $
+ * @version $Revision: 1.1.2.3 $
*/
public class BankStressTestCase
extends JBossTestCase
@@ -61,55 +61,70 @@
throws Exception
{
System.out.println( "AS testTeller()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
- Teller teller = home.create();
+ TellerSessionHome tellerHome = (TellerSessionHome)new
InitialContext().lookup( TellerSessionHome.JNDI_NAME );
+ TellerSession tellerSession = tellerHome.create();
- BankHome bankHome = (BankHome)new InitialContext().lookup( BankBean.JNDI_NAME
);
- Bank bank = bankHome.create();
+ BankSessionHome bankHome = (BankSessionHome)new InitialContext().lookup(
BankSessionHome.JNDI_NAME );
+ BankSession bankSession = bankHome.create();
+ BankData bank = bankSession.createBank( "Andy's Testbank", "ABC Street, New
York, GA" );
log.info("Acquire customers");
- Customer marc = teller.getCustomer("Marc");
- Customer rickard = teller.getCustomer("Rickard");
+ CustomerData marc = tellerSession.createCustomer( bank.getId(), "Marc", 200 );
+ CustomerData rickard = tellerSession.createCustomer( bank.getId(), "Rickard",
200 );
log.info("Acquire accounts");
- Account from = teller.getAccount(marc, 200);
- Account to = teller.getAccount(rickard, 200);
+ AccountData from = tellerSession.getAccount( marc.getId(), Constants.CHECKING
);
+ AccountData to = tellerSession.getAccount( rickard.getId(),
Constants.CHECKING );
log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
+ log.info( from.getId() + ":" + from.getBalance() );
+ log.info( to.getId() + ":" + to.getBalance() );
+
log.info("Transfer money");
long start = System.currentTimeMillis();
int iter = 10;
- for (int i = 0; i < iter; i++)
- teller.transfer(from, to, 50);
+ for( int i = 0; i < iter; i++ ) {
+ tellerSession.transfer( from.getId(), to.getId(), 50 );
+ }
long end = System.currentTimeMillis();
- getLog().info("Average call time: "+((end - start) / (iter*6)));
+ getLog().info( "Average call time: " + ( ( end - start ) / ( iter * 6 ) ) );
log.info("Show balance");
- AccountHome accountHome = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
- Collection accts = accountHome.findAll();
- Iterator enum = accts.iterator();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- AccountData data = acct.getData();
- log.info( data.getId() + "( " + data.getOwnerId() + " ): " +
data.getBalance() );
- acct.withdraw(data.getBalance()); // Clear
- }
-
- teller.remove();
+ Collection accts = tellerSession.getAccounts( marc.getId() );
+ Iterator i = accts.iterator();
+ while( i.hasNext() )
+ {
+ AccountData data = (AccountData) i.next();
+ log.info( data.getId() + "( " + data.getCustomerId() + " ): " +
data.getBalance() );
+ tellerSession.withdraw( data.getId(), data.getBalance() ); // Clear Account
+ tellerSession.removeCustomer( data.getId() );
+ }
+ accts = tellerSession.getAccounts( rickard.getId() );
+ i = accts.iterator();
+ while( i.hasNext() )
+ {
+ AccountData data = (AccountData) i.next();
+ log.info( data.getId() + "( " + data.getCustomerId() + " ): " +
data.getBalance() );
+ tellerSession.withdraw( data.getId(), data.getBalance() ); // Clear Account
+ tellerSession.removeCustomer( data.getId() );
+ }
+
+ // Clear System
+ tellerSession.removeCustomer( marc.getId() );
+ tellerSession.removeCustomer( rickard.getId() );
+ tellerSession.remove();
+ bankSession.removeBank( bank.getId() );
+ bankSession.remove();
System.out.println( "AS testTeller() ends" );
}
-
+/*
public void testBank()
throws Exception
{
System.out.println( "AS testBank()" );
log.info("Get code");
- BankHome bankHome = (BankHome)new InitialContext().lookup( BankBean.JNDI_NAME
);
+ BankHome bankHome = (BankHome)new InitialContext().lookup( BankHome.JNDI_NAME
);
Bank bank = bankHome.create();
@@ -118,61 +133,11 @@
System.out.println( "AS testBank() ends" );
}
-/* public void testCustomer()
- throws Exception
- {
- log.info("Customer test----------------------------------");
-
- log.info("Create Customer");
- CustomerHome customerHome = (CustomerHome)new
InitialContext().lookup("Customer");
- Account from, to;
- try
- {
- from = accountHome.findByPrimaryKey("Marc");
- from.deposit(200);
- } catch (FinderException e)
- {
- from = accountHome.create("Marc", 200);
- }
-
- try
- {
- to = accountHome.findByPrimaryKey("Rickard");
- } catch (FinderException e)
- {
- to = accountHome.create("Rickard", 0);
- }
-
- log.info("Show balance");
- log.info(from.getPrimaryKey()+":"+from.getBalance());
- log.info(to.getPrimaryKey()+":"+to.getBalance());
-
- log.info("Transfer money");
- TellerHome home = (TellerHome)new InitialContext().lookup("Teller");
- Teller teller = home.create();
-
- long start = System.currentTimeMillis();
- for (int i = 0; i < 100; i++)
- teller.transfer(from, to, 50);
- teller.remove();
-
- log.info("Show balance");
- Iterator enum = accountHome.findAll();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- log.info(acct.getPrimaryKey()+":"+acct.getBalance());
- acct.withdraw(acct.getBalance()); // Clear
- }
- log.info("Teller test done----------------------------------");
- }
-*/
-
public void testMultiThread()
throws Exception
{
System.out.println( "AS testMultiThread()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
+ TellerHome home = (TellerHome)new InitialContext().lookup(
TellerHome.JNDI_NAME );
final Teller teller = home.create();
log.info("Acquire customers");
@@ -266,7 +231,7 @@
throws Exception
{
System.out.println( "AS testMultiThread2()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
+ TellerHome home = (TellerHome)new InitialContext().lookup(
TellerHome.JNDI_NAME );
final Teller teller = home.create();
log.info("Acquire customers");
@@ -342,7 +307,7 @@
throws Exception
{
System.out.println( "AS testTransaction()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
+ TellerHome home = (TellerHome)new InitialContext().lookup(
TellerHome.JNDI_NAME );
Teller teller = home.create();
log.info("Acquire customers");
@@ -377,7 +342,7 @@
{
System.out.println( "AS testTransfer()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
+ TellerHome home = (TellerHome)new InitialContext().lookup(
TellerHome.JNDI_NAME );
Teller teller = home.create();
log.info("Acquire customers");
@@ -415,7 +380,7 @@
{
System.out.println( "AS testReadOnly()" );
- TellerHome home = (TellerHome)new InitialContext().lookup(
TellerBean.JNDI_NAME );
+ TellerHome home = (TellerHome)new InitialContext().lookup(
TellerHome.JNDI_NAME );
Teller teller = home.create();
log.info("Acquire customers");
@@ -453,7 +418,7 @@
System.out.println( "AS testPassivation()" );
// Create a bunch of customers, to test passivation
- CustomerHome home = (CustomerHome)new InitialContext().lookup(
CustomerBean.JNDI_NAME );
+ CustomerHome home = (CustomerHome)new InitialContext().lookup(
CustomerHome.JNDI_NAME );
getLog().info("Create customers");
@@ -470,7 +435,7 @@
System.out.println( "AS testFinder()" );
//create some accounts
testPassivation();
- AccountHome home = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
+ AccountHome home = (AccountHome)new InitialContext().lookup(
AccountHome.JNDI_NAME );
getLog().info("Get large accounts");
Iterator enum = home.findLargeAccounts(-1).iterator();
@@ -481,34 +446,40 @@
}
System.out.println( "AS testFinder() ends" );
}
-
+*/
+
protected void setUp()
throws Exception
{
System.out.println( "AS setUp()" );
- getLog().info("Remove accounts");
- {
- AccountHome home = (AccountHome)new InitialContext().lookup(
AccountBean.JNDI_NAME );
- Collection accounts = home.findAll();
- Iterator enum = accounts.iterator();
- while(enum.hasNext())
- {
- Account acct = (Account)enum.next();
- log.info("Removing "+acct.getPrimaryKey());
- acct.remove();
- }
- }
- getLog().info("Remove customers");
- {
- CustomerHome home = (CustomerHome)new InitialContext().lookup(
CustomerBean.JNDI_NAME );
- Collection customers = home.findAll();
- Iterator enum = customers.iterator();
- while(enum.hasNext())
- {
- Customer cust = (Customer)enum.next();
- log.info("Removing "+cust.getPrimaryKey());
- cust.remove();
+ InitialContext lContext = new InitialContext();
+
+ getLog().info("Remove accounts and customers");
+ BankSessionHome lBankHome = (BankSessionHome) lContext.lookup(
BankSessionHome.JNDI_NAME );
+ CustomerSessionHome lCustomerHome = (CustomerSessionHome) lContext.lookup(
CustomerSessionHome.JNDI_NAME );
+ AccountSessionHome lAccountHome = (AccountSessionHome) lContext.lookup(
AccountSessionHome.JNDI_NAME );
+ BankSession lBankSession = lBankHome.create();
+ Collection lBanks = lBankSession.getBanks();
+ Iterator i = lBanks.iterator();
+ while( i.hasNext() ) {
+ BankData lBank = (BankData) i.next();
+ // Get all customers
+ CustomerSession lCustomerSession = lCustomerHome.create();
+ Collection lCustomers = lCustomerSession.getCustomers( lBank.getId() );
+ Iterator j = lCustomers.iterator();
+ while( j.hasNext() ) {
+ CustomerData lCustomer = (CustomerData) j.next();
+ // Get all accounts
+ AccountSession lAccountSession = lAccountHome.create();
+ Collection lAccounts = lAccountSession.getAccounts( lCustomer.getId() );
+ Iterator k = lAccounts.iterator();
+ while( k.hasNext() ) {
+ AccountData lAccount = (AccountData) k.next();
+ lAccountSession.removeAccount( lAccount.getId() );
+ }
+ lCustomerSession.removeCustomer( lCustomer.getId() );
}
+ lBankSession.removeBank( lBank.getId() );
}
System.out.println( "AS setUp() ends" );
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development