User: d_jencks
  Date: 01/09/11 21:55:40

  Added:       src/main/org/jboss/test/lock/test
                        EnterpriseEntityStressTestCase.java
                        SpinUnitTestCase.java
  Removed:     src/main/org/jboss/test/lock/test Main.java TestSpin.java
  Log:
  Changed naming scheme of tests to *UnitTestCase.java for short running tests and 
*StressTestCase.java for lengthy tests.  Made tests-unit and tests-stress targets in 
build.xml
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/lock/test/EnterpriseEntityStressTestCase.java
  
  Index: EnterpriseEntityStressTestCase.java
  ===================================================================
  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 EnterpriseEntityStressTestCase 
     extends TestCase
  {
     public EnterpriseEntityStressTestCase(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));            
  
        // Test ejb.plugins.lock.QueuedPessimisticEJBLock
        suite.addTest(new TestSuite(Entity_Option_A_Queued_Test.class));
        suite.addTest(new TestSuite(Entity_Option_B_Queued_Test.class));
        suite.addTest(new TestSuite(Entity_Option_C_Queued_Test.class));
        suite.addTest(new TestSuite(Entity_Option_D_Queued_Test.class));            
  
        suite.addTest(new TestSuite(Entity_Option_C_Multi_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");
        }
     }
  
     public static class Entity_Option_A_Queued_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_A_Queued_Test(String name) {
           super(name, "EnterpriseEntity_A_Queued");
        }
     }
  
     public static class Entity_Option_B_Queued_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_B_Queued_Test(String name) {
           super(name, "EnterpriseEntity_B_Queued");
        }
     }
  
     public static class Entity_Option_C_Queued_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_C_Queued_Test(String name) {
           super(name, "EnterpriseEntity_C_Queued");
        }
     }
  
     public static class Entity_Option_D_Queued_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_D_Queued_Test(String name) {
           super(name, "EnterpriseEntity_D_Queued");
        }
     }
  
  
     public static class Entity_Option_B_Multi_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_B_Multi_Test(String name) {
           super(name, "EnterpriseEntity_B_Multi");
        }
     }
  
     public static class Entity_Option_C_Multi_Test
        extends EnterpriseEntityTest
     {
        public Entity_Option_C_Multi_Test(String name) {
           super(name, "EnterpriseEntity_C_Multi");
        }
     }
  
  }
  
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/lock/test/SpinUnitTestCase.java
  
  Index: SpinUnitTestCase.java
  ===================================================================
  package org.jboss.test.lock.test;
  
  import java.io.IOException;
  import java.rmi.RemoteException;
  import javax.ejb.CreateException;
  import javax.ejb.RemoveException;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  
  import junit.extensions.TestSetup;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.test.lock.interfaces.EnterpriseEntity;
  import org.jboss.test.lock.interfaces.EnterpriseEntityHome;
  import org.jboss.test.util.Deploy;
  
  /** Test of EJB call invocation overhead.
   
   @author [EMAIL PROTECTED]
   @version $Revision: 1.1 $
   */
  public class SpinUnitTestCase extends junit.framework.TestCase
  {
     public SpinUnitTestCase(String name)
     {
        super(name);
     }
  
     static class Run implements Runnable
     {
         EnterpriseEntity bean;
         Exception ex;
         Run(EnterpriseEntity bean)
         {
             this.bean = bean;
         }
         public synchronized void run()
         {
             notifyAll();
             try
             {
                long start = System.currentTimeMillis();
                bean.sleep(5000);
                long end = System.currentTimeMillis();
                long elapsed = end - start;
                System.out.println(" bean.sleep() time = "+elapsed+" ms");
             }
             catch(Exception e)
             {
                ex = e;
             }
         }
     }
  
     public void testContention() throws Exception
     {
        System.out.println("+++ testContention()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("EnterpriseEntity_A");
        obj = PortableRemoteObject.narrow(obj, EnterpriseEntityHome.class);
        EnterpriseEntityHome home = (EnterpriseEntityHome) obj;
        System.out.println("Found EnterpriseEntityHome @ jndiName=EnterpriseEntity");
        Run r0 = new Run(home.findByPrimaryKey("Bean1"));
        Run r1 = new Run(home.findByPrimaryKey("Bean1"));
        Run r2 = new Run(home.findByPrimaryKey("Bean1"));
        Thread t0 = new Thread(r0);
        Thread t1 = new Thread(r1);
        Thread t2 = new Thread(r2);
        t0.start();
        Thread.sleep(100);
        t1.start();
        Thread.sleep(100);
        t2.start();
        System.out.println("Waiting for t0...");
        try
        {
           t0.join(5000);
           assertTrue( r0.ex == null );
        }
        catch(InterruptedException e)
        {
           System.out.println("Timed out waiting for t1");
        }
        System.out.println("Waiting for t1...");
        try
        {
           t1.join(5000);
           assertTrue( r1.ex == null );
        }
        catch(InterruptedException e)
        {
           System.out.println("Timed out waiting for t1");
        }
        System.out.println("Waiting for t2...");
        try
        {
           t2.join(5000);
           assertTrue( r2.ex == null );
        }
        catch(InterruptedException e)
        {
           System.out.println("Timed out waiting for t2");
        }
  
        System.out.println("End threads");
     }
  
     static void create() throws Exception
     {
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("EnterpriseEntity_A");
        obj = PortableRemoteObject.narrow(obj, EnterpriseEntityHome.class);
        EnterpriseEntityHome home = (EnterpriseEntityHome) obj;
        try
        {
           home.create("Bean1");
        }
        catch(CreateException e)
        {
        }
     }
     static void remove() throws Exception
     {
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("EnterpriseEntity_A");
        obj = PortableRemoteObject.narrow(obj, EnterpriseEntityHome.class);
        EnterpriseEntityHome home = (EnterpriseEntityHome) obj;
        try
        {
           home.remove("Bean1");
        }
        catch(RemoveException e)
        {
        }
     }
     public static Test suite()
     {
        TestSuite suite = new TestSuite();  
        suite.addTest(new TestSuite(SpinUnitTestCase.class));
        final String filename = "locktest.jar";
  
        // Create an initializer for the test suite
        TestSetup setup = new TestSetup(suite)
        {
           protected void setUp() throws Exception
           {
              System.out.println("+++ Performing the TestSuite setup");
              try
              {
                 Deploy.deploy(filename);
                 create();
              }
              catch(Exception e)
              {
                 e.printStackTrace();
                 throw e;
              }
           }
           protected void tearDown() throws Exception
           {
              try
              {
                 remove();
              }
              catch(Exception e)
              {
                 e.printStackTrace();
                 throw e;
              }
           }
        };
        return setup;
     }
  
  }
  
  
  

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

Reply via email to