[jboss-cvs] JBossAS SVN: r76476 - in projects/ejb3/trunk/transactions/src: test/java/org/jboss/ejb3/test/tx/common and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 30 10:46:01 EDT 2008
Author: wolfc
Date: 2008-07-30 10:46:01 -0400 (Wed, 30 Jul 2008)
New Revision: 76476
Added:
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AbstractGreeterBean.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/Greeter.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/AfterCompletionTestBean.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/unit/AfterCompletionTestCase.java
Modified:
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java
Log:
EJBTHREE-1445: check for if the transaction has already been rolled back or committed
Modified: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java 2008-07-30 14:45:06 UTC (rev 76475)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java 2008-07-30 14:46:01 UTC (rev 76476)
@@ -97,10 +97,21 @@
throw new IllegalStateException("getRollbackOnly() not allowed without a transaction.");
// EJBTHREE-805, consider an asynchronous rollback due to timeout
+ // This is counter to EJB 3.1 where an asynchronous call does not inherit the transaction context!
+
int status = tm.getStatus();
- return status == Status.STATUS_MARKED_ROLLBACK
- || status == Status.STATUS_ROLLING_BACK
- || status == Status.STATUS_ROLLEDBACK;
+ if(log.isTraceEnabled())
+ log.trace("Current transaction status is " + status);
+ switch(status)
+ {
+ case Status.STATUS_COMMITTED:
+ case Status.STATUS_ROLLEDBACK:
+ throw new IllegalStateException("getRollbackOnly() not allowed after transaction is completed (EJBTHREE-1445)");
+ case Status.STATUS_MARKED_ROLLBACK:
+ case Status.STATUS_ROLLING_BACK:
+ return true;
+ }
+ return false;
}
catch (SystemException e)
{
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AbstractGreeterBean.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AbstractGreeterBean.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AbstractGreeterBean.java 2008-07-30 14:46:01 UTC (rev 76476)
@@ -0,0 +1,43 @@
+/*
+ * 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.ejb3.test.tx.common;
+
+import javax.annotation.Resource;
+import javax.ejb.EJBContext;
+
+/**
+ * A simple greeter bean with no extra settings.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AbstractGreeterBean
+{
+ // Normally this is injected
+ @Resource
+ protected EJBContext ctx = new MockEJBContext();
+
+ public String sayHi(String name)
+ {
+ return "Hi " + name;
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/Greeter.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/Greeter.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/Greeter.java 2008-07-30 14:46:01 UTC (rev 76476)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.tx.common;
+
+/**
+ * The interface for use of beans which extend AbstractGreeterBean.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Greeter
+{
+ String sayHi(String name);
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/AfterCompletionTestBean.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/AfterCompletionTestBean.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/AfterCompletionTestBean.java 2008-07-30 14:46:01 UTC (rev 76476)
@@ -0,0 +1,74 @@
+/*
+ * 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.ejb3.tx.test.sessionsynchronization;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBException;
+import javax.ejb.Local;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.test.tx.common.AbstractGreeterBean;
+import org.jboss.ejb3.test.tx.common.Greeter;
+import org.jboss.logging.Logger;
+
+/**
+ * getRollbackOnly is not allowed in afterCompletion (EJB 3 4.4.1)
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at Local(Greeter.class)
+public class AfterCompletionTestBean extends AbstractGreeterBean implements SessionSynchronization
+{
+ private static final Logger log = Logger.getLogger(AfterCompletionTestBean.class);
+
+ public static String result = null;
+
+ public void afterBegin() throws EJBException, RemoteException
+ {
+ }
+
+ public void afterCompletion(boolean committed) throws EJBException, RemoteException
+ {
+ try
+ {
+ ctx.getRollbackOnly();
+ result = "allowed";
+ }
+ catch(IllegalStateException e)
+ {
+ result = "disallowed";
+ }
+ catch(Exception e)
+ {
+ result = e.getMessage();
+ log.error("getRollbacjOnly failed", e);
+ }
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/unit/AfterCompletionTestCase.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/unit/AfterCompletionTestCase.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/tx/test/sessionsynchronization/unit/AfterCompletionTestCase.java 2008-07-30 14:46:01 UTC (rev 76476)
@@ -0,0 +1,75 @@
+/*
+ * 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.ejb3.tx.test.sessionsynchronization.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URL;
+
+import org.jboss.ejb3.test.tx.common.Greeter;
+import org.jboss.ejb3.test.tx.common.StatefulContainer;
+import org.jboss.ejb3.test.tx.mc.UnitTestBootstrap;
+import org.jboss.ejb3.tx.test.sessionsynchronization.AfterCompletionTestBean;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AfterCompletionTestCase
+{
+ private static UnitTestBootstrap bootstrap;
+ private static StatefulContainer<AfterCompletionTestBean> container;
+
+ private static URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ bootstrap = new UnitTestBootstrap();
+ bootstrap.deploy(getResource("instance/beans.xml"));
+
+ container = new StatefulContainer<AfterCompletionTestBean>("AfterCompletionTest", "Stateful Container", AfterCompletionTestBean.class);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ if(bootstrap != null)
+ bootstrap.shutdown();
+ }
+
+ @Test
+ public void test1() throws Throwable
+ {
+ Greeter bean = container.constructProxy(Greeter.class);
+
+ bean.sayHi("me");
+
+ assertEquals("disallowed", AfterCompletionTestBean.result);
+ }
+}
More information about the jboss-cvs-commits
mailing list