User: starksm
Date: 01/07/17 20:26:27
Modified: src/main/org/jboss/test/lock/test Tag: Branch_2_2 Main.java
Added: src/main/org/jboss/test/lock/test Tag: Branch_2_2
EnterpriseEntityTest.java TestSpin.java
Log:
Update the lock contention tests
Revision Changes Path
No revision
No revision
1.3.4.1 +56 -165 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.3
retrieving revision 1.3.4.1
diff -u -r1.3 -r1.3.4.1
--- Main.java 2001/04/18 19:48:28 1.3
+++ Main.java 2001/07/18 03:26:27 1.3.4.1
@@ -1,171 +1,62 @@
package org.jboss.test.lock.test;
-import java.rmi.*;
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import java.util.HashMap;
-import java.util.StringTokenizer;
+import org.jboss.test.util.Deploy;
-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;
-
-
-public class Main extends junit.framework.TestCase
+public class Main extends TestCase
{
-
- boolean deployed = false;
- int nbThreads;
- int iterations;
- boolean b2b;
- boolean nodeploy;
-
- HashMap param = new HashMap();
- EnterpriseEntity entity;
-
- public static void main(String arg[]) throws Exception {
- Main main = new Main(arg);
-
- main.testLock();
- }
-
- public Main(String arg[]) {
- super("main");
- // scanning parameters
- int i = 0;
- while (i < arg.length) {
- StringTokenizer st = new StringTokenizer (arg[i++], "=");
- param.put (st.nextToken (), st.hasMoreTokens () ?
st.nextToken () : "");
- }
- if (param.containsKey("help") || param.containsKey("-help")) {
- System.out.println("Valid Parameters:");
- System.out.println(" threads=<t> run <t> threads
concurrently (default 2)");
- System.out.println(" iterations=<n> each thread will perform
<n> calls (default 10)");
- System.out.println(" b2b use bean to bean calls
(default: single bean call)");
- System.out.println();
- System.exit(0);
- }
- }
-
- public Main(String name)
- {
- super(name);
- }
-
- protected void setUp() throws Exception
- {
- init(); // get params
- if( nodeploy == false )
- deploy(); // deploy the bean
- }
-
- public void testLock() throws Exception
- {
- Context ctx = new InitialContext();
- EnterpriseEntityHome home =
(EnterpriseEntityHome)ctx.lookup("EnterpriseEntity");
-
- try {
- entity = home.findByPrimaryKey("seb");
- } catch (FinderException e) {
- entity = home.create("seb");
- }
-
- if (b2b) entity.setNextEntity("daniel");
-
- Worker[] threads = new Worker[nbThreads];
-
- System.out.println("Spawning " + nbThreads + " threads for " +
- iterations + " iterations" +
- (b2b ? " with bean to bean call" : " with single bean call"));
-
- for (int i=0; i<nbThreads; i++) {
- threads[i] = new Worker("thread no " + (i+1));
- threads[i].start();
- }
-
- for (int i=0; i<nbThreads; i++) threads[i].join();
- }
-
-
- private void init() {
- nbThreads = 2;
- try {
- nbThreads = Integer.parseInt((String)param.get("threads"));
- } catch (Exception e) {
- // ignore
- }
-
- iterations = 10;
- try {
- iterations = Integer.parseInt((String)param.get("iterations"));
- } catch (Exception e) {
- // ignore
- }
-
- b2b = param.containsKey("b2b");
- nodeploy = param.containsKey("nodeploy");
-
- }
-
-
- protected void deploy() throws Exception {
- if (deployed) return;
-
- System.out.println("_____________________________________________");
- System.out.println();
- System.out.println("jBoss, the EJB Open Source Server");
- System.out.println("Copyright (C), The jBoss Organization, 2000");
- System.out.println("_____________________________________________");
- System.out.println();
- System.out.println("Welcome to the lock test v0.1");
- System.out.println("_____________________________________________");
- System.out.println();
- System.out.print("Deploying the bean...");
- System.out.flush();
- new org.jboss.jmx.client.Deployer().deploy("../deploy/locktest.jar");
- deployed = true;
- System.out.println("done!");
- }
-
-
- public class Worker extends Thread {
- public String name;
- public boolean running;
-
- public Worker(String name) {
- this.name = name;
- running = true;
- }
-
- public void run() {
- long start = System.currentTimeMillis();
- int i;
-
- for (i=0; i<iterations; i++) {
- if (!running) break;
-
- try {
- if (b2b) {
- entity.setAndCopyField(name+" i="+i);
-
- } else {
- entity.setField(name+" i="+i);
-
- }
- System.out.println(name + " " + (i+1) + "
iterations done");
- } catch (Exception e) {
- System.out.println(name + " caught an
exception, dying");
- e.printStackTrace();
- running = false;
- }
- }
-
- long end = System.currentTimeMillis();
- System.out.println(name + ": did " + i + " iterations in " +
(end-start) + "ms");
- }
- }
+ public Main(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Setup the test suite.
+ */
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite();
+ final String filename = "locktest.jar";
+
+ 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));
+ TestSetup setup = new TestSetup(suite)
+ {
+ protected void setUp() throws Exception
+ {
+ System.out.println("+++ Performing the TestSuite setup");
+ Deploy.deploy(filename);
+ }
+ };
+ return setup;
+ }
+
+ 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");
+ }
+ }
}
-
No revision
No revision
1.2.2.1 +229 -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.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- EnterpriseEntityTest.java 2001/07/11 21:44:22 1.2
+++ EnterpriseEntityTest.java 2001/07/18 03:26:27 1.2.2.1
@@ -1,229 +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 = 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);
- }
- }
-}
-
+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.1.2.1 +178 -0 jbosstest/src/main/org/jboss/test/lock/test/Attic/TestSpin.java
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development