User: d_jencks
Date: 01/09/15 08:07:10
Modified: src/main/org/jboss/test/lock/test
EnterpriseEntityStressTestCase.java
EnterpriseEntityTest.java SpinUnitTestCase.java
Log:
Made to work, changed to JBossTestCase and logging.
Revision Changes Path
1.2 +229 -127
jbosstest/src/main/org/jboss/test/lock/test/EnterpriseEntityStressTestCase.java
Index: EnterpriseEntityStressTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/lock/test/EnterpriseEntityStressTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnterpriseEntityStressTestCase.java 2001/09/12 04:55:40 1.1
+++ EnterpriseEntityStressTestCase.java 2001/09/15 15:07:10 1.2
@@ -1,127 +1,229 @@
-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");
- }
- }
-
-}
-
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.lock.test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * #Description of the Class
+ */
+public class EnterpriseEntityStressTestCase
+ extends JBossTestCase
+{
+ /**
+ * Constructor for the EnterpriseEntityStressTestCase object
+ *
+ * @param name Description of Parameter
+ */
+ public EnterpriseEntityStressTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Setup the test suite.
+ *
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite();
+
+
+ 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));
+
+ return suite;
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_A_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_A_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_A_Test(String name)
+ {
+ super(name, "EnterpriseEntity_A");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_B_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_B_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_B_Test(String name)
+ {
+ super(name, "EnterpriseEntity_B");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_C_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_C_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_C_Test(String name)
+ {
+ super(name, "EnterpriseEntity_C");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_D_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_D_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_D_Test(String name)
+ {
+ super(name, "EnterpriseEntity_D");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_A_Queued_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_A_Queued_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_A_Queued_Test(String name)
+ {
+ super(name, "EnterpriseEntity_A_Queued");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_B_Queued_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_B_Queued_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_B_Queued_Test(String name)
+ {
+ super(name, "EnterpriseEntity_B_Queued");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_C_Queued_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_C_Queued_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_C_Queued_Test(String name)
+ {
+ super(name, "EnterpriseEntity_C_Queued");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_D_Queued_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_D_Queued_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_D_Queued_Test(String name)
+ {
+ super(name, "EnterpriseEntity_D_Queued");
+ }
+ }
+
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_B_Multi_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_B_Multi_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_B_Multi_Test(String name)
+ {
+ super(name, "EnterpriseEntity_B_Multi");
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public static class Entity_Option_C_Multi_Test
+ extends EnterpriseEntityTest
+ {
+ /**
+ * Constructor for the Entity_Option_C_Multi_Test object
+ *
+ * @param name Description of Parameter
+ */
+ public Entity_Option_C_Multi_Test(String name)
+ {
+ super(name, "EnterpriseEntity_C_Multi");
+ }
+ }
+
+}
+
1.4 +362 -229
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EnterpriseEntityTest.java 2001/09/07 10:26:44 1.3
+++ EnterpriseEntityTest.java 2001/09/15 15:07:10 1.4
@@ -1,229 +1,362 @@
-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:
"+getName());
- // 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();
- assertTrue(!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);
- }
- }
-}
-
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.lock.test;
+
+import java.rmi.*;
+
+import java.util.HashMap;
+import java.util.StringTokenizer;
+
+import javax.ejb.FinderException;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import junit.framework.Assert;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Category;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.lock.interfaces.EnterpriseEntity;
+
+import org.jboss.test.lock.interfaces.EnterpriseEntityHome;
+
+/**
+ * #Description of the Class
+ */
+public abstract class EnterpriseEntityTest
+ extends JBossTestCase
+{
+ /**
+ * Description of the Field
+ */
+ public final static int DEFAULT_THREAD_COUNT = 20;
+ /**
+ * Description of the Field
+ */
+ public final static 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;
+
+ /**
+ * Constructor for the EnterpriseEntityTest object
+ *
+ * @param name Description of Parameter
+ * @param jndiname Description of Parameter
+ */
+ public EnterpriseEntityTest(final String name,
+ final String jndiname)
+ {
+ super(name);
+ this.jndiname = jndiname;
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testSingleBean() throws Exception
+ {
+ getLog().debug("Spawning " + nbThreads + " threads for " +
+ iterations + " iterations with single bean call");
+
+ Task prototype =
+ new Task()
+ {
+ /**
+ * Main processing method for the EnterpriseEntityTest object
+ *
+ * @param name Description of Parameter
+ * @param i Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void run(String name, int i) throws Exception
+ {
+ entity.setField(name + " i=" + i);
+ }
+ };
+
+ run(prototype);
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ public void testB2B() throws Exception
+ {
+ getLog().debug("Spawning " + nbThreads + " threads for " +
+ iterations + " iterations with bean to bean call");
+
+ entity.setNextEntity("daniel");
+
+ Task prototype =
+ new Task()
+ {
+ /**
+ * Main processing method for the EnterpriseEntityTest object
+ *
+ * @param name Description of Parameter
+ * @param i Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public void run(String name, int i) throws Exception
+ {
+ entity.setAndCopyField(name + " i=" + i);
+ }
+ };
+
+ run(prototype);
+ }
+
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ deployJ2ee("locktest.jar");
+ nbThreads = DEFAULT_THREAD_COUNT;
+ iterations = DEFAULT_ITERATIONS;
+ getLog().debug("+++ Setting up: " + getClass().getName() + " test: " +
getName());
+ // 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];
+ }
+
+ /**
+ * Sets the Failed attribute of the EnterpriseEntityTest object
+ */
+ protected synchronized void setFailed()
+ {
+ failed = true;
+ }
+
+ /**
+ * The teardown method for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void tearDown() throws Exception
+ {
+ undeployJ2ee("locktest.jar");
+ super.tearDown();
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @param prototype Description of Parameter
+ * @exception Exception Description of 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, getLog());
+ threads[i].start();
+ }
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void joinAll() throws Exception
+ {
+ // wait for all the threads to finish
+ for (int i = 0; i < nbThreads; i++)
+ {
+ threads[i].join();
+ }
+ }
+
+ /**
+ * Main processing method for the EnterpriseEntityTest object
+ *
+ * @param prototype Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ protected void run(Task prototype) throws Exception
+ {
+ startAll(prototype);
+ joinAll();
+ assertTrue(!failed);
+ }
+
+ /**
+ * #Description of the Method
+ *
+ * @return Description of the Returned Value
+ */
+ protected boolean hasFailed()
+ {
+ return failed;
+ }
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // Iteration Worker & Task //
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * #Description of the Class
+ */
+ public abstract class Task
+ implements Cloneable
+ {
+ /**
+ * Main processing method for the Task object
+ *
+ * @param name Description of Parameter
+ * @param i Description of Parameter
+ * @exception Exception Description of Exception
+ */
+ public abstract void run(String name, int i) throws Exception;
+
+ /**
+ * #Description of the Method
+ *
+ * @return Description of the Returned Value
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new InternalError();
+ }
+ }
+ }
+
+ /**
+ * #Description of the Class
+ */
+ public class Worker
+ extends Thread
+ {
+ /**
+ * Description of the Field
+ */
+ public String name;
+ /**
+ * Description of the Field
+ */
+ public boolean running;
+ /**
+ * Description of the Field
+ */
+ public Task task;
+
+ private Category log;
+
+ /**
+ * Constructor for the Worker object
+ *
+ * @param name Description of Parameter
+ * @param task Description of Parameter
+ * @param log Description of Parameter
+ */
+ public Worker(final String name, final Task task, Category log)
+ {
+ this.name = name;
+ this.task = task;
+ this.log = log;
+ running = true;
+ }
+
+ /**
+ * Main processing method for the Worker object
+ */
+ public void run()
+ {
+ long start = System.currentTimeMillis();
+ int i;
+
+ for (i = 0; i < iterations; i++)
+ {
+ if (!running || hasFailed())
+ {
+ break;
+ }
+
+ try
+ {
+ task.run(name, i);
+ //log.debug(name + " " + (i+1) + " iterations done");
+ }
+ catch (Throwable t)
+ {
+ log.error(name + " caught an exception, dying", t);
+ running = false;
+ setFailed();
+ }
+ }
+
+ synchronized (this)
+ {
+ completedThreads++;
+ }
+ long end = System.currentTimeMillis();
+ log.debug(name + ": did " + i +
+ " iterations in " + (end - start) + "ms, complete=" +
completedThreads);
+ }
+ }
+}
+
1.2 +126 -92
jbosstest/src/main/org/jboss/test/lock/test/SpinUnitTestCase.java
Index: SpinUnitTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/lock/test/SpinUnitTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SpinUnitTestCase.java 2001/09/12 04:55:40 1.1
+++ SpinUnitTestCase.java 2001/09/15 15:07:10 1.2
@@ -1,3 +1,9 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.test.lock.test;
import java.io.IOException;
@@ -12,60 +18,76 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.log4j.Category;
+import org.jboss.test.JBossTestCase;
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 $
+/**
+ * Test of EJB call invocation overhead.
+ *
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.2 $
*/
-public class SpinUnitTestCase extends junit.framework.TestCase
+public class SpinUnitTestCase extends JBossTestCase
{
+ /**
+ * Constructor for the SpinUnitTestCase object
+ *
+ * @param name Description of Parameter
+ */
public SpinUnitTestCase(String name)
{
super(name);
}
- static class Run implements Runnable
+ static void create() throws Exception
{
- 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;
- }
- }
+ 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)
+ {
+ }
+ }
+
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
public void testContention() throws Exception
{
- System.out.println("+++ testContention()");
+ getLog().debug("+++ 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"));
+ EnterpriseEntityHome home = (EnterpriseEntityHome)obj;
+ getLog().debug("Found EnterpriseEntityHome @ jndiName=EnterpriseEntity");
+ Run r0 = new Run(home.findByPrimaryKey("Bean1"), getLog());
+ Run r1 = new Run(home.findByPrimaryKey("Bean1"), getLog());
+ Run r2 = new Run(home.findByPrimaryKey("Bean1"), getLog());
Thread t0 = new Thread(r0);
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
@@ -74,105 +96,117 @@
t1.start();
Thread.sleep(100);
t2.start();
- System.out.println("Waiting for t0...");
+ getLog().debug("Waiting for t0...");
try
{
t0.join(5000);
- assertTrue( r0.ex == null );
+ assertTrue(r0.ex == null);
}
- catch(InterruptedException e)
+ catch (InterruptedException e)
{
- System.out.println("Timed out waiting for t1");
+ getLog().debug("Timed out waiting for t1");
}
- System.out.println("Waiting for t1...");
+ getLog().debug("Waiting for t1...");
try
{
t1.join(5000);
- assertTrue( r1.ex == null );
+ assertTrue(r1.ex == null);
}
- catch(InterruptedException e)
+ catch (InterruptedException e)
{
- System.out.println("Timed out waiting for t1");
+ getLog().debug("Timed out waiting for t1");
}
- System.out.println("Waiting for t2...");
+ getLog().debug("Waiting for t2...");
try
{
t2.join(5000);
- assertTrue( r2.ex == null );
+ assertTrue(r2.ex == null);
}
- catch(InterruptedException e)
+ catch (InterruptedException e)
{
- System.out.println("Timed out waiting for t2");
+ getLog().debug("Timed out waiting for t2");
}
- System.out.println("End threads");
+ getLog().debug("End threads");
}
- static void create() throws Exception
+ /**
+ * The JUnit setup method
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void setUp() 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");
+ super.setUp();
+ getLog().debug("+++ Performing the TestSuite setup");
+ deployJ2ee("locktest.jar");
+ //Deploy.deploy(filename);
+ create();
}
- catch(CreateException e)
+ catch (Exception e)
{
+ e.printStackTrace();
+ throw e;
}
}
- static void remove() throws Exception
+
+ /**
+ * The teardown method for JUnit
+ *
+ * @exception Exception Description of Exception
+ */
+ protected void tearDown() 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");
+ remove();
+ undeployJ2ee("locktest.jar");
+ super.tearDown();
+
}
- catch(RemoveException e)
+ catch (Exception e)
{
+ e.printStackTrace();
+ throw e;
}
}
- public static Test suite()
+
+ /**
+ * #Description of the Class
+ */
+ static class Run implements Runnable
{
- TestSuite suite = new TestSuite();
- suite.addTest(new TestSuite(SpinUnitTestCase.class));
- final String filename = "locktest.jar";
+ EnterpriseEntity bean;
+ Exception ex;
+ private Category log;
- // Create an initializer for the test suite
- TestSetup setup = new TestSetup(suite)
+ Run(EnterpriseEntity bean, Category log)
{
- protected void setUp() throws Exception
+ this.bean = bean;
+ this.log = log;
+ }
+
+ /**
+ * Main processing method for the Run object
+ */
+ public synchronized void run()
+ {
+ notifyAll();
+ try
{
- System.out.println("+++ Performing the TestSuite setup");
- try
- {
- Deploy.deploy(filename);
- create();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw e;
- }
+ long start = System.currentTimeMillis();
+ bean.sleep(5000);
+ long end = System.currentTimeMillis();
+ long elapsed = end - start;
+ log.debug(" bean.sleep() time = " + elapsed + " ms");
}
- protected void tearDown() throws Exception
+ catch (Exception e)
{
- try
- {
- remove();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- throw e;
- }
+ ex = e;
}
- };
- return setup;
+ }
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development