User: d_jencks
  Date: 01/09/14 17:12:16

  Modified:    src/main/org/jboss/test/bank/test BankStressTestCase.java
  Log:
  Made tests work and converted to JBossTestCase and logging
  
  Revision  Changes    Path
  1.2       +113 -126  
jbosstest/src/main/org/jboss/test/bank/test/BankStressTestCase.java
  
  Index: BankStressTestCase.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/bank/test/BankStressTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BankStressTestCase.java   2001/09/12 04:55:37     1.1
  +++ BankStressTestCase.java   2001/09/15 00:12:16     1.2
  @@ -15,16 +15,18 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  -import org.jboss.test.util.Deploy;
  +import org.jboss.test.JBossTestCase;
   
  +import org.apache.log4j.Category;
  +
   /**
    *      
    *   @see <related>
  - *   @author $Author: d_jencks $
  - *   @version $Revision: 1.1 $
  + *   @author Author: d_jencks among many others
  + *   @version $Revision: 1.2 $
    */
   public class BankStressTestCase
  -   extends TestCase
  +   extends JBossTestCase
   {
      // Constants -----------------------------------------------------
       
  @@ -34,7 +36,8 @@
      Exception exc;
      
      // Static --------------------------------------------------------
  -     static boolean deployed = false;
  +   private static final int THREAD_COUNT = 10;
  +   private static final int ITERATIONS = 100;
        
      // Constructors --------------------------------------------------
        public BankStressTestCase(String name)
  @@ -52,28 +55,28 @@
         BankHome bankHome = (BankHome)new InitialContext().lookup(BankHome.JNDI_NAME);
         Bank bank = bankHome.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
         Customer marc = teller.getCustomer("Marc");
         Customer rickard = teller.getCustomer("Rickard");
         
  -      System.out.println("Acquire accounts");
  +      getLog().debug("Acquire accounts");
         Account from = teller.getAccount(marc, 200);
         Account to = teller.getAccount(rickard, 200);
         
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().debug("Show balance");
  +      getLog().debug(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().debug(to.getPrimaryKey()+":"+to.getBalance());
   
  -      System.out.println("Transfer money");
  +      getLog().debug("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();
  -      System.out.println("Average call time: "+((end - start) / (iter*6)));
  +      getLog().info("Average call time: "+((end - start) / (iter*6)));
         
  -      System.out.println("Show balance");
  +      getLog().debug("Show balance");
         AccountHome accountHome = (AccountHome)new 
InitialContext().lookup(AccountHome.JNDI_NAME);
         Collection accts = accountHome.findAll();
         Iterator enum = accts.iterator();
  @@ -81,7 +84,7 @@
         {
            Account acct = (Account)enum.next();
            AccountData data = acct.getData();
  -         
System.out.println(data.getId()+"("+data.getOwner().getName()+"):"+data.getBalance());
  +         
getLog().debug(data.getId()+"("+data.getOwner().getName()+"):"+data.getBalance());
            acct.withdraw(data.getBalance()); // Clear
         }
         
  @@ -91,21 +94,21 @@
      public void testBank()
         throws Exception
      {
  -      System.out.println("Get code");
  +      getLog().debug("Get code");
         BankHome bankHome = (BankHome)new InitialContext().lookup(BankHome.JNDI_NAME);
         
         Bank bank = bankHome.create();
         
  -      System.out.println("Bank id="+bank.getId());
  +      getLog().debug("Bank id="+bank.getId());
         bank.remove();
      }
      
   /*   public void testCustomer()
         throws Exception
      {
  -      System.out.println("Customer test----------------------------------");
  +      getLog().debug("Customer test----------------------------------");
         
  -      System.out.println("Create Customer");
  +      getLog().debug("Create Customer");
         CustomerHome customerHome = (CustomerHome)new 
InitialContext().lookup("Customer");
         Account from, to;
         try
  @@ -125,11 +128,11 @@
            to = accountHome.create("Rickard", 0);
         }
         
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().debug("Show balance");
  +      getLog().debug(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().debug(to.getPrimaryKey()+":"+to.getBalance());
   
  -      System.out.println("Transfer money");
  +      getLog().debug("Transfer money");
         TellerHome home = (TellerHome)new InitialContext().lookup("Teller");
         Teller teller = home.create();
         
  @@ -138,15 +141,15 @@
            teller.transfer(from, to, 50);
         teller.remove();
         
  -      System.out.println("Show balance");
  +      getLog().debug("Show balance");
         Iterator enum = accountHome.findAll();
         while(enum.hasNext())
         {
            Account acct = (Account)enum.next();
  -         System.out.println(acct.getPrimaryKey()+":"+acct.getBalance());
  +         getLog().debug(acct.getPrimaryKey()+":"+acct.getBalance());
            acct.withdraw(acct.getBalance()); // Clear
         }
  -      System.out.println("Teller test done----------------------------------");
  +      getLog().debug("Teller test done----------------------------------");
      }
   */
   
  @@ -156,41 +159,41 @@
         TellerHome home = (TellerHome)new 
InitialContext().lookup(TellerHome.JNDI_NAME);
         final Teller teller = home.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
         Customer marc = teller.getCustomer("Marc");
         Customer rickard = teller.getCustomer("Rickard");
         
  -      System.out.println("Acquire accounts");
  +      getLog().debug("Acquire accounts");
         final Account from = teller.getAccount(marc, 50);
         final Account to = teller.getAccount(rickard, 0);
         
         final Object lock = new Object();
      
  -      final int threadCount = 10;
  -      final int threadIterations = 10;
  -      
  -      iter = threadCount;
  -      System.out.println("Start test. "+threadCount+ " threads, 
"+threadIterations+" iterations");
  +     
  +      iter = THREAD_COUNT;
  +      getLog().info("Start test. "+THREAD_COUNT+ " threads, "+ITERATIONS+" 
iterations");
         long start = System.currentTimeMillis();
   
  -      for (int i = 0; i < threadCount; i++)
  +      for (int i = 0; i < THREAD_COUNT; i++)
         {
            Thread.sleep(50);
            new Thread(new Runnable()
            {
               public void run()
               {
  +               Category log = Category.getInstance(getClass().getName());
  +
                  try
                  {
                     
  -                  for (int j = 0; j < threadIterations; j++)
  +                  for (int j = 0; j < ITERATIONS; j++)
                     {
                        if (exc != null) break;
                        
                        teller.transfer(from,to,50);
                        teller.transfer(from,to,-50);
   //                     Thread.currentThread().yield();
  -//                     System.out.println(idx++);
  +//                     logdebug(idx++);
                     }
                  } catch (Exception e) 
                  {
  @@ -200,7 +203,7 @@
                  synchronized(lock)
                  {
                     iter--;
  -                  System.out.println("Only "+iter+" left");
  +                  log.info("Only "+iter+" left");
                     lock.notifyAll();
                  }
               }
  @@ -219,11 +222,11 @@
         
         long end = System.currentTimeMillis();
         
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  -      System.out.println("Time:"+(end-start));
  -      System.out.println("Avg. 
time/call(ms):"+((end-start)/(threadCount*threadIterations*6)));
  +      getLog().info("Show balance");
  +      getLog().info(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().info(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().info("Time:"+(end-start));
  +      getLog().info("Avg. 
time/call(ms):"+((end-start)/(THREAD_COUNT*ITERATIONS*6)));
      }
   
      public void testMultiThread2()
  @@ -232,25 +235,25 @@
         TellerHome home = (TellerHome)new 
InitialContext().lookup(TellerHome.JNDI_NAME);
         final Teller teller = home.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
   
         final Customer marc = teller.getCustomer("Marc");
         final Customer rickard = teller.getCustomer("Rickard");
         
         final Object lock = new Object();
      
  -      final int threadCount = 50;
  -      final int threadIterations = 100;
         
  -      iter = threadCount;
  -      System.out.println("Start test. "+threadCount+ " threads, 
"+threadIterations+" iterations");
  +      iter = THREAD_COUNT;
  +      getLog().info("Start test. "+THREAD_COUNT+ " threads, "+ITERATIONS+" 
iterations");
         long start = System.currentTimeMillis();
   
  -      for (int i = 0; i < threadCount; i++)
  +      for (int i = 0; i < THREAD_COUNT; i++)
         {
            Thread.sleep(500); // Wait between each client
            new Thread(new Runnable()
            {
  +            Category log = Category.getInstance(getClass().getName());
  +
               public void run()
               {
                  try
  @@ -259,14 +262,14 @@
                     Account from = teller.createAccount(marc, 50);
                     Account to = teller.createAccount(rickard, 0);
                     
  -                  for (int j = 0; j < threadIterations; j++)
  +                  for (int j = 0; j < ITERATIONS; j++)
                     {
                        if (exc != null) break;
                        
                        teller.transfer(from,to,50);
                        teller.transfer(from,to,-50);
   //                     Thread.currentThread().yield();
  -//                     System.out.println(idx++);
  +//                     log.debug(idx++);
                     }
                  } catch (Exception e) 
                  {
  @@ -276,7 +279,7 @@
                  synchronized(lock)
                  {
                     iter--;
  -                  System.out.println("Only "+iter+" left");
  +                  log.info("Only "+iter+" left");
                     lock.notifyAll();
                  }
               }
  @@ -295,8 +298,8 @@
         
         long end = System.currentTimeMillis();
         
  -      System.out.println("Time:"+(end-start));
  -      System.out.println("Avg. 
time/call(ms):"+((end-start)/(threadCount*threadIterations*6)));
  +      getLog().info("Time:"+(end-start));
  +      getLog().info("Avg. 
time/call(ms):"+((end-start)/(THREAD_COUNT*ITERATIONS*6)));
      }
      
      public void testTransaction()
  @@ -305,27 +308,27 @@
         TellerHome home = (TellerHome)new 
InitialContext().lookup(TellerHome.JNDI_NAME);
         Teller teller = home.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
         Customer marc = teller.getCustomer("Marc");
  -      System.out.println("Marc acquired");
  +      getLog().debug("Marc acquired");
         Customer rickard = teller.getCustomer("Rickard");
  -      System.out.println("Rickard acquired");
  +      getLog().debug("Rickard acquired");
         
  -      System.out.println("Acquire accounts");
  +      getLog().debug("Acquire accounts");
         Account from = teller.getAccount(marc, 50);
         Account to = teller.getAccount(rickard, 0);
         
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().debug("Show balance");
  +      getLog().debug(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().debug(to.getPrimaryKey()+":"+to.getBalance());
   
  -      System.out.println("Transfer money");
  +      getLog().debug("Transfer money");
         teller.transfer(from, to, 50);
  -      System.out.println("Transfer done");
  +      getLog().debug("Transfer done");
         
  -      System.out.println("Show balance");
  -      
System.out.println(from.getPrimaryKey()+"("+from.getOwner().getName()+"):"+from.getBalance());
  -      
System.out.println(to.getPrimaryKey()+"("+to.getOwner().getName()+"):"+to.getBalance());
  +      getLog().debug("Show balance");
  +      
getLog().debug(from.getPrimaryKey()+"("+from.getOwner().getName()+"):"+from.getBalance());
  +      
getLog().debug(to.getPrimaryKey()+"("+to.getOwner().getName()+"):"+to.getBalance());
         
         teller.remove();
         
  @@ -334,37 +337,35 @@
      public void testTransfer()
         throws Exception
      {
  -      // Nr of transfers
  -      iter = 100;
            
         TellerHome home = (TellerHome)new 
InitialContext().lookup(TellerHome.JNDI_NAME);
         Teller teller = home.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
         Customer marc = teller.getCustomer("Marc");
  -      System.out.println("Marc acquired");
  +      getLog().debug("Marc acquired");
         Customer rickard = teller.getCustomer("Rickard");
  -      System.out.println("Rickard acquired");
  +      getLog().debug("Rickard acquired");
         
  -      System.out.println("Acquire accounts");
  -      Account from = teller.getAccount(marc, 50*iter);
  +      getLog().debug("Acquire accounts");
  +      Account from = teller.getAccount(marc, 50*ITERATIONS);
         Account to = teller.getAccount(rickard, 0);
         
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().debug("Show balance");
  +      getLog().debug(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().debug(to.getPrimaryKey()+":"+to.getBalance());
   
  -      System.out.println("Transfer money");
  +      getLog().info("Transfer money");
         long start = System.currentTimeMillis();
  -      teller.transferTest(from, to, 50, iter);
  +      teller.transferTest(from, to, 50, ITERATIONS);
         long end = System.currentTimeMillis();
  -      System.out.println("Transfer done");
  -      System.out.println("Total time(ms):"+(end-start));
  -      System.out.println("Avg. time/call(ms):"+((end-start)/(iter*2)));
  -      
  -      System.out.println("Show balance");
  -      System.out.println(from.getPrimaryKey()+":"+from.getBalance());
  -      System.out.println(to.getPrimaryKey()+":"+to.getBalance());
  +      getLog().info("Transfer done");
  +      getLog().info("Total time(ms):"+(end-start));
  +      getLog().info("Avg. time/call(ms):"+((end-start)/(ITERATIONS*2)));
  +      
  +      getLog().debug("Show balance");
  +      getLog().debug(from.getPrimaryKey()+":"+from.getBalance());
  +      getLog().debug(to.getPrimaryKey()+":"+to.getBalance());
         
         teller.remove();
      }
  @@ -372,25 +373,23 @@
      public void testReadOnly()
         throws Exception
      {
  -      // Nr of transfers
  -      iter = 100;
            
         TellerHome home = (TellerHome)new 
InitialContext().lookup(TellerHome.JNDI_NAME);
         Teller teller = home.create();
         
  -      System.out.println("Acquire customers");
  +      getLog().debug("Acquire customers");
         Customer marc = teller.getCustomer("Marc");
  -      System.out.println("Marc acquired");
  +      getLog().debug("Marc acquired");
         Customer rickard = teller.getCustomer("Rickard");
  -      System.out.println("Rickard acquired");
  +      getLog().debug("Rickard acquired");
         
  -      System.out.println("Acquire accounts");
  -      Account from = teller.getAccount(marc, 50*iter);
  +      getLog().debug("Acquire accounts");
  +      Account from = teller.getAccount(marc, 50*ITERATIONS);
         Account to = teller.getAccount(rickard, 0);
         
  -      System.out.println("Do read calls");
  +      getLog().info("Do read calls");
         long start = System.currentTimeMillis();
  -      for (int i = 0; i < iter; i++)
  +      for (int i = 0; i < ITERATIONS; i++)
         {
            marc.getName();
            from.getBalance();
  @@ -399,9 +398,9 @@
         }
         long end = System.currentTimeMillis();
         
  -      System.out.println("Calls done");
  -      System.out.println("Total time(ms):"+(end-start));
  -      System.out.println("Avg. time/call(ms):"+((end-start)/(iter*4)));
  +      getLog().info("Calls done");
  +      getLog().info("Total time(ms):"+(end-start));
  +      getLog().info("Avg. time/call(ms):"+((end-start)/(ITERATIONS*4)));
         
         teller.remove();
      }
  @@ -410,41 +409,41 @@
         throws Exception
      {
         // Create a bunch of customers, to test passivation
  -      iter = 200;
            
         CustomerHome home = (CustomerHome)new 
InitialContext().lookup(CustomerHome.JNDI_NAME);
         
  -      System.out.println("Create customers");
  +      getLog().info("Create customers");
         
  -      for (int i = 0; i < iter; i++)
  +      for (int i = 0; i < ITERATIONS; i++)
            home.create(i+"", "Smith_"+i);
  -      System.out.println("Customers created");
  +      getLog().debug("Customers created");
         
      }
      
      public void testFinder()
         throws Exception
      {
  +      //create some accounts
  +      testPassivation();
         AccountHome home = (AccountHome)new 
InitialContext().lookup(AccountHome.JNDI_NAME);
         
  -      System.out.println("Get large accounts");
  +      getLog().info("Get large accounts");
         Iterator enum = home.findLargeAccounts(-1).iterator();
         while (enum.hasNext())
         {
            Account acct = (Account)enum.next();
  -         System.out.println(acct.getOwner().getName()+":"+acct.getBalance());
  +         getLog().debug(acct.getOwner().getName()+":"+acct.getBalance());
         }
      }
        
      protected void setUp()
         throws Exception
      {
  -      if (deployed) return;
  -      // System.out.println("Deploying");
  -      // new org.jboss.jmx.client.Deployer().deploy("../deploy/bank.jar");
  -      deployed = true;
  +      super.setUp();
  +      deployJ2ee("bank.jar");
                
  -      System.out.println("Remove accounts");
  +     
  +      getLog().info("Remove accounts");
         {
            AccountHome home = (AccountHome)new 
InitialContext().lookup(AccountHome.JNDI_NAME);
            Collection accounts = home.findAll();
  @@ -452,12 +451,11 @@
            while(enum.hasNext())
            {
               Account acct = (Account)enum.next();
  -            System.out.println("Removing "+acct.getPrimaryKey());
  +            getLog().debug("Removing "+acct.getPrimaryKey());
               acct.remove();
            }
         }
  -             
  -      System.out.println("Remove customers");
  +      getLog().info("Remove customers");
         {
            CustomerHome home = (CustomerHome)new 
InitialContext().lookup(CustomerHome.JNDI_NAME);
            Collection customers = home.findAll();
  @@ -465,27 +463,16 @@
            while(enum.hasNext())
            {
               Customer cust = (Customer)enum.next();
  -            System.out.println("Removing "+cust.getPrimaryKey());
  +            getLog().debug("Removing "+cust.getPrimaryKey());
               cust.remove();
            }
         }
      }
   
  -   /**
  -    * Setup the test suite.
  -    */
  -   public static Test suite() {
  -      TestSuite suite = new TestSuite();
  -      
  -      // add a test case to deploy our support applications
  -      String filename = "bank.jar";
  -      suite.addTest(new Deploy.Deployer(filename));
  -      
  -      suite.addTest(new TestSuite(BankStressTestCase.class));
  -      
  -      // add a test case to undeploy our support applications
  -      suite.addTest(new Deploy.Undeployer(filename));
  -      
  -      return suite;
  +   protected void tearDown() throws Exception
  +   {
  +      undeployJ2ee("bank.jar");
  +      super.tearDown();
      }
  +
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to