[jboss-cvs] JBossAS SVN: r96640 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src: test/org/jboss/ejb3/test/stateless/unit and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 20 10:20:13 EST 2009
Author: jaikiran
Date: 2009-11-20 10:20:13 -0500 (Fri, 20 Nov 2009)
New Revision: 96640
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java
Log:
JBPAPP-3120 Fixed the testsuite and ported EJBTHREE-1840, EJBTHREE-1703
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2009-11-20 13:43:25 UTC (rev 96639)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2009-11-20 15:20:13 UTC (rev 96640)
@@ -24,6 +24,7 @@
import org.jboss.injection.Injector;
import org.jboss.annotation.ejb.cache.tree.CacheConfig;
import org.jboss.aop.Advisor;
+import org.jboss.ejb3.BeanContext;
import org.jboss.ejb3.stateful.StatefulBeanContext;
import org.jboss.logging.Logger;
import org.jboss.util.id.GUID;
@@ -215,20 +216,12 @@
public void remove(BeanContext ctx)
{
- try
- {
- container.invokePreDestroy(ctx);
- }
- finally
- {
- ctx.remove();
- ++removeCount;
- }
+ this.doRemove(ctx);
}
public void discard(BeanContext ctx)
{
- remove(ctx);
+ this.doRemove(ctx);
}
public void setInjectors(Injector[] injectors)
@@ -245,4 +238,23 @@
{
return removeCount;
}
+
+ /**
+ * Remove the bean context and invoke any callbacks
+ * and track the remove count
+ *
+ * @param ctx
+ */
+ protected void doRemove(BeanContext ctx)
+ {
+ try
+ {
+ container.invokePreDestroy(ctx);
+ }
+ finally
+ {
+ ctx.remove();
+ ++removeCount;
+ }
+ }
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2009-11-20 13:43:25 UTC (rev 96639)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2009-11-20 15:20:13 UTC (rev 96640)
@@ -240,8 +240,8 @@
strictMaxSize.release();
--inUse;
- // Throw away, unsetContext()
- super.discard(ctx);
+ // Let the super do any other remove stuff
+ super.doRemove(ctx);
}
// Package protected ---------------------------------------------
@@ -288,6 +288,7 @@
strictMaxSize.release();
--inUse;
- super.remove(ctx);
+ // let the super do the other remove stuff
+ super.doRemove(ctx);
}
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java 2009-11-20 13:43:25 UTC (rev 96639)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java 2009-11-20 15:20:13 UTC (rev 96640)
@@ -47,6 +47,11 @@
public void testDefaultJmxMetrics() throws Exception
{
+ // The default pool used by a SLSB is the ThreadLocalPool
+ // For a detailed explanation about what each metric value
+ // means when a ThreadLocalPool is used, check the comments
+ // from carlo in this JIRA https://jira.jboss.org/jira/browse/EJBTHREE-1703
+
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.j2ee:jar=stateless-test.jar,name=DefaultPoolStatelessBean,service=EJB3");
@@ -66,10 +71,10 @@
assertEquals(1, size);
size = (Integer)server.getAttribute(testerName, "AvailableCount");
- assertEquals(30, size);
+ assertEquals(1, size);
size = (Integer)server.getAttribute(testerName, "MaxSize");
- assertEquals(30, size);
+ assertEquals(1, size);
size = (Integer)server.getAttribute(testerName, "CreateCount");
assertEquals(1, size);
@@ -104,15 +109,17 @@
size = (Integer)server.getAttribute(testerName, "MaxSize");
assertEquals(3, size);
- size = (Integer)server.getAttribute(testerName, "CreateCount");
- assertEquals(1, size);
+ int createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+ assertEquals(1, createCount);
runConcurrentTests(20, 1);
int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
- assertEquals(1, size);
+
checkMetrics(server, testerName, currentSize, 3, 3, currentSize, 0);
+
+ createCount = (Integer)server.getAttribute(testerName, "CreateCount");
for (int i = 1 ; i <= 10 ; ++i)
{
@@ -129,13 +136,44 @@
}
}
+ // New instances should have been created in the loop above,
+ // since 10 bean instances were discarded because of exception.
+ int createCountAfterExceptionOnBeanInstances = (Integer)server.getAttribute(testerName, "CreateCount");
+ assertTrue("New instances not created", createCountAfterExceptionOnBeanInstances > createCount);
+
+
+ // 10 method calls led to exceptions so 10 bean instances would be removed
+ int removedCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+ assertEquals("Removed count does not match", 10, removedCount);
+
+ // current size (created - removed) should now be zero
+ // since all the created ones have been removed after exception
+ currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+ assertEquals("Current size is incorrect", 0, currentSize);
+
+ // none of the instances are in use, so available count should be
+ // max (=3)
+ int availableCount = (Integer) server.getAttribute(testerName, "AvailableCount");
+ assertEquals("Available count does not match", 3, availableCount);
+
+
+ // one more round of concurrent invocations
runConcurrentTests(20, 1);
+
+ // again there should be no "inUse" instances and hence available count
+ // should be equal to max (=3)
+ availableCount = (Integer) server.getAttribute(testerName, "AvailableCount");
+ assertEquals("Available count not matching", 3, availableCount);
+
+ // some new instances should have been created in runconcurrent tests,
+ // since all the bean instances were earlier removed because of exception.
+ // We won't know the exact count because of the thread concurrency involved
+ // but the create count should definitely be greater than the earlier
+ // create count
+ createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+ assertTrue("Create count does not match after concurrent test",createCount > createCountAfterExceptionOnBeanInstances);
+
- currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
- assertEquals(1, size);
-
- checkMetrics(server, testerName, currentSize, 3, 3, currentSize + 10, 10);
-
Runnable r = new Runnable()
{
public void run()
@@ -159,7 +197,7 @@
int maxSize = (Integer)server.getAttribute(testerName, "MaxSize");
System.out.println("MaxSize=" + maxSize);
- int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+ availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
System.out.println("AvailableCount=" + availableCount);
assertEquals(maxSize - 1, availableCount);
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java 2009-11-20 13:43:25 UTC (rev 96639)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java 2009-11-20 15:20:13 UTC (rev 96640)
@@ -110,6 +110,10 @@
public void testThreadLocalPoolJmxMetrics() throws Exception
{
+ // For a detailed explanation about what each metric value
+ // means when a ThreadLocalPool is used, check the comments
+ // from carlo in this JIRA https://jira.jboss.org/jira/browse/EJBTHREE-1703
+
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.j2ee:jar=statelesscreation-test.jar,name=ThreadLocalPoolStatelessBean,service=EJB3");
int size = 0;
@@ -128,10 +132,10 @@
assertEquals(1, currentSize);
size = (Integer)server.getAttribute(testerName, "AvailableCount");
- assertEquals(20, size);
+ assertEquals(1, size);
size = (Integer)server.getAttribute(testerName, "MaxSize");
- assertEquals(20, size);
+ assertEquals(1, size);
size = (Integer)server.getAttribute(testerName, "CreateCount");
assertEquals(1, size);
More information about the jboss-cvs-commits
mailing list