[jboss-cvs] JBossAS SVN: r112085 - in branches/JBPAPP_5_1: testsuite and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 17 04:18:02 EDT 2011
Author: pferraro
Date: 2011-08-17 04:18:01 -0400 (Wed, 17 Aug 2011)
New Revision: 112085
Added:
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionSticky.java
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java
Modified:
branches/JBPAPP_5_1/component-matrix/pom.xml
branches/JBPAPP_5_1/testsuite/build.xml
branches/JBPAPP_5_1/testsuite/imports/config/tests-clustering.xml
branches/JBPAPP_5_1/testsuite/imports/sections/cluster.xml
branches/JBPAPP_5_1/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml
Log:
JBPAPP-7015 Add EJB3 Transaction Stickiness Load Balancing Policies
Modified: branches/JBPAPP_5_1/component-matrix/pom.xml
===================================================================
--- branches/JBPAPP_5_1/component-matrix/pom.xml 2011-08-17 08:00:16 UTC (rev 112084)
+++ branches/JBPAPP_5_1/component-matrix/pom.xml 2011-08-17 08:18:01 UTC (rev 112085)
@@ -65,7 +65,7 @@
<version.org.jboss.cl>2.0.9.GA</version.org.jboss.cl>
<version.org.jboss.cluster.cache.jbc>2.0.3.Final</version.org.jboss.cluster.cache.jbc>
<version.org.jboss.cluster.cache.spi>2.0.0.GA</version.org.jboss.cluster.cache.spi>
- <version.org.jboss.cluster.client>1.1.1.GA</version.org.jboss.cluster.client>
+ <version.org.jboss.cluster.client>1.1.3.Final</version.org.jboss.cluster.client>
<version.org.jboss.cluster.server.api>1.2.0.Final</version.org.jboss.cluster.server.api>
<version.org.jboss.common.core>2.2.17.GA</version.org.jboss.common.core>
<version.org.jboss.deployers>2.0.10.GA</version.org.jboss.deployers>
Modified: branches/JBPAPP_5_1/testsuite/build.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/build.xml 2011-08-17 08:00:16 UTC (rev 112084)
+++ branches/JBPAPP_5_1/testsuite/build.xml 2011-08-17 08:18:01 UTC (rev 112085)
@@ -174,6 +174,7 @@
<path refid="jboss.jboss.ejb3.ext.api.classpath" />
<path refid="jboss.jboss.ejb3.proxy.impl.classpath" />
<path refid="jboss.jboss.ejb3.proxy.spi.classpath" />
+ <path refid="jboss.jboss.ejb3.transactions.classpath" />
<path refid="ejb3-persistence.classpath"/>
<path refid="org.jboss.ws.native.classpath"/>
<path refid="org.jboss.spec.javax.xml.rpc.classpath"/>
@@ -326,6 +327,8 @@
<pathelement path="${jboss.dist.client}/jboss-remoting.jar" />
<!-- path refid="jboss.serialization.classpath"/ -->
<pathelement path="${jboss.dist.client}/jboss-serialization.jar" />
+ <!-- path refid="jboss.jboss.ejb3.context.base.classpath" / -->
+ <pathelement path="${jboss.dist.common.lib}/jboss-ejb3-context-base.jar" />
<!-- path refid="jboss.jboss.ejb3.core.classpath" / -->
<pathelement path="${jboss.dist.client}/jboss-ejb3-core-client.jar" />
<pathelement path="${jboss.dist.common.lib}/jboss-ejb3-core.jar" />
Modified: branches/JBPAPP_5_1/testsuite/imports/config/tests-clustering.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/imports/config/tests-clustering.xml 2011-08-17 08:00:16 UTC (rev 112084)
+++ branches/JBPAPP_5_1/testsuite/imports/config/tests-clustering.xml 2011-08-17 08:18:01 UTC (rev 112085)
@@ -63,7 +63,7 @@
<include name="org/jboss/test/cluster/defaultcfg/profileservice/test/*TestCase.class"/>
</patternset>
<patternset id="cluster.ustxsticky.includes">
- <include name="org/jboss/test/cluster/defaultcfg/ejb2/ustxsticky/test/UserTransactionStickyUnitTestCase.class"/>
+ <include name="org/jboss/test/cluster/defaultcfg/ejb*/ustxsticky/test/UserTransactionStickyUnitTestCase.class"/>
</patternset>
<patternset id="cluster.mod_cluster.includes">
<include name="org/jboss/test/cluster/mod_cluster/ModClusterServiceTestCase.class"/>
Modified: branches/JBPAPP_5_1/testsuite/imports/sections/cluster.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/imports/sections/cluster.xml 2011-08-17 08:00:16 UTC (rev 112084)
+++ branches/JBPAPP_5_1/testsuite/imports/sections/cluster.xml 2011-08-17 08:18:01 UTC (rev 112085)
@@ -1065,6 +1065,13 @@
</jar>
-->
+ <!-- ustxsticky-ejb3.jar -->
+ <zip destfile="${build.lib}/ustxsticky-ejb3.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/cluster/ejb3/ustxsticky/*"/>
+ </fileset>
+ </zip>
+
<!-- ustxsticky.jar -->
<zip destfile="${build.lib}/ustxsticky.jar">
<zipfileset dir="${build.resources}/cluster/ejb2/ustxsticky"/>
Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java 2011-08-17 08:18:01 UTC (rev 112085)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.ustxsticky.test;
+
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import junit.framework.Test;
+
+import org.jboss.ha.framework.interfaces.GenericClusteringException;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.ejb3.ustxsticky.UserTransactionSticky;
+
+/**
+ * UserTransactionStickyTestCase.
+ *
+ * @author Paul Ferraro
+ */
+public class UserTransactionStickyUnitTestCase extends JBossClusteredTestCase
+{
+ private static final String deployment = "ustxsticky-ejb3.jar";
+
+ private static final Logger log = Logger.getLogger(UserTransactionStickyUnitTestCase.class);
+
+ public UserTransactionStickyUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(UserTransactionStickyUnitTestCase.class, deployment);
+ }
+
+ public void testSeveralTransactionalStickyCalls() throws Exception
+ {
+ severalTransactionalCalls("ejb3/UserTransactionSticky");
+ }
+
+ private void severalTransactionalCalls(String jndiName) throws Exception
+ {
+ // Connect to the server0 JNDI
+ String[] urls = getNamingURLs();
+ Properties env1 = new Properties();
+ env1.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
+ env1.setProperty(Context.PROVIDER_URL, urls[0]);
+ Context ctx = new InitialContext(env1);
+
+ UserTransactionSticky bean = (UserTransactionSticky)ctx.lookup(jndiName);
+ bean.test(-1);
+ bean.test(-1);
+ bean.test(-1);
+
+ javax.transaction.UserTransaction tx = (javax.transaction.UserTransaction) ctx.lookup("UserTransaction");
+ tx.begin();
+ // Stick tx to a node
+ bean.test(-1);
+ bean.test(-1);
+ bean.test(-1);
+ try
+ {
+ // This should fail since tx prevents failover
+ bean.test(GenericClusteringException.COMPLETED_NO);
+ fail();
+ }
+ catch (Exception e)
+ {
+ assertTrue(e.getMessage(), e.getMessage().startsWith("Current transaction is stuck to"));
+ }
+ tx.rollback();
+
+ // Not in tx anymore
+ bean.test(-1);
+ bean.test(-1);
+ bean.test(-1);
+ try
+ {
+ // This should fail since there are no more cluster members left
+ bean.test(GenericClusteringException.COMPLETED_NO);
+ fail();
+ }
+ catch (Exception e)
+ {
+ assertTrue(e.getMessage(), e.getMessage().startsWith("cluster invocation failed"));
+ }
+ }
+}
Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionSticky.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionSticky.java (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionSticky.java 2011-08-17 08:18:01 UTC (rev 112085)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.ejb3.ustxsticky;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.ejb.Remote;
+import org.jboss.ha.framework.interfaces.GenericClusteringException;
+
+/**
+ * @author Paul Ferraro
+ */
+ at Remote
+public interface UserTransactionSticky
+{
+ void test(int status) throws GenericClusteringException;
+}
Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java 2011-08-17 08:18:01 UTC (rev 112085)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.ustxsticky;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.transaction.Transaction;
+import javax.transaction.UserTransaction;
+
+import org.jboss.aop.DispatcherConnectException;
+import org.jboss.ejb3.annotation.Clustered;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ha.framework.interfaces.GenericClusteringException;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.CannotConnectException;
+import org.jboss.tm.TransactionPropagationContextImporter;
+import org.jboss.tm.TransactionPropagationContextFactory;
+import org.jboss.tm.TransactionPropagationContextUtil;
+
+/**
+ * UserTransactionStickyBean.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+ at Stateless(mappedName = "ejb3/UserTransactionSticky")
+ at Remote(UserTransactionSticky.class)
+ at Clustered(loadBalancePolicy="org.jboss.ha.client.loadbalance.RoundRobin")
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+ at TransactionAttribute(TransactionAttributeType.SUPPORTS)
+public class UserTransactionStickyBean implements UserTransactionSticky
+{
+ private static Logger log = Logger.getLogger(UserTransactionStickyBean.class);
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 3926319963458764127L;
+
+ @Override
+ public void test(int status) throws GenericClusteringException
+ {
+ if (status > 0)
+ {
+ throw new GenericClusteringException(status);
+ }
+ }
+
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ System.out.println(ctx.getMethod().getName());
+ try
+ {
+ javax.transaction.Transaction tx = org.jboss.ejb3.tx.TxUtil.getTransactionManager().getTransaction();
+ System.out.println("Transaction is " + ((tx != null) ? "not " : "") + "null");
+// UserTransaction tpc = this.context.getUserTransaction();
+// System.out.println("UserTransaction is " + ((tpc != null) ? "not " : "") + "null");
+
+ Object tpc = TransactionPropagationContextUtil.getTPCFactoryClientSide().getTransactionPropagationContext();
+ System.out.println("TPC = " + tpc);
+/*
+ UserTransaction tpcFactory = this.context.getUserTransaction();
+ Object tpc = ((TransactionPropagationContextFactory) tpcFactory).getTransactionPropagationContext();
+ TransactionPropagationContextImporter tpcImporter = TransactionPropagationContextUtil.getTPCImporter();
+ Transaction tx = tpcImporter.importTransactionPropagationContext(tpc);
+ */
+ log.debug("Tpc " + tpc + " is associated with tx " + tx);
+
+ /* If a tpc is retrieved on the server side but matches no transaction
+ * there, then it means that invocation was not sticky. An invocation
+ * containing a tpc must, under transaction sticky rules, hit the server
+ * where the tpc was generated from and where the transaction is running.
+ */
+ if (tx == null && tpc != null)
+ {
+ throw new IllegalStateException("Tpc " + tpc + " does not match a transaction on this node, invocation not sticky!");
+ }
+
+ return ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ throw e;
+ }
+ catch (Error e)
+ {
+ e.printStackTrace(System.err);
+ throw e;
+ }
+ }
+}
Modified: branches/JBPAPP_5_1/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml 2011-08-17 08:00:16 UTC (rev 112084)
+++ branches/JBPAPP_5_1/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml 2011-08-17 08:18:01 UTC (rev 112085)
@@ -53,7 +53,7 @@
<container-name>User Transaction Sticky Clustered Stateless SessionBean</container-name>
<invoker-proxy-binding-name>ustxsticky-clustered-stateless-unified-invoker</invoker-proxy-binding-name>
<container-interceptors>
- <interceptor>org.jboss.test.cluster.invokerha.ejb.UserTransactionStickinessVerifierInterceptor</interceptor>
+ <interceptor>org.jboss.test.cluster.ejb2.ustxsticky.UserTransactionStickinessVerifierInterceptor</interceptor>
<interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
<interceptor>org.jboss.ejb.plugins.CleanShutdownInterceptor</interceptor>
<interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
More information about the jboss-cvs-commits
mailing list