[jboss-cvs] JBossAS SVN: r110776 - in projects/ejb3/trunk/testsuite: src/test/java/org/jboss/ejb3/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 25 03:39:24 EST 2011
Author: jaikiran
Date: 2011-02-25 03:39:23 -0500 (Fri, 25 Feb 2011)
New Revision: 110776
Added:
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/BMTBean.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/TxActivity.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/unit/
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/unit/BMTxTestCase.java
Modified:
projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-2238 Testcase for making sure that a BMT bean isn't invoked in a CMT context
Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml 2011-02-25 08:34:12 UTC (rev 110775)
+++ projects/ejb3/trunk/testsuite/build-test.xml 2011-02-25 08:39:23 UTC (rev 110776)
@@ -4223,6 +4223,10 @@
</jar>
</target>
+ <target name="ejbthree2238">
+ <build-simple-jar name="ejbthree2238"/>
+ </target>
+
<target name="jars" depends="removedislocal, statelesscreation, defaultremotebindings, localfromremote, clusteredjms, concurrentnaming, propertyreplacement, persistenceunits, appclient, tck5sec, invalidtxmdb, descriptortypo, libdeployment, homeinterface, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader,
concurrent,
circulardependency, jsp, timerdependency, servicedependency, stateless14, webservices, ear, ejbthree440,
@@ -4249,6 +4253,7 @@
ejbthree1995,
ejbthree2095,
ejbthree2193,
+ ejbthree2238,
jaxws, jbas4489, epcpropagation, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency,
securitydomain, enventry, security5,
jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions,
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/BMTBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/BMTBean.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/BMTBean.java 2011-02-25 08:39:23 UTC (rev 110776)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., 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.ejb3.test.ejbthree2238;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.annotation.TransactionTimeout;
+import org.jboss.logging.Logger;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Author : Jaikiran Pai
+ */
+ at Stateless
+ at TransactionManagement(value = TransactionManagementType.BEAN)
+ at Remote(TxActivity.class)
+ at RemoteBinding(jndiBinding = BMTBean.JNDI_NAME)
+ at TransactionTimeout(value = BMTBean.FIVE_SECOND_TIMEOUT) // 5 second timeout
+public class BMTBean implements TxActivity
+{
+ public static final String JNDI_NAME = "ejbthree-2238-BMTBean";
+
+ private static final Logger logger = Logger.getLogger(BMTBean.class);
+
+ static final int FIVE_SECOND_TIMEOUT = 5;
+
+ @Resource (mappedName = "java:DefaultDS")
+ private DataSource ds;
+
+ public void doTxStuff()
+ {
+ try
+ {
+ int SEVEN_SECONDS_IN_MILLIS = (FIVE_SECOND_TIMEOUT + 2) * 1000;
+ logger.info("Sleeping for " + SEVEN_SECONDS_IN_MILLIS + " milli. seconds for transaction timeout to happen");
+ // sleep for a few seconds longer than the timeout
+ Thread.sleep(SEVEN_SECONDS_IN_MILLIS);
+ }
+ catch (InterruptedException ie)
+ {
+ throw new RuntimeException(ie);
+ }
+ logger.info("Woke up after a nap! Now time to do a tx activity");
+ // now do some dummy tx activity
+ // If the bean was (incorrectly) invoked through a CMT tx context then the tx will have
+ // timedout and we'll run into an exception while doing the tx activity and the test will fail.
+ // However, if the bean was (correctly) invoked as a BMT context then this tx activity will go through fine
+ Connection conn = null;
+ try
+ {
+ conn = ds.getConnection();
+ }
+ catch (SQLException sqle)
+ {
+ throw new RuntimeException(sqle);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (SQLException sqle)
+ {
+ // ignore
+ logger.debug("Ignoring exception that occured during connection close: ", sqle);
+ }
+ }
+ }
+ }
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/TxActivity.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/TxActivity.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/TxActivity.java 2011-02-25 08:39:23 UTC (rev 110776)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., 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.ejb3.test.ejbthree2238;
+
+/**
+ * Author : Jaikiran Pai
+ */
+public interface TxActivity
+{
+ void doTxStuff();
+}
Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/unit/BMTxTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/unit/BMTxTestCase.java (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree2238/unit/BMTxTestCase.java 2011-02-25 08:39:23 UTC (rev 110776)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., 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.ejb3.test.ejbthree2238.unit;
+
+import junit.framework.Test;
+import org.jboss.ejb3.test.ejbthree2238.BMTBean;
+import org.jboss.ejb3.test.ejbthree2238.TxActivity;
+import org.jboss.test.JBossTestCase;
+import org.junit.Assert;
+
+/**
+ * Tests that a bean marked for Bean Managed Transactions isn't picked up by Container Managed Transaction intereceptor.
+ *
+ * @see https://issues.jboss.org/browse/EJBTHREE-2238 for the complete bug details
+ *
+ * Author : Jaikiran Pai
+ */
+public class BMTxTestCase extends JBossTestCase
+{
+ public BMTxTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(BMTxTestCase.class, "ejbthree2238.jar");
+ }
+
+ /**
+ * Tests that the BMT bean isn't invoked in a CMT context.
+ *
+ * @see https://issues.jboss.org/browse/EJBTHREE-2238
+ * @throws Exception
+ */
+ public void testBMTxManagement() throws Exception
+ {
+ TxActivity bmtBean = (TxActivity) this.getInitialContext().lookup(BMTBean.JNDI_NAME);
+ bmtBean.doTxStuff();
+ }
+}
More information about the jboss-cvs-commits
mailing list