User: starksm 
  Date: 01/07/11 14:44:22

  Modified:    src/main/org/jboss/test/lock/test EnterpriseEntityTest.java
                        Main.java
  Log:
  Restore all lock tests and comment out the logging in the bean as
  it just drowns out any trace info enabled in the core packages.
  
  Revision  Changes    Path
  1.2       +229 -197  
jbosstest/src/main/org/jboss/test/lock/test/EnterpriseEntityTest.java
  
  Index: EnterpriseEntityTest.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/lock/test/EnterpriseEntityTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EnterpriseEntityTest.java 2001/07/11 05:52:08     1.1
  +++ EnterpriseEntityTest.java 2001/07/11 21:44:22     1.2
  @@ -1,197 +1,229 @@
  -package org.jboss.test.lock.test;
  -
  -import java.rmi.*;
  -
  -import java.util.HashMap;
  -import java.util.StringTokenizer;
  -
  -import javax.naming.Context;
  -import javax.naming.InitialContext;
  -
  -import javax.ejb.FinderException;
  -
  -import org.jboss.test.lock.interfaces.EnterpriseEntityHome;
  -import org.jboss.test.lock.interfaces.EnterpriseEntity;
  -
  -import junit.framework.Test;
  -import junit.framework.Assert;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
  -
  -import org.jboss.test.util.Deploy;
  -
  -public abstract class EnterpriseEntityTest
  -   extends TestCase
  -{
  -   public static final int DEFAULT_THREAD_COUNT = 10;
  -   public static final int DEFAULT_ITERATIONS = 20;
  -
  -   private String jndiname;
  -   
  -   /** The number of threads to test with. */
  -   private int nbThreads;
  -
  -   /** The number of iterations each thread will go through */
  -   private int iterations;
  -
  -   private Worker[] threads;
  -   
  -   private HashMap param = new HashMap();
  -   
  -   private EnterpriseEntity entity;
  -
  -   private boolean failed;
  -   
  -   public EnterpriseEntityTest(final String name,
  -                               final String jndiname)
  -   {
  -      super(name);
  -      this.jndiname = jndiname;
  -   }
  -
  -   protected void setUp() throws Exception
  -   {
  -      nbThreads = DEFAULT_THREAD_COUNT;
  -      iterations = DEFAULT_ITERATIONS;
  -
  -      // get a handle on an entity bean
  -      Context ctx = new InitialContext();
  -      try {
  -         EnterpriseEntityHome home =
  -            (EnterpriseEntityHome)ctx.lookup(jndiname);
  -                     
  -         try {
  -            entity = home.findByPrimaryKey("seb");
  -         } catch (FinderException e) {
  -            entity = home.create("seb");
  -         }
  -      }
  -      finally {
  -         ctx.close();
  -      }
  -
  -      // setup the threads
  -      threads = new Worker[nbThreads];
  -   }
  -
  -   protected void tearDown() throws Exception {
  -      // ???
  -   }
  -
  -   protected void startAll(Task prototype) throws Exception {
  -      for (int i=0; i<nbThreads; i++) {
  -         Task task = (Task)prototype.clone();
  -         threads[i] = new Worker("Thread #" + (i+1), task);
  -         threads[i].start();
  -      }
  -   }
  -
  -   protected void joinAll() throws Exception {
  -      // wait for all the threads to finish
  -      for (int i=0; i<nbThreads; i++) {
  -         threads[i].join();
  -      }
  -   }
  -
  -   protected void run(Task prototype) throws Exception {
  -      startAll(prototype);
  -      joinAll();
  -      Assert.assert(!failed);
  -   }
  -   
  -   protected synchronized void setFailed() {
  -      failed = true;
  -   }
  -
  -   protected boolean hasFailed() {
  -      return failed;
  -   }
  -   
  -   public void testSingleBean() throws Exception
  -   {         
  -      System.out.println("Spawning " + nbThreads + " threads for " + 
  -                         iterations + " iterations with single bean call");
  -
  -      Task prototype = new Task() {
  -            public void run(String name, int i) throws Exception {
  -               entity.setField(name+" i="+i);
  -            }
  -         };
  -
  -      run(prototype);
  -   }
  -
  -   public void testB2B() throws Exception
  -   {         
  -      System.out.println("Spawning " + nbThreads + " threads for " + 
  -                         iterations + " iterations with bean to bean call");
  -
  -      entity.setNextEntity("daniel");
  -                     
  -      Task prototype = new Task() {      
  -            public void run(String name, int i) throws Exception {
  -               entity.setAndCopyField(name+" i="+i);
  -            }
  -         };
  -
  -      run(prototype);      
  -   }
  -   
  -   
  -   /////////////////////////////////////////////////////////////////////////
  -   //                        Iteration Worker & Task                      //
  -   /////////////////////////////////////////////////////////////////////////
  -   
  -   public abstract class Task
  -      implements Cloneable
  -   {
  -      public abstract void run(String name, int i) throws Exception;
  -
  -      public Object clone() {
  -         try {
  -            return super.clone();
  -         }
  -         catch (CloneNotSupportedException e) {
  -            throw new InternalError();
  -         }
  -      }
  -   }
  -   
  -   public class Worker
  -      extends Thread
  -   {
  -      public String name;
  -      public boolean running;
  -      public Task task;
  -      
  -      public Worker(final String name, final Task task) {
  -         this.name = name;
  -         this.task = task;
  -         running = true;
  -      }
  -      
  -      public void run() {
  -         long start = System.currentTimeMillis();
  -         int i;
  -         
  -         for (i=0; i<iterations; i++) {
  -            if (!running || hasFailed()) break;
  -            
  -            try {
  -               task.run(name, i); 
  -               // System.out.println(name + " " + (i+1) + " iterations done");
  -            } catch (Throwable t) {
  -               System.out.println(name + " caught an exception, dying");
  -               t.printStackTrace();
  -               running = false;
  -               setFailed();
  -            }
  -         }
  -         
  -         long end = System.currentTimeMillis();
  -         System.out.println(name + ": did " + i +
  -                            " iterations in " + (end-start) + "ms");
  -      }
  -   }
  -}
  -
  +package org.jboss.test.lock.test;
  +
  +import java.rmi.*;
  +
  +import java.util.HashMap;
  +import java.util.StringTokenizer;
  +
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
  +
  +import javax.ejb.FinderException;
  +
  +import org.jboss.test.lock.interfaces.EnterpriseEntityHome;
  +import org.jboss.test.lock.interfaces.EnterpriseEntity;
  +
  +import junit.framework.Test;
  +import junit.framework.Assert;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
  +import org.jboss.test.util.Deploy;
  +
  +public abstract class EnterpriseEntityTest
  +   extends TestCase
  +{
  +   public static final int DEFAULT_THREAD_COUNT = 20;
  +   public static final int DEFAULT_ITERATIONS = 10;
  +
  +   private String jndiname;
  +   
  +   /** The number of threads to test with. */
  +   private int nbThreads;
  +   private int completedThreads;
  +
  +   /** The number of iterations each thread will go through */
  +   private int iterations;
  +
  +   private Worker[] threads;
  +   
  +   private HashMap param = new HashMap();
  +   
  +   private EnterpriseEntity entity;
  +
  +   private boolean failed;
  +   
  +   public EnterpriseEntityTest(final String name,
  +                               final String jndiname)
  +   {
  +      super(name);
  +      this.jndiname = jndiname;
  +   }
  +
  +   protected void setUp() throws Exception
  +   {
  +      nbThreads = DEFAULT_THREAD_COUNT;
  +      iterations = DEFAULT_ITERATIONS;
  +      System.out.println("+++ Setting up: "+getClass().getName()+" test: "+name());
  +      // get a handle on an entity bean
  +      Context ctx = new InitialContext();
  +      try
  +      {
  +         EnterpriseEntityHome home =
  +            (EnterpriseEntityHome)ctx.lookup(jndiname);
  +                     
  +         try
  +         {
  +            entity = home.findByPrimaryKey("seb");
  +         }
  +         catch (FinderException e)
  +         {
  +            entity = home.create("seb");
  +         }
  +      }
  +      finally
  +      {
  +         ctx.close();
  +      }
  +
  +      // setup the threads
  +      threads = new Worker[nbThreads];
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      // ???
  +   }
  +
  +   protected void startAll(Task prototype) throws Exception
  +   {
  +      completedThreads = 0;
  +      for (int i=0; i<nbThreads; i++)
  +      {
  +         Task task = (Task)prototype.clone();
  +         threads[i] = new Worker("Thread #" + (i+1), task);
  +         threads[i].start();
  +      }
  +   }
  +
  +   protected void joinAll() throws Exception
  +   {
  +      // wait for all the threads to finish
  +      for (int i=0; i<nbThreads; i++)
  +      {
  +         threads[i].join();
  +      }
  +   }
  +
  +   protected void run(Task prototype) throws Exception
  +   {
  +      startAll(prototype);
  +      joinAll();
  +      Assert.assert(!failed);
  +   }
  +   
  +   protected synchronized void setFailed()
  +   {
  +      failed = true;
  +   }
  +
  +   protected boolean hasFailed()
  +   {
  +      return failed;
  +   }
  +
  +   public void testSingleBean() throws Exception
  +   {         
  +      System.out.println("Spawning " + nbThreads + " threads for " + 
  +                         iterations + " iterations with single bean call");
  +
  +      Task prototype = new Task()
  +      {
  +            public void run(String name, int i) throws Exception
  +            {
  +               entity.setField(name+" i="+i);
  +            }
  +      };
  +
  +      run(prototype);
  +   }
  +
  +   public void testB2B() throws Exception
  +   {         
  +      System.out.println("Spawning " + nbThreads + " threads for " + 
  +                         iterations + " iterations with bean to bean call");
  +
  +      entity.setNextEntity("daniel");
  +                     
  +      Task prototype = new Task()
  +      {      
  +            public void run(String name, int i) throws Exception
  +            {
  +               entity.setAndCopyField(name+" i="+i);
  +            }
  +         };
  +
  +      run(prototype);      
  +   }
  +   
  +   
  +   /////////////////////////////////////////////////////////////////////////
  +   //                        Iteration Worker & Task                      //
  +   /////////////////////////////////////////////////////////////////////////
  +   
  +   public abstract class Task
  +      implements Cloneable
  +   {
  +      public abstract void run(String name, int i) throws Exception;
  +
  +      public Object clone()
  +      {
  +         try
  +         {
  +            return super.clone();
  +         }
  +         catch (CloneNotSupportedException e)
  +         {
  +            throw new InternalError();
  +         }
  +      }
  +   }
  +   
  +   public class Worker
  +      extends Thread
  +   {
  +      public String name;
  +      public boolean running;
  +      public Task task;
  +      
  +      public Worker(final String name, final Task task)
  +      {
  +         this.name = name;
  +         this.task = task;
  +         running = true;
  +      }
  +      
  +      public void run()
  +      {
  +         long start = System.currentTimeMillis();
  +         int i;
  +         
  +         for (i=0; i<iterations; i++)
  +         {
  +            if (!running || hasFailed()) break;
  +            
  +            try
  +            {
  +               task.run(name, i); 
  +               // System.out.println(name + " " + (i+1) + " iterations done");
  +            }
  +            catch (Throwable t)
  +            {
  +               System.out.println(name + " caught an exception, dying");
  +               t.printStackTrace();
  +               running = false;
  +               setFailed();
  +            }
  +         }
  +
  +         synchronized(this)
  +         {
  +            completedThreads ++;
  +         }
  +         long end = System.currentTimeMillis();
  +         System.out.println(name + ": did " + i +
  +                            " iterations in " + (end-start) + "ms, 
complete="+completedThreads);
  +      }
  +   }
  +}
  +
  
  
  
  1.7       +69 -69    jbosstest/src/main/org/jboss/test/lock/test/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/lock/test/Main.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java 2001/07/11 05:52:08     1.6
  +++ Main.java 2001/07/11 21:44:22     1.7
  @@ -1,69 +1,69 @@
  -package org.jboss.test.lock.test;
  -
  -import junit.framework.Test;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
  -
  -import org.jboss.test.util.Deploy;
  -
  -public class Main 
  -   extends TestCase
  -{
  -   public Main(String name) {
  -      super(name);
  -   }
  -   
  -   /**
  -    * Setup the test suite.
  -    */
  -   public static Test suite() {
  -      TestSuite suite = new TestSuite();
  -        
  -      // add a test case to deploy our support applications
  -      String filename = "locktest.jar";
  -      suite.addTest(new Deploy.Deployer(filename));
  -
  -      suite.addTest(new TestSuite(Entity_Option_A_Test.class));
  -      suite.addTest(new TestSuite(Entity_Option_B_Test.class));
  -      // suite.addTest(new TestSuite(Entity_Option_C_Test.class));
  -      // suite.addTest(new TestSuite(Entity_Option_D_Test.class));            
  -
  -      // add a test case to undeploy our support applications
  -      suite.addTest(new Deploy.Undeployer(filename));
  -      
  -      return suite;
  -   }
  -
  -   public static class Entity_Option_A_Test
  -      extends EnterpriseEntityTest
  -   {
  -      public Entity_Option_A_Test(String name) {
  -         super(name, "EnterpriseEntity_A");
  -      }
  -   }
  -
  -   public static class Entity_Option_B_Test
  -      extends EnterpriseEntityTest
  -   {
  -      public Entity_Option_B_Test(String name) {
  -         super(name, "EnterpriseEntity_B");
  -      }
  -   }
  -
  -   public static class Entity_Option_C_Test
  -      extends EnterpriseEntityTest
  -   {
  -      public Entity_Option_C_Test(String name) {
  -         super(name, "EnterpriseEntity_C");
  -      }
  -   }
  -
  -   public static class Entity_Option_D_Test
  -      extends EnterpriseEntityTest
  -   {
  -      public Entity_Option_D_Test(String name) {
  -         super(name, "EnterpriseEntity_D");
  -      }
  -   }
  -}
  -
  +package org.jboss.test.lock.test;
  +
  +import junit.framework.Test;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
  +import org.jboss.test.util.Deploy;
  +
  +public class Main 
  +   extends TestCase
  +{
  +   public Main(String name) {
  +      super(name);
  +   }
  +   
  +   /**
  +    * Setup the test suite.
  +    */
  +   public static Test suite() {
  +      TestSuite suite = new TestSuite();
  +        
  +      // add a test case to deploy our support applications
  +      String filename = "locktest.jar";
  +      suite.addTest(new Deploy.Deployer(filename));
  +
  +      suite.addTest(new TestSuite(Entity_Option_A_Test.class));
  +      suite.addTest(new TestSuite(Entity_Option_B_Test.class));
  +      suite.addTest(new TestSuite(Entity_Option_C_Test.class));
  +      suite.addTest(new TestSuite(Entity_Option_D_Test.class));            
  +
  +      // add a test case to undeploy our support applications
  +      suite.addTest(new Deploy.Undeployer(filename));
  +      
  +      return suite;
  +   }
  +
  +   public static class Entity_Option_A_Test
  +      extends EnterpriseEntityTest
  +   {
  +      public Entity_Option_A_Test(String name) {
  +         super(name, "EnterpriseEntity_A");
  +      }
  +   }
  +
  +   public static class Entity_Option_B_Test
  +      extends EnterpriseEntityTest
  +   {
  +      public Entity_Option_B_Test(String name) {
  +         super(name, "EnterpriseEntity_B");
  +      }
  +   }
  +
  +   public static class Entity_Option_C_Test
  +      extends EnterpriseEntityTest
  +   {
  +      public Entity_Option_C_Test(String name) {
  +         super(name, "EnterpriseEntity_C");
  +      }
  +   }
  +
  +   public static class Entity_Option_D_Test
  +      extends EnterpriseEntityTest
  +   {
  +      public Entity_Option_D_Test(String name) {
  +         super(name, "EnterpriseEntity_D");
  +      }
  +   }
  +}
  +
  
  
  

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

Reply via email to