[jboss-cvs] JBossAS SVN: r82515 - projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 23 06:40:44 EST 2008
Author: wolfc
Date: 2008-12-23 06:40:43 -0500 (Tue, 23 Dec 2008)
New Revision: 82515
Modified:
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
Log:
EJBTHREE-1241: keep previously injected beans in mind
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java 2008-12-23 11:23:02 UTC (rev 82514)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java 2008-12-23 11:40:43 UTC (rev 82515)
@@ -24,16 +24,13 @@
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
+import junit.framework.Test;
+
import org.jboss.ejb3.test.stateful.Stateful;
-
import org.jboss.logging.Logger;
-import org.jboss.test.JBossTestCase;
-import junit.framework.Test;
-
-import org.jboss.security.SimplePrincipal;
-import org.jboss.security.SecurityAssociation;
import org.jboss.security.client.SecurityClient;
import org.jboss.security.client.SecurityClientFactory;
+import org.jboss.test.JBossTestCase;
/**
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -42,37 +39,55 @@
extends JBossTestCase
{
private static final Logger log = Logger.getLogger(MetricsUnitTestCase.class);
+
+ private SecurityClient client = null;
public MetricsUnitTestCase(String name)
{
-
super(name);
-
}
- public void testJmxMetrics() throws Exception
+ @Override
+ protected void setUp() throws Exception
{
- SecurityClient client = SecurityClientFactory.getSecurityClient();
+ super.setUp();
+
+ this.client = SecurityClientFactory.getSecurityClient();
client.setSimple("somebody", "password");
client.login();
-
- MBeanServerConnection server = getServer();
-
- testJmxMetrics(server, "Stateful", "jboss.j2ee:jar=stateful-test.jar,name=StatefulBean,service=EJB3");
- testJmxMetrics(server, "TreeCacheStateful", "jboss.j2ee:jar=stateful-test.jar,name=TreeCacheStatefulBean,service=EJB3");
}
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(MetricsUnitTestCase.class, "stateful-test.jar");
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ if(client == null)
+ return;
+ client.logout();
+ client = null;
+
+ super.tearDown();
+ }
+
protected void testJmxMetrics(MBeanServerConnection server, String jndiBinding, String objectName) throws Exception
{
ObjectName testerName = new ObjectName(objectName);
- System.out.println("testPassivation");
+ // Establish how many beans are already active
+ int prevCount = (Integer)server.getAttribute(testerName, "CreateCount");
+ System.out.println("prevCount = " + prevCount);
+ assertTrue("can't have negative creation count", prevCount >= 0);
+
Stateful stateful = (Stateful)getInitialContext().lookup(jndiBinding);
assertNotNull(stateful);
stateful.setState("state");
int count = (Integer)server.getAttribute(testerName, "CreateCount");
- assertEquals(1, count);
+ assertEquals(1, count - prevCount);
int size = (Integer)server.getAttribute(testerName, "CacheSize");
assertEquals(1, size);
@@ -89,7 +104,7 @@
assertEquals(0, size);
count = (Integer)server.getAttribute(testerName, "PassivatedCount");
- assertEquals(1, count);
+ assertEquals(1, count - prevCount);
assertTrue(stateful.wasPassivated());
assertEquals("state", stateful.getState());
@@ -106,11 +121,15 @@
stateful.testResources();
count = (Integer)server.getAttribute(testerName, "CreateCount");
- assertEquals(2, count);
+ assertEquals(2, count - prevCount);
+ // the injected beans are passivated at this point in time
+
size = (Integer)server.getAttribute(testerName, "CacheSize");
assertEquals(2, size);
+ // keep in mind, we're not removing already injected beans
+
size = (Integer)server.getAttribute(testerName, "RemoveCount");
assertEquals(0, size);
@@ -130,9 +149,19 @@
}
- public static Test suite() throws Exception
+ public void testJmxMetricsStateful() throws Exception
{
- return getDeploySetup(MetricsUnitTestCase.class, "stateful-test.jar");
+ MBeanServerConnection server = getServer();
+
+ // Note: we got one creation in ServiceBean
+
+ testJmxMetrics(server, "Stateful", "jboss.j2ee:jar=stateful-test.jar,name=StatefulBean,service=EJB3");
}
+
+ public void testJmxMetricsTreeCacheStateful() throws Exception
+ {
+ MBeanServerConnection server = getServer();
+ testJmxMetrics(server, "TreeCacheStateful", "jboss.j2ee:jar=stateful-test.jar,name=TreeCacheStatefulBean,service=EJB3");
+ }
}
More information about the jboss-cvs-commits
mailing list