[jboss-cvs] JBossAS SVN: r60632 - trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Feb 18 23:21:30 EST 2007
Author: bstansberry at jboss.com
Date: 2007-02-18 23:21:30 -0500 (Sun, 18 Feb 2007)
New Revision: 60632
Modified:
trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java
trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java
Log:
Refactor and expand testing of nested SFSBs
[EJBTHREE-867] Loosen coupling of lifecycle of nested SFSBs
[EJBTHREE-849] Properly handle passivation/activation callbacks for nested SFSBs
[EJBTHREE-851] Invoke passivation/activation callbacks around replication
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java 2007-02-19 04:14:29 UTC (rev 60631)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java 2007-02-19 04:21:30 UTC (rev 60632)
@@ -21,44 +21,71 @@
*/
package org.jboss.ejb3.test.clusteredsession.unit;
-import org.jboss.ejb3.test.clusteredentity.unit.DBSetup;
-import org.jboss.ejb3.test.clusteredsession.Customer;
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-import org.jboss.ejb3.test.clusteredsession.ShoppingCart;
-import org.jboss.ejb3.test.clusteredsession.StatelessRemote;
-import org.jboss.test.JBossClusteredTestCase;
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
-import javax.naming.InitialContext;
-import javax.naming.Context;
+import org.jboss.ejb3.test.clusteredentity.unit.DBSetup;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Customer;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.NestedXPCMonitor;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCart;
+import org.jboss.ejb3.test.stateful.unit.XPCTestRunner;
+import org.jboss.ejb3.test.stateful.unit.XPCTestRunner.BeanSet;
+import org.jboss.test.JBossClusteredTestCase;
-import java.rmi.dgc.VMID;
-import java.util.Properties;
-
/**
- * Tests for extended persistence under clustering.
+ * Tests for ExtendedPersistenceContext management.
+ *
+ * This class uses a delegate to execute the tests so the clustered
+ * version of the tests (which derive from a different base class)
+ * can use the same delegate code.
*
* @author Ben Wang
* @version $Id$
*/
-
-public class ExtendedPersistenceUnitTestCase extends JBossClusteredTestCase
+public class ExtendedPersistenceUnitTestCase
+ extends JBossClusteredTestCase
{
- org.jboss.logging.Logger log = getLog();
-
- static boolean deployed = false;
- static int test = 0;
-
+ private XPCTestRunner runner;
+
public ExtendedPersistenceUnitTestCase(String name)
{
-
super(name);
+ }
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+ Test t1 = getDeploySetup(ExtendedPersistenceUnitTestCase.class,
+ "clusteredsession-test.jar");
+
+ suite.addTest(t1);
+
+ // Create an initializer for the test suite
+ DBSetup wrapper = new DBSetup(suite);
+ return wrapper;
}
- protected InitialContext getInitialContext(int node) throws Exception {
- // Connect to the server0 JNDI
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ runner = new XPCTestRunner(getInitialContext(0), getLog());
+ runner.setUp();
+ // Use a sleep time equal to 2 thread runs + a 100 ms fudge
+ runner.setSleepTime(10100L);
+ }
+
+ private InitialContext getInitialContext(int node) throws Exception {
+ // Connect to the serverX JNDI
String[] urls = getNamingURLs();
Properties env1 = new Properties();
env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
@@ -67,104 +94,160 @@
return new InitialContext(env1);
}
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (runner != null)
+ runner.tearDown();
+ }
+
+
public void testBasic() throws Exception
{
- ShoppingCart cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
- StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
- Customer customer;
-
- long id = cart.createCustomer();
- customer = stateless.find(id);
- assertEquals("William", customer.getName());
- customer = cart.find(id);
- assertEquals("William", customer.getName());
- cart.update();
- customer = stateless.find(id);
- assertEquals("Bill", customer.getName());
- customer = cart.find(id);
- assertEquals("Bill", customer.getName());
- cart.update2();
- customer = stateless.find(id);
- assertEquals("Billy", customer.getName());
- customer = cart.find(id);
- assertEquals("Billy", customer.getName());
- cart.update3();
- customer = stateless.find(id);
- assertEquals("Bill Jr.", customer.getName());
- customer = cart.find(id);
- assertEquals("Bill Jr.", customer.getName());
- cart.setContainedCustomer();
- cart.checkout();
+ runner.testBasic();
}
+
+ public void testDependentLifecycle() throws Exception
+ {
+ runner.testDependentLifecycle();
+ }
+
+ public void testXPCSharing() throws Exception
+ {
+ runner.testXPCSharing();
+ }
public void testPassivation() throws Exception
{
- // We want a colocated SLSB and SFSB to test passivation/destruction
- // StatelessRemoteBean is not clustered, so once we have it's VMID
- // we can keep creating SFSBs until we get one we want
- StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
- VMID statelessVM = stateless.getVMID();
+ runner.testPassivation();
+ }
+
+ public void testFailover() throws Exception
+ {
+ failoverTest(false, false, false);
+ }
+
+ public void testRepeatedFailover() throws Exception
+ {
+ failoverTest(false, false, true);
+ }
+
+ public void testFailoverWithPassivation() throws Exception
+ {
+ failoverTest(true, false, false);
+ }
+
+ public void testRepeatedFailoverWithPassivation() throws Exception
+ {
+ failoverTest(true, true, true);
+ }
+
+ private void failoverTest(boolean passivate, boolean passivateAgain, boolean repeated)
+ throws Exception
+ {
+ BeanSet beanSet = runner.getBeanSet();
+ ShoppingCart parent = beanSet.cart;
+ NestedXPCMonitor monitor = beanSet.monitor;
- ShoppingCart cart = null;
- boolean vmMatch = false;
- for (int i = 0; i < 10 && !vmMatch; i++)
+ // Confirm the nested beans are there
+ String deepId = monitor.getDeepNestedId();
+ Assert.assertNotNull("Got a deepId", deepId);
+ Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
+ String localDeepId = monitor.getLocalDeepNestedId();
+ Assert.assertNotNull("Got a localDeepId", localDeepId);
+ Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
+
+ VMID origId = parent.getVMID();
+ Assert.assertNotNull("Got a VMID", origId);
+
+ long id = parent.createCustomer();
+ Customer customer = parent.find(id);
+ Assert.assertNotNull("Customer created and found on parent", customer);
+
+ parent.setContainedCustomer();
+ Assert.assertTrue("Parent and contained share customer", parent.checkContainedCustomer());
+
+ Assert.assertTrue("Parent and remote nested do not share ref",
+ monitor.compareTopToNested(id));
+ Assert.assertTrue("Parent and local nested do share ref",
+ monitor.compareTopToLocalNested(id));
+ Assert.assertTrue("Remote nested and local nested do not share a ref",
+ monitor.compareNestedToLocalNested(id));
+ Assert.assertTrue("Remote nested and deepNested share a ref",
+ monitor.compareNestedToDeepNested(id));
+ Assert.assertTrue("Local nested and localDeepNested share a ref",
+ monitor.compareLocalNestedToLocalDeepNested(id));
+
+ VMID newId = parent.getVMID();
+ Assert.assertTrue("VMID remained the same", origId.equals(newId));
+
+ if (passivate)
{
- cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
- vmMatch = statelessVM.equals(cart.getVMID());
- if (!vmMatch)
- cart.checkout();
+ runner.sleep();
}
- assertTrue("SLSB and SFSB in same VM", vmMatch);
+ parent.setUpFailover("once");
- Customer customer;
+ newId = parent.getVMID();
+ assertNotNull("Got a new VMID", newId);
+ assertFalse("Failover has occurred", origId.equals(newId));
- long id = cart.createCustomer();
- customer = stateless.find(id);
- assertEquals("William", customer.getName());
- customer = cart.find(id);
- assertEquals("William", customer.getName());
- cart.update();
- customer = stateless.find(id);
- assertEquals("Bill", customer.getName());
- customer = cart.find(id);
- assertEquals("Bill", customer.getName());
- cart.update2();
- customer = stateless.find(id);
- assertEquals("Billy", customer.getName());
- customer = cart.find(id);
- assertEquals("Billy", customer.getName());
- cart.update3();
- customer = stateless.find(id);
- assertEquals("Bill Jr.", customer.getName());
- customer = cart.find(id);
- assertEquals("Bill Jr.", customer.getName());
- cart.setContainedCustomer();
+ InitialContext[] ctxs = new InitialContext[2];
+ ctxs[0] = getInitialContext(1);
+ ctxs[1] = getInitialContext(0);
+ monitor = runner.getXPCMonitor(ctxs, newId);
- Thread.sleep(11000); // passivation
- assertTrue("Contained bean was passivated", stateless.isPassivated());
+ monitor.monitor(parent);
- cart.checkContainedCustomer();
- cart.findAndUpdateStateless();
- cart.updateContained();
+ Assert.assertTrue("Parent and remote nested do not share ref",
+ monitor.compareTopToNested(id));
+ Assert.assertTrue("Parent and local nested do share ref",
+ monitor.compareTopToLocalNested(id));
+ Assert.assertTrue("Remote nested and local nested do not share a ref",
+ monitor.compareNestedToLocalNested(id));
+ Assert.assertTrue("Remote nested and deepNested share a ref",
+ monitor.compareNestedToDeepNested(id));
+ Assert.assertTrue("Local nested and localDeepNested share a ref",
+ monitor.compareLocalNestedToLocalDeepNested(id));
- stateless.clearDestroyed();
- assertTrue(cart.isContainedActivated());
- cart.checkout();
- assertFalse("Contained bean was not destroyed", stateless.isDestroyed());
+ if (repeated)
+ {
+ if (passivateAgain)
+ {
+ runner.sleep();
+ }
+ origId = newId;
+
+ parent.setUpFailover("once");
+
+ newId = parent.getVMID();
+ assertNotNull("Got a new VMID", newId);
+ assertFalse("Failover has occurred", origId.equals(newId));
+
+ // Swap the contexts so we try node0 first
+ InitialContext ctx = ctxs[1];
+ ctxs[1] = ctxs[0];
+ ctxs[0] = ctx;
+
+ monitor = runner.getXPCMonitor(ctxs, newId);
+
+ monitor.monitor(parent);
+
+ Assert.assertTrue("Parent and remote nested do not share ref",
+ monitor.compareTopToNested(id));
+ Assert.assertTrue("Parent and local nested do share ref",
+ monitor.compareTopToLocalNested(id));
+ Assert.assertTrue("Remote nested and local nested do not share a ref",
+ monitor.compareNestedToLocalNested(id));
+ Assert.assertTrue("Remote nested and deepNested share a ref",
+ monitor.compareNestedToDeepNested(id));
+ Assert.assertTrue("Local nested and localDeepNested share a ref",
+ monitor.compareLocalNestedToLocalDeepNested(id));
+
+ }
}
- public static Test suite() throws Exception
- {
- TestSuite suite = new TestSuite();
- Test t1 = getDeploySetup(ExtendedPersistenceUnitTestCase.class,
- "clusteredsession-test.jar");
-
- suite.addTest(t1);
-
- // Create an initializer for the test suite
- DBSetup wrapper = new DBSetup(suite);
- return wrapper;
- }
-
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java 2007-02-19 04:14:29 UTC (rev 60631)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java 2007-02-19 04:21:30 UTC (rev 60632)
@@ -1,42 +1,54 @@
/*
- * JBoss, Home of Professional Open Source
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
*
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ejb3.test.clusteredsession.unit;
-import org.jboss.test.JBossClusteredTestCase;
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-import org.jboss.ejb3.test.clusteredsession.nested.ParentStatefulRemote;
+import java.rmi.dgc.VMID;
+import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
-import java.util.Date;
-import java.util.Properties;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner.NestedBeanSet;
+import org.jboss.test.JBossClusteredTestCase;
+
import junit.framework.Test;
/**
- * Test nested SFSB for load-balancing and failover behaviour
- *
- * @author Ben.Wang at jboss.org
+ * Overrides the parent test to use clustered versions of
+ * the beans.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
-public class NestedBeanUnitTestCase extends JBossClusteredTestCase
+public class NestedBeanUnitTestCase
+ extends JBossClusteredTestCase
{
- static boolean deployed = false;
- public static int test = 0;
- static Date startDate = new Date();
-
- protected final String namingFactory =
- System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
-
- protected final String providerURL =
- System.getProperty(Context.PROVIDER_URL);
-
- public NestedBeanUnitTestCase (String name)
+ private NestedBeanTestRunner runner;
+
+
+ public NestedBeanUnitTestCase(String name)
{
super(name);
}
@@ -44,13 +56,30 @@
public static Test suite() throws Exception
{
final String jarName = "clusteredsession-test.jar";
- Test t1 = JBossClusteredTestCase.getDeploySetup(NestedBeanUnitTestCase.class,
- jarName);
+ Test t1 = getDeploySetup(NestedBeanUnitTestCase.class,
+ jarName);
return t1;
}
+
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ runner = new NestedBeanTestRunner(getInitialContext(0), getLog());
+ runner.setUp();
+ // Use a sleep time equal to 2 thread runs + a 100 ms fudge
+ runner.setSleepTime(10100L);
+ // For clustered beans, an invocation is a passivation
+ runner.setPassivationPerInvocation(1);
+ // For clustered beans, passivation occurs after already called
+ // @PrePassivate for replication, so don't get a 2nd event
+ runner.setPassivationPerSleep(0);
+ }
- protected InitialContext getInitialContext(int node) throws Exception {
- // Connect to the server0 JNDI
+ private InitialContext getInitialContext(int node) throws Exception {
+ // Connect to the serverX JNDI
String[] urls = getNamingURLs();
Properties env1 = new Properties();
env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
@@ -59,122 +88,95 @@
return new InitialContext(env1);
}
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (runner != null)
+ runner.tearDown();
+ }
public void testBasic()
throws Exception
{
- getLog().debug(++NestedBeanUnitTestCase.test +"- "
- +"Trying the context...");
+ runner.testBasic();
+ }
+
+ public void testDependentLifecycle()
+ throws Exception
+ {
+ runner.testDependentLifecycle();
+ }
- // Connect to the server0 JNDI
- InitialContext ctx = getInitialContext(0);
+ public void testStatefulPassivation()
+ throws Exception
+ {
+ runner.testStatefulPassivation();
+ }
- getLog().debug("Test Nested Stateful Bean");
- getLog().debug("==================================");
- getLog().debug(++NestedBeanUnitTestCase.test +"- "
- +"Looking up testBasic...");
- ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
- stateful.reset();
- stateful.setName("The Code");
- _sleep(300);
-
- NodeAnswer node1 = stateful.getNodeState ();
+ public void testStatefulBeanCounterFailoverWithRemote()
+ throws Exception
+ {
+ getLog().debug("Test Nested Stateful Bean Counter Failover with Remote");
+ getLog().debug("======================================================");
+
+ NestedBeanSet beanSet = runner.getNestedBeanSet();
+ ParentStatefulRemote stateful = beanSet.parent;
+ VMID node1 = stateful.getVMID();
+ assertNotNull("State node: ", node1);
getLog ().debug ("Node 1 ID: " +node1);
assertEquals("Counter: ", 1, stateful.increment());
assertEquals("Counter: ", 2, stateful.increment());
+ sleep(300);
- stateful.remove();
- getLog().debug("ok");
- _sleep(11000);
- }
+ // Now we switch to the other node, simulating a failure on node 1
+ stateful.setUpFailover("once");
+ VMID node2 = stateful.getVMID();
+ assertNotNull("State node: ", node2);
+ getLog ().debug ("Node 2 ID : " +node2);
- public void testPassivation()
- throws Exception
- {
- getLog().debug(++NestedBeanUnitTestCase.test +"- "
- +"Trying the context...");
+ assertFalse("Failover has occured", node1.equals(node2));
- // Connect to the server0 JNDI
- InitialContext ctx = getInitialContext(0);
-
- getLog().debug("Test Nested Stateful Bean");
- getLog().debug("==================================");
- getLog().debug(++NestedBeanUnitTestCase.test +"- "
- +"Looking up remote...");
- ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
- stateful.setName("The Code");
- _sleep(300);
-
- NodeAnswer node1 = stateful.getNodeState ();
- getLog ().debug ("Node 1 ID: " +node1);
-// _sleep(300000);
- assertEquals("Counter: ", 1, stateful.increment());
- assertEquals("Counter: ", 2, stateful.increment());
- assertEquals("SLSB state: ", "test", stateful.getStatelessState().getAnswer());
- stateful.reset();
- _sleep(11000);
assertEquals("Counter: ", 3, stateful.increment());
- assertEquals("SLSB state: ", "test", stateful.getStatelessState().getAnswer());
- assertEquals(1, stateful.getPrePassivate());
- assertEquals(1, stateful.getPostActivate());
- assertEquals(1, stateful.getNestedPrePassivate());
- assertEquals(1, stateful.getNestedPostActivate());
+ assertEquals("Counter: ", 4, stateful.increment());
- stateful.remove();
- getLog().debug("ok: done");
- _sleep(12000);
+ runner.removeBean(stateful);
+ getLog().debug("ok");
}
+
public void testStatefulBeanCounterFailover()
throws Exception
{
- getLog().debug(++NestedBeanUnitTestCase.test +"- "+"Trying the context...");
-
- // Connect to the server0 JNDI
- InitialContext ctx = getInitialContext(0);
-
- getLog().debug("Test Stateful Bean Failover");
- getLog().debug("==================================");
- getLog().debug(++NestedBeanUnitTestCase.test +"- "
- +"Looking up testParentStateful...");
- ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
- stateful.setName("The Code");
- NodeAnswer node1 = stateful.getNodeState ();
+ getLog().debug("Test Nested Stateful Bean Counter Failover");
+ getLog().debug("==========================================");
+
+ NestedBeanSet beanSet = runner.getNestedBeanSet();
+ ParentStatefulRemote stateful = beanSet.parent;
+ VMID node1 = stateful.getVMID();
+ assertNotNull("State node: ", node1);
getLog ().debug ("Node 1 ID: " +node1);
- assertEquals("Counter: ", 1, stateful.increment());
- assertEquals("Counter: ", 2, stateful.increment());
- _sleep(300);
+ assertEquals("Counter: ", 1, stateful.incrementLocal());
+ assertEquals("Counter: ", 2, stateful.incrementLocal());
+ sleep(300);
// Now we switch to the other node, simulating a failure on node 1
- //
stateful.setUpFailover("once");
- NodeAnswer node2 = stateful.getNodeState();
+ VMID node2 = stateful.getVMID();
assertNotNull("State node: ", node2);
getLog ().debug ("Node 2 ID : " +node2);
- assertFalse("Failover has occured", node1.nodeId.equals(node2.nodeId));
+ assertFalse("Failover has occured", node1.equals(node2));
- assertEquals ("Node 1: ", "The Code", node1.answer);
- assertEquals ("Node 2: ", "The Code", node2.answer);
+ assertEquals("Counter: ", 3, stateful.incrementLocal());
+ assertEquals("Counter: ", 4, stateful.incrementLocal());
- assertEquals("Counter: ", 3, stateful.increment());
- assertEquals("Counter: ", 4, stateful.increment());
-
- stateful.remove();
+ runner.removeBean(stateful);
getLog().debug("ok");
}
- protected void _sleep(long time)
- {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
}
More information about the jboss-cvs-commits
mailing list