[jboss-cvs] JBossAS SVN: r64211 - in trunk/testsuite/src/main/org/jboss/test/cluster: defaultcfg and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 23 22:35:13 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-07-23 22:35:13 -0400 (Mon, 23 Jul 2007)
New Revision: 64211
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/CrossServerCallsUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PackagedSessionImplUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PooledHAUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/RetryInterceptorUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/SingleRetryInterceptorUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/FieldBasedSessionPassivationTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/ScopedFieldBasedTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/jk/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/AttributeBasedSessionPassivationTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/CrossContextCallsTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetAttributeTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetTriggerTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionEventTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionPassivationTestCase.java
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SimpleTestCase.java
Log:
[JBAS-4552] Move cluster tests into cluster package
[JBAS-4553] Reorg cluster tests to prevent unnecessary repetition
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/CrossServerCallsUnitTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/CrossServerCallsUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/CrossServerCallsUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/CrossServerCallsUnitTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.ejb2.test;
+
+import java.util.Properties;
+import java.rmi.dgc.VMID;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.ejb2.crossserver.CalledHome;
+import org.jboss.test.cluster.ejb2.crossserver.CalledRemote;
+
+/**
+ * Tests of inter-server ejb calls
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class CrossServerCallsUnitTestCase extends JBossClusteredTestCase
+{
+ public CrossServerCallsUnitTestCase (String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(CrossServerCallsUnitTestCase.class, "cross-server.jar");
+ return t1;
+ }
+
+ public void testEjb2EjbCall()
+ throws Exception
+ {
+ log.info("+++ testEjb2EjbCall");
+
+ // Connect to the server0 JNDI
+ String[] urls = getNamingURLs();
+ Properties env1 = new Properties();
+ env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ env1.setProperty(Context.PROVIDER_URL, urls[0]);
+ InitialContext ctx = new InitialContext(env1);
+
+ CalledHome home = (CalledHome) ctx.lookup("cluster.ejb.CalledHome");
+ CalledRemote bean = home.create();
+ VMID[] ids = bean.invokeCall(urls[1], "cluster.ejb.CalleeHome");
+ log.info("VMID[0] = "+ids[0]);
+ log.info("VMID[1] = "+ids[1]);
+ assertTrue("VMID[0] != VMID[1]", ids[0].equals(ids[1]) == false);
+ bean.remove();
+ log.info("done");
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PackagedSessionImplUnitTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/PackagedSessionImplUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PackagedSessionImplUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PackagedSessionImplUnitTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,71 @@
+package org.jboss.test.cluster.defaultcfg.ejb2.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.jboss.ha.hasessionstate.server.PackagedSessionImpl;
+import org.jboss.test.JBossTestCase;
+
+public class PackagedSessionImplUnitTestCase extends JBossTestCase
+{
+
+ public PackagedSessionImplUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testUnmodifiedExistenceInVM() throws Exception
+ {
+ long oldTimestamp = System.currentTimeMillis();
+
+ sleep(15); // make sure the system clock changes
+
+ byte[] state = new byte[1];
+ PackagedSessionImpl psi = new PackagedSessionImpl("Test", state, "Test");
+
+ long newTimestamp = psi.unmodifiedExistenceInVM();
+
+ assertTrue("Valid initial timestamp", newTimestamp > oldTimestamp);
+
+
+ sleep(15); // make sure the system clock changes
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(psi);
+ oos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ psi = (PackagedSessionImpl) ois.readObject();
+ ois.close();
+
+ oldTimestamp = newTimestamp;
+ newTimestamp = psi.unmodifiedExistenceInVM();
+
+ assertTrue("Valid timestamp after deserialization", newTimestamp > oldTimestamp);
+
+ sleep(15); // make sure the system clock changes
+
+ psi.setState(state); // use the same state to confirm that the timestamp updates anyway
+
+ oldTimestamp = newTimestamp;
+ newTimestamp = psi.unmodifiedExistenceInVM();
+
+ assertTrue("Valid timestamp after setState()", newTimestamp > oldTimestamp);
+
+ sleep(15); // make sure the system clock changes
+
+ PackagedSessionImpl psi2 = new PackagedSessionImpl("Test", state, "Test");
+
+ psi.update(psi2);
+
+ oldTimestamp = newTimestamp;
+ newTimestamp = psi.unmodifiedExistenceInVM();
+
+ assertTrue("Valid timestamp after update()", newTimestamp > oldTimestamp);
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PooledHAUnitTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/PooledHAUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PooledHAUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/PooledHAUnitTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,273 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.ejb2.test;
+
+import java.util.Date;
+import java.util.Properties;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.ejb2.basic.interfaces.NodeAnswer;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatefulSession;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatelessSession;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatelessSessionHome;
+import org.jboss.test.testbean.interfaces.StatefulSessionHome;
+import org.jboss.invocation.pooled.interfaces.PooledInvokerProxy;
+import org.jboss.invocation.pooled.interfaces.ServerAddress;
+import junit.framework.Test;
+
+/**
+ * Tests of stateless/stateful HA behavior using the pooled invoker
+ *
+ * @author <a href="mailto:sacha.labourey at jboss.org">Sacha Labourey</a>.
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class PooledHAUnitTestCase extends JBossClusteredTestCase
+{
+ static boolean deployed = false;
+ 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 PooledHAUnitTestCase (String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(PooledHAUnitTestCase.class, "pooledha.jar");
+ return t1;
+ }
+
+ /**
+ * Test the equals/hashCode behavior for ServerAddress
+ * @throws Exception
+ */
+ public void testServerAddressHashEquals()
+ throws Exception
+ {
+ ServerAddress sa1 = new ServerAddress("127.0.0.1", 4445, false, 60, null);
+ ServerAddress sa2 = new ServerAddress("127.0.0.1", 4445, false, 61, null);
+ assertEquals(sa1, sa2);
+ assertEquals(sa1.hashCode(), sa2.hashCode());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(sa1);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ sa2 = (ServerAddress) ois.readObject();
+ assertEquals(sa1, sa2);
+ assertEquals(sa1.hashCode(), sa2.hashCode());
+
+ // Different tcpNoDelay should not be equal
+ sa2 = new ServerAddress("127.0.0.1", 4445, true, 61, null);
+ assertNotSame(sa1, sa2);
+ // Different ports should not be equal
+ sa2 = new ServerAddress("127.0.0.1", 4446, false, 60, null);
+ assertNotSame(sa1, sa2);
+ // Different host should not be equal
+ sa2 = new ServerAddress("127.0.0.2", 4445, false, 60, null);
+ assertNotSame(sa1, sa2);
+ }
+
+ public void testStatelessBeanLoadBalancing()
+ throws Exception
+ {
+ log.debug("testStatelessBeanLoadBalancing - Trying the context...");
+
+ // Connect to the server0 JNDI
+ String[] urls = getNamingURLs();
+ Properties env1 = new Properties();
+ env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ env1.setProperty(Context.PROVIDER_URL, urls[0]);
+ InitialContext ctx = new InitialContext(env1);
+
+ log.debug("Looking up the home pooledha_StatelessSession..."+urls[0]);
+ StatelessSessionHome homeHA =
+ (StatelessSessionHome) ctx.lookup("pooledha_StatelessSession");
+ log.debug("Looking up the home pooled_StatelessSession..."+urls[0]);
+ StatelessSessionHome home =
+ (StatelessSessionHome) ctx.lookup("pooled_StatelessSession");
+
+ // Simple connection count stress test
+ PooledInvokerProxy.clearStats();
+ PooledInvokerProxy.clearPools();
+ for(int n = 0; n < 100; n ++)
+ {
+ StatelessSession tmp = homeHA.create();
+ StatelessSession tmp2 = home.create();
+ tmp.getCallCount();
+ tmp2.getCallCount();
+ tmp.getCallCount();
+ tmp2.getCallCount();
+ int totalCount = PooledInvokerProxy.getTotalPoolCount();
+ // N cluster nodes + 1 for unclustered
+ int expectedCount = urls.length + 1;
+ assertEquals("TotalPoolCount", expectedCount, totalCount);
+ long usedPooled = PooledInvokerProxy.getUsedPooled();
+ // iter * Ncalls - expectedCount (for the initial conn creation)
+ int expectedUsedPooled = (n+1) * 6 - expectedCount;
+ assertEquals("UsedPooled", expectedUsedPooled, usedPooled);
+ }
+ long inUseCount = PooledInvokerProxy.getInUseCount();
+ assertEquals("InUseCount", 0, inUseCount);
+
+ log.debug("Calling create on StatelessSessionHome...");
+ StatelessSession statelessSession = homeHA.create();
+ assertTrue("homeHA.create() != null", statelessSession != null);
+ log.debug("Calling getEJBHome() on StatelessSession...");
+ assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null);
+
+ log.debug("Reseting the number of calls made on beans (making 2 calls)... ");
+ for (int i=0; i<6; i++)
+ {
+ log.debug("Reseting number... ");
+ statelessSession.resetNumberOfCalls ();
+ }
+
+ log.debug("- "+"Now making 20 calls on this remote... ");
+ for (int i=0; i<20; i++)
+ {
+ log.debug("- "+" Calling remote... ");
+ statelessSession.makeCountedCall ();
+ }
+
+ log.debug("- "+"Getting the number of calls that have been performed on each bean... ");
+ long node1 = statelessSession.getCallCount();
+ log.debug("- "+"One node has received: " + node1);
+
+ long node2 = statelessSession.getCallCount();
+ log.debug("- "+"The other node has received: " + node2);
+
+ if (node1 == node2 && node1 == 10)
+ {
+ log.debug("- "+"Test is ok.");
+ }
+ else if( urls.length > 1 )
+ {
+ log.debug("- "+"Something wrong has happened! Calls seems not to have been load-balanced.");
+ fail ("call count mismatch: "+node1+" != "+node2);
+ }
+
+ statelessSession.remove();
+ log.debug("ok");
+ }
+
+ public void testStatefulBeanFailover()
+ throws Exception
+ {
+ log.debug("testStatelessBeanLoadBalancing - Trying the context...");
+
+ // Connect to the server0 JNDI
+ String[] urls = getNamingURLs();
+ Properties env1 = new Properties();
+ env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ env1.setProperty(Context.PROVIDER_URL, urls[0]);
+ InitialContext ctx = new InitialContext(env1);
+
+ log.debug("Looking up the home pooledha_StatefulSession..."+urls[0]);
+ StatefulSessionHome homeHA =
+ (StatefulSessionHome) ctx.lookup("pooledha_StatefulSession");
+ log.debug("Looking up the home pooled_StatelessSession..."+urls[0]);
+ StatelessSessionHome home =
+ (StatelessSessionHome) ctx.lookup("pooled_StatelessSession");
+
+ // Simple connection count stress test
+ PooledInvokerProxy.clearStats();
+ PooledInvokerProxy.clearPools();
+ for(int n = 0; n < 100; n ++)
+ {
+ StatefulSession tmp = (StatefulSession) homeHA.create();
+ tmp.remove();
+ tmp = (StatefulSession) homeHA.create();
+ StatelessSession tmp2 = home.create();
+ tmp.getNodeState();
+ tmp2.getCallCount();
+ tmp.getNodeState();
+ tmp2.getCallCount();
+ tmp.remove();
+ int totalCount = PooledInvokerProxy.getTotalPoolCount();
+ // N cluster nodes + 1 for unclustered
+ int expectedCount = urls.length + 1;
+ assertEquals("TotalPoolCount", expectedCount, totalCount);
+ long usedPooled = PooledInvokerProxy.getUsedPooled();
+ // iter * Ncalls - expectedCount (for the initial conn creation)
+ int expectedUsedPooled = (n+1) * 9 - expectedCount;
+ assertEquals("UsedPooled", expectedUsedPooled, usedPooled);
+ }
+ long inUseCount = PooledInvokerProxy.getInUseCount();
+ assertEquals("InUseCount", 0, inUseCount);
+
+ log.debug("Test Stateful Bean Failover");
+ log.debug("Looking up the home nextgen.StatefulSession...");
+ log.debug("Calling create on StatefulSessionHome...");
+ StatefulSession statefulSession =
+ (StatefulSession)homeHA.create("Bupple-Dupple");
+ assertTrue("statefulSessionHome.create() != null", statefulSession != null);
+
+ NodeAnswer node1 = statefulSession.getNodeState ();
+ getLog ().debug (node1);
+
+ // Now we switch to the other node, simulating a failure on node 1
+ System.setProperty ("JBossCluster-DoFail", "once");
+ NodeAnswer node2 = statefulSession.getNodeState ();
+ log.debug (node2);
+ assertEquals("Value is identical on replicated node1", "Bupple-Dupple", node1.answer);
+ assertEquals("Value is identical on replicated node2", "Bupple-Dupple", node2.answer);
+
+ // we change our name to see if it replicates to node 1
+ statefulSession.setName ("Changed");
+
+ // now we travel back on node 1
+ System.setProperty ("JBossCluster-DoFail", "once");
+ node1 = statefulSession.getNodeState ();
+ log.debug(node1);
+
+ assertEquals("Value is identical on replicated node1", "Changed", node1.answer);
+ node2 = statefulSession.getNodeState ();
+ log.debug(node2);
+ assertEquals("Value is identical on replicated node2", "Changed", node2.answer);
+
+ statefulSession.remove();
+
+ int totalCount = PooledInvokerProxy.getTotalPoolCount();
+ // N cluster nodes + 1 for unclustered
+ int expectedCount = urls.length + 1;
+ assertEquals("TotalPoolCount", expectedCount, totalCount);
+ }
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/RetryInterceptorUnitTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/RetryInterceptorUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/RetryInterceptorUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/RetryInterceptorUnitTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,699 @@
+/*
+ * 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.
+ *
+ * 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.test.cluster.defaultcfg.ejb2.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+import java.util.Random;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.logging.Logger;
+import org.jboss.proxy.ejb.RetryInterceptor;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.ejb2.basic.interfaces.NodeAnswer;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatefulSession;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatelessSession;
+import org.jboss.test.cluster.ejb2.basic.interfaces.StatelessSessionHome;
+import org.jboss.test.cluster.testutil.DBSetup;
+import org.jboss.test.testbean.interfaces.AComplexPK;
+import org.jboss.test.testbean.interfaces.EntityPK;
+import org.jboss.test.testbean.interfaces.EntityPKHome;
+import org.jboss.test.testbean.interfaces.StatefulSessionHome;
+
+/**
+ * Tests the RetryInterceptor.
+ *
+ * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
+ * @version $Revision $
+ */
+public class RetryInterceptorUnitTestCase extends JBossClusteredTestCase
+{
+ private static final String DISCOVERY_TTL = System.getProperty("jbosstest.udp.ip_ttl", "1");
+ private static final String DISCOVERY_GROUP = System.getProperty("jbosstest.udpGroup");
+
+ private static File customJndiDir = null;
+ private static File customJndiProperties = null;
+
+ // NOTE: these variables must be static as apparently a separate instance
+ // of this class is created for each test.
+ private static boolean deployed0 = false;
+ private static boolean deployed1 = false;
+
+ static abstract class RetryCaller extends Thread
+ {
+ Properties env;
+ Throwable failure;
+
+ RetryCaller(Properties env)
+ {
+ this.env = env;
+ }
+
+ public void run()
+ {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ if (customJndiProperties != null)
+ {
+ // Create a special classloader that will read in the
+ // customJndiProperties file and include it in any
+ // getResources("jndi.properties") request.
+ // We use this to allow running the server with
+ // HA-JNDI autodiscovery set to a custom address
+ URL[] urls = new URL[]{ customJndiDir.toURL() };
+ ClassLoader cl = new URLClassLoader(urls, tccl);
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
+ // Establish an initial context on this thread with the
+ // given properties -- needed for JBoss NamingContextFactory
+ // to work properly. Meaningless otherwise
+ new InitialContext(env);
+
+ executeTest();
+ }
+ catch (Throwable t)
+ {
+ failure = t;
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ protected abstract void executeTest() throws Throwable;
+
+ }
+
+ static class MultiRetryCaller extends RetryCaller
+ {
+ StatelessSessionHome slsbh;
+ StatelessSession slsb;
+ StatefulSessionHome sfsbh;
+ StatefulSession sfsb;
+ NodeAnswer node1;
+ EntityPKHome epkh;
+ EntityPK epk;
+ int other;
+ AComplexPK pk;
+ Logger log;
+ Throwable failure;
+
+ MultiRetryCaller(Properties env,
+ StatelessSessionHome slsbh, StatelessSession slsb,
+ StatefulSessionHome sfsbh, StatefulSession sfsb,
+ NodeAnswer node1,
+ EntityPKHome epkh, EntityPK epk,
+ int other, AComplexPK pk,
+ Logger log)
+ {
+ super(env);
+ this.slsbh = slsbh;
+ this.slsb = slsb;
+ this.sfsbh = sfsbh;
+ this.sfsb = sfsb;
+ this.node1 = node1;
+ this.epkh = epkh;
+ this.epk = epk;
+ this.other = other;
+ this.pk = pk;
+ this.log = log;
+ }
+
+ protected void executeTest() throws Throwable
+ {
+ // Test that the SFSB still works
+
+ System.setProperty ("JBossCluster-DoFail", "once");
+ NodeAnswer node2 = sfsb.getNodeState ();
+ log.debug (node2);
+
+ assertTrue ("StatefulSession: Failover has occured",
+ !node1.nodeId.equals(node2.nodeId));
+
+ assertTrue ("StatefulSession: Value is identical on replicated node",
+ "Bupple-Dupple".equals (node1.answer) &&
+ node1.answer.equals(node2.answer) );
+
+ log.debug("StatefulSession: Retry successful");
+
+ // Test that the SFSB Home still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ sfsb = (StatefulSession)sfsbh.create("Hippie-Dippie");
+
+ node2 = sfsb.getNodeState ();
+ log.debug (node2);
+
+ assertTrue ("StatefulSessionHome: Failover has occured",
+ !node1.nodeId.equals (node2.nodeId));
+
+ log.debug("StatefulSessionHome: Retry successful");
+
+ // Test that the SLSB still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ log.debug("StatelessSession: Now making 1 call on server1 ");
+ assertTrue("StatelessSession: Server1 has no calls", 0 == slsb.getCallCount());
+
+ log.debug("StatelessSession: Retry successful");
+
+ // Test that the SLSB Home still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ log.debug("Calling create on StatelessSessionHome...");
+ slsb = slsbh.create();
+
+ log.debug("StatelessSessionHome: Retry successful");
+
+ // Test that the entity bean still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ log.debug("Retrieving other field again, should be " + other + "...");
+ int newValue = epk.getOtherField();
+ assertEquals("pkBean.getOtherField() correct:", other, newValue);
+
+ log.debug("EntityBean: Retry successful");
+
+ // Test the entity home still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ epk = epkh.findByPrimaryKey(pk);
+
+ assertTrue("pkBean != null", epk != null);
+
+ log.debug("EntityBeanHome: Retry successful");
+ }
+ }
+
+ static class SFSBRetryCaller extends RetryCaller
+ {
+ StatefulSessionHome sfsbh;
+ StatefulSession sfsb;
+ Throwable failure;
+ Logger log;
+
+ SFSBRetryCaller(Properties env, StatefulSession sfsb, Logger log)
+ {
+ super(env);
+ this.sfsb = sfsb;
+ this.log = log;
+ }
+
+ protected void executeTest() throws Throwable
+ {
+ // Test that the SFSB still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ NodeAnswer node2 = sfsb.getNodeState ();
+ log.debug (node2);
+
+ assertTrue ("StatefulSession: Failover has occured", node2 != null);
+
+ log.debug("StatefulSession: Retry successful");
+
+ }
+ }
+ static class DeferredRecoveryCaller extends RetryCaller
+ {
+ StatelessSession slsb;
+ Object result;
+
+ DeferredRecoveryCaller(Properties env, StatelessSession slsb)
+ {
+ super(env);
+ this.slsb = slsb;
+ }
+
+ public void executeTest() throws Throwable
+ {
+ // Test that the SLSB still works
+ System.setProperty ("JBossCluster-DoFail", "once");
+ result = new Long(slsb.getCallCount());
+ }
+ }
+
+ /**
+ * Create a new RetryInterceptorUnitTestCase.
+ *
+ * @param name
+ */
+ public RetryInterceptorUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new TestSuite(RetryInterceptorUnitTestCase.class));
+
+ // Create an initializer for the test suite
+ DBSetup wrapper = new DBSetup(suite);
+ return wrapper;
+ }
+
+ /**
+ * Tests that calls to bean and home calls to SLSB, SFSB, Entity beans
+ * will still succeed after a cluster topology change that makes
+ * the target list in FamilyClusterInfo completely invalid.
+ *
+ * @throws Exception
+ */
+ public void testRetryInterceptor() throws Exception
+ {
+ getLog().debug("+++ Enter testRetryInterceptor");
+
+ configureCluster();
+
+ // Connect to the server0 HA-JNDI
+
+ Properties env = getNamingProperties("org.jboss.naming.NamingContextFactory",
+ false);
+ InitialContext ctx = new InitialContext(env);
+
+ getLog().debug("Looking up the home nextgen.StatefulSession" + getJndiSuffix()+"...");
+ StatefulSessionHome sfsbHome =
+ (StatefulSessionHome) ctx.lookup("nextgen_StatefulSession" + getJndiSuffix());
+ if (sfsbHome!= null ) getLog().debug("ok");
+ getLog().debug("Calling create on StatefulSessionHome" + getJndiSuffix()+"...");
+ StatefulSession sfsb = (StatefulSession)sfsbHome.create("Bupple-Dupple");
+ assertTrue("statefulSessionHome.create() != null", sfsb != null);
+ getLog().debug("ok");
+
+ NodeAnswer node1 = sfsb.getNodeState ();
+ getLog ().debug (node1);
+
+ getLog().debug("Looking up the home nextgen.StatelessSession" + getJndiSuffix()+"...");
+ StatelessSessionHome slsbHome =
+ (StatelessSessionHome) ctx.lookup("nextgen_StatelessSession" + getJndiSuffix());
+ if (slsbHome!= null ) getLog().debug("ok");
+ getLog().debug("Calling create on StatelessSessionHome" + getJndiSuffix()+"...");
+ StatelessSession slsb = slsbHome.create();
+
+ getLog().debug("StatelessSession: Now making 1 call on server0 ");
+ assertEquals("StatelessSession: Server0 has no calls", 0, slsb.getCallCount());
+
+ getLog().debug("Looking up home for nextgen_EntityPK" + getJndiSuffix()+"...");
+ EntityPKHome pkHome = (EntityPKHome) ctx.lookup("nextgen_EntityPK" + getJndiSuffix());
+ assertTrue("pkHome != null", pkHome != null);
+ getLog().debug("ok");
+
+ getLog().debug("Calling find on the home...");
+ EntityPK pkBean = null;
+
+ Random rnd = new Random(System.currentTimeMillis());
+ int anInt = rnd.nextInt(10);
+ int other = rnd.nextInt(10000);
+ AComplexPK pk = new AComplexPK(true, anInt, 100, 1000.0, "Marc");
+ // Let's try to find the instance
+ try
+ {
+ pkBean = pkHome.findByPrimaryKey(pk);
+ }
+ catch (Exception e)
+ {
+ getLog().debug("Did not find the instance will create it...");
+ pkBean = pkHome.create(true, anInt, 100, 1000.0, "Marc");
+ }
+
+
+ assertTrue("pkBean != null", pkBean != null);
+ getLog().debug("ok");
+
+ getLog().debug("Setting otherField to " + other + "...");
+ pkBean.setOtherField(other);
+ getLog().debug("ok");
+
+
+ // Reconfigure the cluster so the existing targets are invalid
+ reconfigureCluster();
+
+ // Make calls on the beans in another thread so we can terminate
+ // after a reasonable period of time if the RetryInterceptor is looping
+ MultiRetryCaller caller = new MultiRetryCaller(env, slsbHome,
+ slsb, sfsbHome, sfsb, node1, pkHome, pkBean, other,
+ pk, getLog());
+ executeRetryTest(caller);
+
+ getLog().debug("+++ Exit testRetryInterceptor");
+ }
+
+ protected void executeRetryTest(RetryCaller caller)
+ throws InterruptedException, AssertionFailedError
+ {
+ caller.start();
+
+ // Give the caller 15 secs to do its work
+ caller.join(15000);
+
+ boolean alive = caller.isAlive();
+ if (alive)
+ caller.interrupt();
+
+ assertFalse("Retry calls completed", alive);
+
+ if (caller.failure instanceof AssertionFailedError)
+ {
+ throw (AssertionFailedError) caller.failure;
+ }
+ else if (caller.failure != null)
+ {
+ fail(caller.failure.getMessage());
+ }
+ }
+
+ public void testDeferredRecovery() throws Exception
+ {
+ deferredRecoveryTest(true);
+ }
+
+ protected void deferredRecoveryTest(boolean expectSuccess) throws Exception
+ {
+ getLog().debug("+++ Enter testDeferredRecovery");
+
+ configureCluster();
+
+ Properties env = getNamingProperties("org.jboss.naming.NamingContextFactory",
+ false);
+ InitialContext ctx = new InitialContext(env);
+
+ getLog().debug("Looking up the home nextgen.StatelessSession" + getJndiSuffix()+"...");
+ StatelessSessionHome home =
+ (StatelessSessionHome) ctx.lookup("nextgen_StatelessSession" + getJndiSuffix());
+ if (home!= null ) getLog().debug("ok");
+ getLog().debug("Calling create on StatelessSessionHome" + getJndiSuffix()+"...");
+ StatelessSession slsb = home.create();
+
+ getLog().debug("StatelessSession: Now making 1 call on server0 ");
+ assertEquals("StatelessSession: Server0 has no calls", 0, slsb.getCallCount());
+
+ // Undeploy the ear
+ RMIAdaptor[] adaptors = getAdaptors();
+ undeploy(adaptors[0], "test-retry.ear");
+ setDeployed0(false);
+
+ sleep(1000);
+
+ DeferredRecoveryCaller caller = new DeferredRecoveryCaller(env, slsb);
+ caller.start();
+
+ sleep(1000);
+
+ if (caller.isAlive()) // don't bother deploying otherwise
+ {
+ deploy(adaptors[1], "test-retry.ear");
+ setDeployed1(true);
+ }
+
+ // Give the caller 3 secs to complete (extremely generous)
+ caller.join(3000);
+
+ if (caller.isAlive())
+ fail("Caller did not complete");
+
+ if (expectSuccess)
+ {
+ assertTrue("Caller retrieved a long", (caller.result instanceof Long));
+ getLog().debug("StatefulSession: Retry successful");
+ }
+ else
+ {
+ assertTrue("Caller failed as expected", caller.failure != null);
+ getLog().debug("StatefulSession: Retry failed as expected");
+ }
+
+ getLog().debug("+++ Exit testDeferredRecovery");
+ }
+
+ /**
+ * Tests that the retry interceptor works properly if the naming context
+ * is established via RetryInterceptor.setRetryEnv()
+ * and auto-discovery is disabled.
+ *
+ * @throws Exception
+ */
+ public void testSetRetryEnv() throws Exception
+ {
+ getLog().debug("+++ Enter testSetRetryEnv");
+
+ Properties env = getNamingProperties("org.jnp.interfaces.NamingContextFactory", false);
+ try
+ {
+ RetryInterceptor.setRetryEnv(env);
+ InitialContext ctx = new InitialContext(env);
+
+ sfsbTest(ctx, env);
+
+ }
+ finally
+ {
+ RetryInterceptor.setRetryEnv(null);
+ }
+
+ getLog().debug("+++ Exit testSetRetryEnv");
+ }
+
+ /**
+ * Tests that the retry interceptor works properly if the naming context
+ * is established by using org.jnp.interfaces.NamingContextFactory
+ * and auto-discovery is enabled.
+ *
+ * @throws Exception
+ */
+ public void testRetryWithJnpAndAutoDiscovery() throws Exception
+ {
+ getLog().debug("+++ Enter testRetryWithJnpAndAutoDiscovery()");
+
+ // Create a jndi.properties in the temp dir with special configs
+ // to prevent autodiscovery spuriously discovering random servers
+ // on the network. When the RetryCaller runs, it will create a
+ // special classloader that will pick up this file
+ if (customJndiDir == null)
+ customJndiDir = new File(System.getProperty("java.io.tempdir"),
+ "retry-int-test");
+ if (!customJndiDir.exists())
+ customJndiDir.mkdir();
+ customJndiProperties = new File(customJndiDir, "jndi.properties");
+ FileOutputStream fos = new FileOutputStream(customJndiProperties);
+ OutputStreamWriter writer = new OutputStreamWriter(fos);
+ writer.write("jnp.discoveryTTL=" + DISCOVERY_TTL + "\n");
+ if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // The server isn't listening on the std multicast address
+ writer.write("jnp.discoveryGroup=" + DISCOVERY_GROUP);
+ }
+ writer.close();
+ getLog().debug("Created custom jndi.properties at " + customJndiProperties +
+ " -- DISCOVERY_GROUP is " + DISCOVERY_GROUP);
+
+
+ Properties env = getNamingProperties("org.jnp.interfaces.NamingContextFactory", true);
+
+ InitialContext ctx = new InitialContext(env);
+
+ sfsbTest(ctx, env);
+ }
+
+ /**
+ * Tests that the retry interceptor works properly for an SFSB given
+ * a particular JNDI client configuration.
+ *
+ * @param ctx
+ * @throws Exception
+ */
+ protected void sfsbTest(Context ctx, Properties env) throws Exception
+ {
+ configureCluster();
+
+ getLog().debug("Looking up the home nextgen.StatefulSession" + getJndiSuffix()+"...");
+ StatefulSessionHome statefulSessionHome =
+ (StatefulSessionHome) ctx.lookup("nextgen_StatefulSession" + getJndiSuffix());
+ if (statefulSessionHome!= null ) getLog().debug("ok");
+ getLog().debug("Calling create on StatefulSessionHome" + getJndiSuffix()+"...");
+ StatefulSession statefulSession =
+ (StatefulSession)statefulSessionHome.create("Bupple-Dupple");
+ assertTrue("statefulSessionHome.create() != null", statefulSession != null);
+ getLog().debug("ok");
+
+ NodeAnswer node1 = statefulSession.getNodeState ();
+ getLog ().debug (node1);
+
+ // Reconfigure the cluster so the existing targets are invalid
+ // BES -- don't bother; we test that functionality in testRetryInterceptor
+ // just confirm that reestablishing the targets works
+// reconfigureCluster();
+
+ // Make calls on the bean in another thread so we can terminate
+ // after a reasonable period of time if the RetryInterceptor is looping
+ SFSBRetryCaller caller = new SFSBRetryCaller(env, statefulSession, getLog());
+ executeRetryTest(caller);
+
+ getLog().debug("StatefulSession: Retry successful");
+ }
+
+ protected Properties getNamingProperties(String namingFactoryClass, boolean autoDiscovery)
+ throws Exception
+ {
+ String[] urls = getHANamingURLs();
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, namingFactoryClass);
+ env.setProperty(Context.PROVIDER_URL, urls[0]);
+ // Don't let the discovery packet off the test server so we don't
+ // get spurious responses from other servers on the network
+ env.setProperty("jnp.discoveryTTL", DISCOVERY_TTL);
+
+ if (!autoDiscovery)
+ {
+ env.setProperty("jnp.disableDiscovery", "true");
+ }
+ else if (DISCOVERY_GROUP != null && "".equals(DISCOVERY_GROUP) == false)
+ {
+ // Use the multicast address this test environment is using
+ env.put("jnp.discoveryGroup", DISCOVERY_GROUP);
+ }
+
+ return env;
+ }
+
+ protected String getJndiSuffix()
+ {
+ return "_Retry";
+ }
+
+ protected void configureCluster() throws Exception
+ {
+ RMIAdaptor[] adaptors = getAdaptors();
+
+ if (!isDeployed0())
+ {
+ deploy(adaptors[0], "test-retry.ear");
+ getLog().debug("Deployed test-retry.ear on server0");
+ setDeployed0(true);
+ }
+ if (isDeployed1())
+ {
+ undeploy(adaptors[1], "test-retry.ear");
+ getLog().debug("Undeployed test-retry.ear on server1");
+ setDeployed1(false);
+ }
+
+ sleep(2000);
+ }
+
+ protected void reconfigureCluster() throws Exception
+ {
+ RMIAdaptor[] adaptors = getAdaptors();
+ deploy(adaptors[1], "test-retry.ear");
+ setDeployed1(true);
+
+ sleep(2000);
+
+ undeploy(adaptors[0], "test-retry.ear");
+ setDeployed0(false);
+
+ sleep(2000);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (customJndiProperties != null)
+ {
+ try
+ {
+ customJndiProperties.delete();
+ if (customJndiProperties.exists())
+ customJndiProperties.deleteOnExit();
+ }
+ catch (Exception e)
+ {
+ log.error("problem cleaning customJndiProperties", e);
+ }
+
+ customJndiProperties = null;
+ }
+
+ if (customJndiDir != null)
+ {
+ try
+ {
+ customJndiDir.delete();
+ if (customJndiDir.exists())
+ customJndiDir.deleteOnExit();
+ }
+ catch (Exception e)
+ {
+ log.error("problem cleaning customJndiDir", e);
+ }
+
+ customJndiProperties = null;
+ }
+
+ if (System.getProperty("JBossCluster-DoFail") != null)
+ System.setProperty("JBossCluster-DoFail", "false");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ if (isDeployed0())
+ {
+ undeploy(adaptors[0], "test-retry.ear");
+ getLog().debug("Undeployed test-retry.ear on server0");
+ setDeployed0(false);
+}
+ if (isDeployed1())
+ {
+ undeploy(adaptors[1], "test-retry.ear");
+ getLog().debug("Undeployed test-retry.ear on server1");
+ setDeployed1(false);
+ }
+ }
+
+ protected boolean isDeployed0()
+ {
+ return deployed0;
+ }
+
+ protected void setDeployed0(boolean deployed)
+ {
+ deployed0 = deployed;
+ }
+
+ protected boolean isDeployed1()
+ {
+ return deployed1;
+ }
+
+ protected void setDeployed1(boolean deployed)
+ {
+ deployed1 = deployed;
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/SingleRetryInterceptorUnitTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/testbeancluster/test/SingleRetryInterceptorUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/SingleRetryInterceptorUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb2/test/SingleRetryInterceptorUnitTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,98 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.test.cluster.defaultcfg.ejb2.test;
+
+import org.jboss.test.cluster.testutil.DBSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests the SingleRetryInterceptor.
+ *
+ * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class SingleRetryInterceptorUnitTestCase extends RetryInterceptorUnitTestCase
+{
+ // NOTE: these variables must be static as apparently a separate instance
+ // of this class is created for each test.
+ private static boolean deployed0 = false;
+ private static boolean deployed1 = false;
+
+ /**
+ * Create a new SingleRetryInterceptorUnitTestCase.
+ *
+ * @param name
+ */
+ public SingleRetryInterceptorUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new TestSuite(SingleRetryInterceptorUnitTestCase.class));
+
+ // Create an initializer for the test suite
+ DBSetup wrapper = new DBSetup(suite);
+ return wrapper;
+ }
+
+
+ /**
+ * Override the superclass to not expect recovery.
+ */
+ public void testDeferredRecovery() throws Exception
+ {
+ deferredRecoveryTest(false);
+ }
+
+ protected String getJndiSuffix()
+ {
+ return "_SingleRetry";
+ }
+
+ protected boolean isDeployed0()
+ {
+ return deployed0;
+ }
+
+ protected void setDeployed0(boolean deployed)
+ {
+ deployed0 = deployed;
+ }
+
+ protected boolean isDeployed1()
+ {
+ return deployed1;
+ }
+
+ protected void setDeployed1(boolean deployed)
+ {
+ deployed1 = deployed;
+ }
+
+}
\ No newline at end of file
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/FieldBasedSessionPassivationTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/FieldBasedSessionPassivationTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/FieldBasedSessionPassivationTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/FieldBasedSessionPassivationTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ *
+ * 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.test.cluster.defaultcfg.web.field.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.defaultcfg.web.test.SessionPassivationTestCase;
+
+/**
+ * @author bstansberry
+ *
+ */
+public class FieldBasedSessionPassivationTestCase extends SessionPassivationTestCase
+{
+
+ /**
+ * @param name
+ */
+ public FieldBasedSessionPassivationTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-field/";
+ concatenate();
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(FieldBasedSessionPassivationTestCase.class,
+ "jbosscache-helper.sar, http-field.war");
+ return t1;
+ }
+
+ protected String getWarName()
+ {
+ return "http-field";
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/ScopedFieldBasedTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/ScopedFieldBasedTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/ScopedFieldBasedTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.field.test;
+
+import junit.framework.Test;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.multicfg.web.field.test.FieldBasedTestCase;
+
+/**
+ * Clustering test case of get/set under scoped class loader.
+ * Replication granularity is attribute-based.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public class ScopedFieldBasedTestCase
+ extends FieldBasedTestCase
+{
+
+ public ScopedFieldBasedTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-scoped-field/";
+
+ concatenate();
+ }
+
+ protected String getWarName()
+ {
+ return "http-scoped-field";
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(ScopedFieldBasedTestCase.class,
+ "jbosscache-helper.sar, http-scoped-field.war");
+ return t1;
+ }
+
+}
Property changes on: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/field/test/ScopedFieldBasedTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/AttributeBasedSessionPassivationTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/AttributeBasedSessionPassivationTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/AttributeBasedSessionPassivationTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/AttributeBasedSessionPassivationTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * @author bstansberry
+ *
+ */
+public class AttributeBasedSessionPassivationTestCase extends SessionPassivationTestCase
+{
+ /**
+ * @param name
+ */
+ public AttributeBasedSessionPassivationTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-scoped-attr/";
+
+ concatenate();
+ }
+
+ protected String getWarName()
+ {
+ return "http-scoped-attr";
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(AttributeBasedSessionPassivationTestCase.class,
+ "jbosscache-helper.sar, http-scoped-attr.war");
+ return t1;
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/CrossContextCallsTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/CrossContextCallsTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/CrossContextCallsTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/CrossContextCallsTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,151 @@
+package org.jboss.test.cluster.defaultcfg.web.test;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.multicfg.web.test.ScopedTestCase;
+
+public class CrossContextCallsTestCase extends ScopedTestCase
+{
+
+ public CrossContextCallsTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-cross-ctx-first/";
+
+ concatenate();
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(CrossContextCallsTestCase.class,
+ "http-cross-ctx.ear");
+ return t1;
+ }
+
+
+ /**
+ * Disabled; no-op.
+ */
+ public void testExcludeSecuritySubject() throws Exception
+ {
+ return;
+ }
+
+ /**
+ * Disabled; no-op.
+ */
+ public void testSessionBindingEvent() throws Exception
+ {
+ return;
+ }
+
+ protected String makeGet(HttpClient client, String url)
+ throws IOException
+ {
+ getLog().debug("makeGet(): trying to get from url " +url);
+
+ GetMethod method = new GetMethod(url);
+ int responseCode = 0;
+ try
+ {
+ responseCode = client.executeMethod(method);
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("HttpClient executeMethod fails." +e.toString());
+ }
+ assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
+ , responseCode == HttpURLConnection.HTTP_OK);
+
+ String response = extractResponse(method);
+
+ // Release the connection.
+ // method.releaseConnection();
+
+ return response;
+ }
+
+ protected String getWarName()
+ {
+ return "http-cross-ctx-first";
+ }
+
+ /**
+ * Makes a http call to the jsp that retrieves the attribute stored on the
+ * session. When the attribute values mathes with the one retrieved earlier,
+ * we have HttpSessionReplication.
+ * Makes use of commons-httpclient library of Apache
+ *
+ * @param client
+ * @param url
+ * @return session attribute
+ */
+ protected String makeGetWithState(HttpClient client, String url)
+ throws IOException
+ {
+ getLog().debug("makeGetWithState(): trying to get from url " +url);
+ GetMethod method = new GetMethod(url);
+ int responseCode = 0;
+ try
+ {
+ HttpState state = client.getState();
+ responseCode = client.executeMethod(method.getHostConfiguration(),
+ method, state);
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("HttpClient executeMethod fails." +e.toString());
+ }
+ assertTrue("Get OK with url: " +url + " responseCode: " +responseCode,
+ responseCode == HttpURLConnection.HTTP_OK);
+
+ String response = extractResponse(method);
+
+ // Release the connection.
+ // method.releaseConnection();
+
+ return response;
+ }
+
+ private String extractResponse(GetMethod method)
+ throws IOException
+ {
+ Header header = method.getResponseHeader("FIRST");
+
+ assertNotNull("Received FIRST header", header);
+
+ String result = header.getValue();
+
+ assertNotNull("FIRST header not null", result);
+
+ header = method.getResponseHeader("SECOND");
+
+ assertNotNull("Received SECOND header", header);
+
+ String second = header.getValue();
+
+ assertNotNull("FIRST header not null", second);
+
+ result.concat(second);
+
+ // Read the response body.
+ byte[] responseBody = method.getResponseBody();
+ // Use caution: ensure correct character encoding and is not binary data
+ result.concat(new String(responseBody));
+
+ // Release the connection.
+ // method.releaseConnection();
+
+ return result;
+
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetAttributeTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/ScopedSetAttributeTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetAttributeTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetAttributeTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import junit.framework.Test;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.multicfg.web.test.ScopedTestCase;
+
+/**
+ * Clustering test case of get/set under scoped class loader.
+ * Trigger type is set only, i.e., get is not dirty.
+ * And replication granularity is attribute based.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public class ScopedSetAttributeTestCase
+ extends ScopedTestCase
+{
+
+ public ScopedSetAttributeTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-scoped-set-attr/";
+
+ concatenate();
+ }
+
+ protected String getWarName()
+ {
+ return "http-scoped-set-attr";
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(ScopedSetAttributeTestCase.class,
+ "http-scoped-set-attr.war");
+ return t1;
+ }
+
+
+ /**
+ * Test session modify with non-primitive get/modify.
+ *
+ * @throws Exception
+ */
+ public void testNonPrimitiveModify()
+ throws Exception
+ {
+ String attr = "";
+ getLog().debug("Enter testNonPrimitiveModify");
+
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ // Get the Attribute set
+ String attrOld = makeGet(client, baseURL0_ +getUrl);
+
+ // Get the Attribute set
+ makeGet(client, baseURL0_ +modifyNoSetUrl);
+
+ // Get the Attribute set
+ attr = makeGet(client, baseURL0_ +getUrl);
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Make connection to server 1 and get
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr2 = makeGet(client, baseURL1_ +getUrl);
+
+ // Check the result
+ assertEquals("Attributes should be the same", attrOld, attr2);
+ getLog().debug("Exit testNonPrimitiveModify");
+ }
+
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetTriggerTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/ScopedSetTriggerTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetTriggerTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/ScopedSetTriggerTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import junit.framework.Test;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.multicfg.web.test.ScopedTestCase;
+
+/**
+ * Clustering test case of get/set under scoped class loader.
+ * Trigger type is set only, i.e., get is not dirty.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public class ScopedSetTriggerTestCase
+ extends ScopedTestCase
+{
+
+ public ScopedSetTriggerTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-scoped-set/";
+
+ concatenate();
+ }
+
+ protected String getWarName()
+ {
+ return "http-scoped-set";
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(ScopedSetTriggerTestCase.class,
+ "http-scoped-set.war");
+ return t1;
+ }
+
+
+ /**
+ * Test session modify with non-primitive get/modify.
+ *
+ * @throws Exception
+ */
+ public void testNonPrimitiveModify()
+ throws Exception
+ {
+ String attr = "";
+ getLog().debug("Enter testNonPrimitiveModify");
+
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ // Create a method instance.
+ HttpMethod method = new GetMethod(getUrl);
+ // Get the Attribute set
+ String attrOld = makeGet(client, baseURL0_ +getUrl);
+
+ // Get the Attribute set
+ makeGet(client, baseURL0_ +modifyNoSetUrl);
+
+ // Get the Attribute set
+ attr = makeGet(client, baseURL0_ +getUrl);
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Make connection to server 1 and get
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr2 = makeGet(client, baseURL1_ +getUrl);
+
+ // Check the result
+ assertEquals("Attributes should be the same", attrOld, attr2);
+ getLog().debug("Exit testNonPrimitiveModify");
+ }
+
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionEventTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/SessionEventTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionEventTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionEventTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import junit.framework.Test;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.testutil.WebTestBase;
+import org.jboss.test.cluster.web.BindingListener;
+import org.jboss.test.cluster.web.SessionListener;
+
+/**
+ * Test case for clustered session event.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public class SessionEventTestCase
+ extends WebTestBase
+{
+
+ public SessionEventTestCase(String name)
+ {
+ super(name);
+
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(SessionEventTestCase.class,
+ "http-sr.war");
+ return t1;
+ }
+
+ public void testSessionBindingEvent()
+ throws Exception
+ {
+ String attr = "";
+ getLog().debug("Enter testSessionBindingEvent");
+
+ String setURLName = "/http-sr/bindSession.jsp" + "?Binding=true";
+ String getURLName = "/http-sr/bindSession.jsp" + "?Binding=false";
+
+ getLog().debug(setURLName + ":::::::" + getURLName);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ attr = makeGet(client, baseURL0_ +setURLName);
+System.out.println("*** Response is " +attr);
+
+ assertNotNull("Http session get", attr);
+ boolean isOK = false;
+ if( attr.indexOf("OK") >= 0 ) isOK = true;
+ assertTrue("Response for session bound event should be", isOK);
+ attr = makeGetWithState(client, baseURL0_ +getURLName);
+ if( attr.indexOf("OK") >= 0 ) isOK = true;
+ assertNotNull("Http session get", attr);
+ assertTrue("Response for session unbound event should be", isOK);
+ }
+
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionPassivationTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/SessionPassivationTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionPassivationTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SessionPassivationTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,330 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.jboss.cache.Fqn;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.testutil.SessionTestUtil;
+import org.jboss.test.cluster.testutil.WebTestBase;
+
+/**
+ * Session passivation tests.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 1.0
+ */
+public class SessionPassivationTestCase
+ extends WebTestBase
+{
+ protected String setUrl;
+ protected String getUrl;
+ protected String modifyUrl;
+ protected String modifyNoSetUrl;
+ protected String removeUrl;
+ protected String invalidateUrl;
+ protected String clearUrl;
+ protected String attrListUrl;
+ protected String bindUrl_;
+ protected String protectedUrl_;
+ protected String securityCheckUrl_;
+ protected String loginFormUrl_;
+ protected String setSecuritySubjectUrl_;
+ protected String getSecuritySubjectUrl_;
+ protected String warName_;
+ protected String setUrlBase_;
+ protected String getUrlBase_;
+ protected String modifyUrlBase_;
+ protected String modifyNoSetUrlBase_;
+ protected String removeUrlBase_;
+ protected String invalidateUrlBase_;
+ protected String clearUrlBase_;
+ protected String bindUrlBase_;
+ protected String attrListUrlBase_;
+ protected String protectedUrlBase_;
+ protected String securityCheckUrlBase_;
+ protected String loginFormUrlBase_;
+ protected String setSecuritySubjectUrlBase_;
+ protected String getSecuritySubjectUrlBase_;
+
+ private ObjectName warObjectName;
+ private String warFqn_;
+
+ public SessionPassivationTestCase(String name)
+ {
+ super(name);
+ warName_ = "/http-scoped/";
+ setUrlBase_ = "setSession.jsp";
+ getUrlBase_ = "getAttribute.jsp";
+ modifyUrlBase_ = "modifyAttribute.jsp";
+ modifyNoSetUrlBase_ = "modifyAttributeNoSet.jsp";
+ removeUrlBase_ = "removeAttribute.jsp";
+ invalidateUrlBase_ = "invalidateSession.jsp";
+ clearUrlBase_ = "clearCache.jsp";
+ bindUrlBase_ = "bindSession.jsp?Binding=";
+ protectedUrlBase_ = "index.html";
+ securityCheckUrlBase_ = "j_security_check";
+ loginFormUrlBase_ = "login.html";
+ attrListUrlBase_ = "attributeNames.jsp";
+ setSecuritySubjectUrlBase_ = "setSecuritySubject.jsp";
+ getSecuritySubjectUrlBase_ = "getSecuritySubject.jsp";
+
+ concatenate();
+ }
+
+ protected void concatenate()
+ {
+ setUrl = warName_ +setUrlBase_;
+ getUrl = warName_ +getUrlBase_;
+ modifyUrl = warName_ +modifyUrlBase_;
+ modifyNoSetUrl = warName_ +modifyNoSetUrlBase_;
+ removeUrl = warName_ +removeUrlBase_;
+ invalidateUrl = warName_ +invalidateUrlBase_;
+ clearUrl = warName_ +clearUrlBase_;
+ bindUrl_ = warName_ + bindUrlBase_;
+ protectedUrl_ = warName_ + protectedUrlBase_;
+ securityCheckUrl_ = warName_ + securityCheckUrlBase_;
+ loginFormUrl_ = warName_ + loginFormUrlBase_;
+ attrListUrl = warName_ + attrListUrlBase_;
+ setSecuritySubjectUrl_ = warName_ + setSecuritySubjectUrlBase_;
+ getSecuritySubjectUrl_ = warName_ + getSecuritySubjectUrlBase_;
+ }
+
+ protected String getWarName()
+ {
+ return "http-scoped";
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(SessionPassivationTestCase.class,
+ "jbosscache-helper.sar, http-scoped.war");
+ return t1;
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ if (warObjectName == null)
+ {
+ String oname = "jboss.web:J2EEApplication=none,J2EEServer=none," +
+ "j2eeType=WebModule,name=//localhost/" + getWarName();
+ warObjectName = new ObjectName(oname);
+
+ RMIAdaptor[] adaptors = getAdaptors();
+
+ Object[] names = {"JSESSION", "localhost", getWarName() };
+ Fqn fqn = new Fqn(names);
+ warFqn_ = fqn.toString();
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+// clear();
+ super.tearDown();
+ }
+
+ /**
+ * Tests the ability to passivate session when max idle for session is reached
+ *
+ * @throws Exception
+ */
+ public void testSessionPassivationWMaxIdle() throws Exception
+ {
+ getLog().debug("Enter testSessionPassivationWMaxActive");
+
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ // Get the Attribute set
+ String attr0 = makeGet(client, baseURL0_ +getUrl);
+
+ // Find out the session id and use it to build an FQN
+ String sessionID = getSessionID(client, servers_[0]);
+ // Strip off the jvmRoute, if there is one
+ sessionID = stripJvmRoute(sessionID);
+ String sessionFqn = "/JSESSION/localhost" + warName_ + sessionID;
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Make connection to server 1 and get
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr1 = makeGet(client, baseURL1_ + getUrl);
+
+ // check for replication first
+ assertEquals("attributes match", attr0, attr1);
+
+ // sleep up to 11 secs to allow max idle to be reached
+ // and tomcat background process to run
+ // assuming that max idle in jboss-web.xml = 10 secs
+ // and tomcat background process is using the default = 10 secs
+ sleepThread(11000);
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ getLog().debug("Session in the cache = " + SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+ //session is passivate should not exist in the cache
+ assertNull("Session is passivated therefore it is not in the cache...", SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+
+ // activate the session by requesting the attrribute
+ // Make connection to server 0 and get
+ setCookieDomainToThisServer(client, servers_[0]);
+ String attr2 = makeGet(client, baseURL0_ + getUrl);
+
+ assertEquals("attribute match after activation", attr0, attr2);
+ }
+
+ /**
+ * Tests the ability to passivate session when max number of active sessions reached
+ *
+ * @throws Exception
+ */
+ public void testSessionPassivationWMaxActive() throws Exception
+ {
+ getLog().debug("Enter testSessionPassivationWMaxActive");
+
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ // Get the Attribute set
+ String attr0 = makeGet(client, baseURL0_ +getUrl);
+
+ // Find out the session id and use it to build an FQN
+ String sessionID = getSessionID(client, servers_[0]);
+ // Strip off the jvmRoute, if there is one
+ sessionID = stripJvmRoute(sessionID);
+ String sessionFqn = "/JSESSION/localhost" + warName_ + sessionID;
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Make connection to server 1 and get
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr1 = makeGet(client, baseURL1_ + getUrl);
+
+ // check for replication first
+ assertEquals("attributes match", attr0, attr1);
+
+ // Create 3 more sessions on server0
+ // assuming that max-active-sessions is set to 20 in jboss-web.xml
+ getLog().debug("current active sessions = " + SessionTestUtil.getSessionIds(adaptors[0], warFqn_));
+ int numberOfActiveSessions = SessionTestUtil.getSessionIds(adaptors[0], warFqn_).size();
+ HttpClient[] clients = new HttpClient[(20 - numberOfActiveSessions + 1)];
+ String[] attrs = new String[clients.length];
+ for (int i = 0; i < clients.length; i++)
+ {
+ clients[i] = new HttpClient();
+ makeGet(clients[i], baseURL0_ +setUrl);
+ attrs[i] = makeGet(clients[i], baseURL0_ + getUrl);
+ // Set cookie domain to server1
+ this.setCookieDomainToThisServer(clients[i], servers_[1]);
+ }
+ getLog().debug("to reach max active sessions we needed to create " + clients.length + " clients");
+
+ getLog().debug("Session in the cache = " + SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+ //session is passivate should not exist in the cache
+ assertNull("Session is passivated therefore it is not in the cache...", SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+
+ // activate the session by requesting the attrribute
+ // Make connection to server 0 and get
+ setCookieDomainToThisServer(client, servers_[0]);
+ String attr2 = makeGet(client, baseURL0_ + getUrl);
+
+ assertEquals("attribute match after activation", attr0, attr2);
+ }
+
+ /**
+ * Tests the ability to passivate sessions on undeployment of an application
+ * and to activate it on restart or redeployment of an application
+ * @throws Exception
+ */
+ public void testRedeploy() throws Exception
+ {
+ getLog().info("Enter testRedeploy");
+
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ // force deployment
+ RMIAdaptor[] adaptors = getAdaptors();
+ String warName = getWarName() + ".war";
+ deploy(adaptors[0], warName);
+ deploy(adaptors[1], warName);
+
+ sleep(2000);
+
+ // the code above should be removed when we figure out what's wrong
+ // with configure cluster.
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ // replicate the session to server1
+ sleepThread(DEFAULT_SLEEP);
+
+ // Get the Attribute set
+ String attr = makeGetWithState(client, baseURL0_ +getUrl);
+
+ // Make connection to server 1 and get
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr2 = makeGetWithState(client, baseURL1_ + getUrl);
+
+ assertEquals("attribute match", attr, attr2);
+
+
+
+ // undeploy server0, which passivates the session to the distributed store
+ undeploy(adaptors[0], warName);
+
+
+ sleep(2000);
+ // redeploy the application on server 0
+ deploy(adaptors[0], warName);
+
+ sleep(2000);
+
+ // Get the Attribute using the same session ID
+ setCookieDomainToThisServer(client, servers_[0]);
+ String attr0 = makeGet(client, baseURL0_ +getUrl);
+
+ assertEquals("attributeMatches after activation", attr0, attr);
+
+ getLog().debug("Exit testRedeploy");
+
+ }
+}
Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SimpleTestCase.java (from rev 64055, trunk/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SimpleTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/SimpleTestCase.java 2007-07-24 02:35:13 UTC (rev 64211)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test.cluster.defaultcfg.web.test;
+
+import junit.framework.Test;
+import org.apache.commons.httpclient.HttpClient;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.testutil.SessionTestUtil;
+import org.jboss.test.cluster.testutil.WebTestBase;
+
+/**
+ * Simple clustering test case of get/set.
+ *
+ * @author Ben Wang
+ * @version $Revision: 1.0
+ */
+public class SimpleTestCase
+ extends WebTestBase
+{
+
+ public SimpleTestCase(String name)
+ {
+ super(name);
+
+ }
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = JBossClusteredTestCase.getDeploySetup(SimpleTestCase.class,
+ "jbosscache-helper.sar, http-sr.war");
+ return t1;
+ }
+
+ /**
+ * Main method that deals with the Http Session Replication Test
+ *
+ * @throws Exception
+ */
+ public void testHttpSessionReplication()
+ throws Exception
+ {
+ String attr = "";
+ getLog().debug("Enter testHttpSessionReplication");
+
+ String setURLName = "/http-sr/testsessionreplication.jsp";
+ String getURLName = "/http-sr/getattribute.jsp";
+
+ getLog().debug(setURLName + ":::::::" + getURLName);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setURLName);
+
+ // Get the Attribute set by testsessionreplication.jsp
+ attr = makeGetWithState(client, baseURL0_ +getURLName);
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Let's switch to server 2 to retrieve the session attribute.
+ setCookieDomainToThisServer(client, servers_[1]);
+ String attr2 = makeGet(client, baseURL1_ +getURLName);
+
+ // Check the result
+ assertEquals("Http session replication attribtues retrieved from both servers ", attr, attr2);
+
+ getLog().debug("Http Session Replication has happened");
+ getLog().debug("Exit testHttpSessionReplication");
+ }
+
+ /**
+ * Tests that sessions time out properly and that activity
+ * on one cluster node prevents timeout on another.
+ */
+ public void testSessionTimeout()
+ throws Exception
+ {
+ String attr = "";
+ String attr2 = "";
+ getLog().debug("Enter testSessionTimeout");
+
+ String setURLName = "/http-sr/testsessionreplication.jsp";
+ String getURLName = "/http-sr/getattribute.jsp";
+
+ getLog().debug(setURLName + ":::::::" + getURLName);
+
+ // Create a session on server0
+ HttpClient client = new HttpClient();
+ makeGet(client, baseURL0_ +setURLName);
+
+ // Create a session on server 1.
+ HttpClient client1 = new HttpClient();
+ makeGet(client1, baseURL1_ +setURLName);
+
+ // Find out the session id and use it to build an FQN
+ String sessionID = getSessionID(client1, servers_[1]);
+ // Strip off the jvmRoute, if there is one
+ sessionID = stripJvmRoute(sessionID);
+ String sessionFqn = "/JSESSION/localhost/http-sr/" + sessionID;
+
+ sleepThread(6000);
+
+ // Set the server0 session to ensure replication occurs
+ attr = makeGetWithState(client, baseURL0_ +setURLName);
+ // Get the Attribute set by testsessionreplication.jsp
+ attr = makeGetWithState(client, baseURL0_ +getURLName);
+ assertNotNull("Http session get", attr);
+
+ // Sleep 15 secs. This plus the previous 6 secs is enough to expire
+ // session0 on server1 if replication failed to keep it alive
+ sleepThread(15000);
+
+ // Switch to the other server and check if 1st session is alive
+ setCookieDomainToThisServer(client, servers_[1]);
+ attr2 = makeGetWithState(client, baseURL1_ +getURLName);
+
+ // Check the result
+ assertEquals("Http session replication attributes retrieved from both servers ", attr, attr2);
+
+ getLog().debug("Replication has kept the session alive");
+
+ // sleep 6 more seconds so session0 will expire on server0
+ sleepThread(6000);
+
+ // Confirm first session is expired on node 0
+ setCookieDomainToThisServer(client, servers_[0]);
+ attr = makeGetWithState(client, baseURL0_ +getURLName);
+ assertFalse("Original session not present", attr2.equals(attr));
+
+ // sleep 45 more seconds so session 1 will expire on server0.
+ // need a total of 70 secs -- 60 to expire and 10 to ensure the
+ // bg thread runs. 20 secs to expire is not enough as the reduced
+ // life of this session is not available to the manager w/o
+ // deserializing the session
+ sleepThread(45000);
+
+ // Confirm 2nd session is gone from the distributed cache on node 0
+ RMIAdaptor[] adaptors = getAdaptors();
+ assertNull("Session gone from distributed cache",
+ SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+ assertNull("Session gone from distributed cache",
+ SessionTestUtil.getBuddySessionVersion(adaptors[0], sessionFqn));
+
+ getLog().debug("Exit testSessionTimeout");
+ }
+
+ public void testMaxUnreplicatedInterval()
+ throws Exception
+ {
+ getLog().debug("Enter testMaxUnreplicatedInterval");
+
+ String setURLName = "/http-sr/testsessionreplication.jsp";
+ String getURLName = "/http-sr/getattribute.jsp";
+ String accessURLName = "/http-sr/access.jsp";
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setURLName);
+ // Get the Attribute set by testsessionreplication.jsp
+ String attr = makeGetWithState(client, baseURL0_ +getURLName);
+
+ // Sleep 90% of the maxInactiveInterval
+ sleepThread(18000);
+
+ // Access the session without touching any attribute
+ makeGet(client, baseURL0_ +accessURLName);
+
+ // Sleep some more, long enough for the session to expire
+ // if access didn't cause replication and for the bg thread to run
+ sleepThread(17000);
+
+ // Switch servers
+ setCookieDomainToThisServer(client, servers_[1]);
+ // Get the Attribute set by testsessionreplication.jsp
+ String attr1 = makeGetWithState(client, baseURL1_ +getURLName);
+
+ assertEquals("Session still present", attr, attr1);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list