[jboss-cvs] JBossAS SVN: r102090 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3/stateful and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 8 17:07:11 EST 2010
Author: wolfc
Date: 2010-03-08 17:07:11 -0500 (Mon, 08 Mar 2010)
New Revision: 102090
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTRemoteBusiness.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationRemoteBusiness.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/ImplementsSessionSynchronizationUnitTestCase.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/SessionSynchronizationInterceptor.java
Log:
JBPAPP-2290: fixed tx synchronized flag (merged 71139)
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2010-03-08 22:06:51 UTC (rev 102089)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2010-03-08 22:07:11 UTC (rev 102090)
@@ -2305,6 +2305,13 @@
</jar>
</target>
+ <target name="jbpapp2290"
+ description="Builds a simple jar files."
+ depends="compile-classes">
+
+ <build-simple-jar name="jbpapp2290"/>
+ </target>
+
<target name="jbpapp2811"
description="Builds a simple jar files."
depends="compile-classes">
@@ -4127,6 +4134,7 @@
jbpapp1668,
jbpapp1951,
jbpapp2260,
+ jbpapp2290,
jbpapp2811,
jbas4489, epcpropagation, jaccpropagation,
aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
@@ -4820,6 +4828,9 @@
<antcall target="test" inheritRefs="true">
<param name="test" value="jbpapp2260"/>
</antcall>
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="jbpapp2290"/>
+ </antcall>
<antcall target="test" inheritRefs="true">
<param name="test" value="jbpapp2811"/>
</antcall>
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/SessionSynchronizationInterceptor.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/SessionSynchronizationInterceptor.java 2010-03-08 22:06:51 UTC (rev 102089)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/stateful/SessionSynchronizationInterceptor.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -22,6 +22,7 @@
package org.jboss.ejb3.stateful;
import java.rmi.RemoteException;
+
import javax.ejb.EJBException;
import javax.ejb.SessionSynchronization;
import javax.transaction.RollbackException;
@@ -30,9 +31,11 @@
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.logging.Logger;
/**
* Comment
@@ -42,6 +45,8 @@
*/
public class SessionSynchronizationInterceptor implements Interceptor
{
+ private static final Logger log = Logger.getLogger(SessionSynchronizationInterceptor.class);
+
private TransactionManager tm;
public SessionSynchronizationInterceptor()
@@ -102,33 +107,28 @@
}
}
- protected void registerSessionSynchronization(StatefulBeanContext ctx) throws SystemException
+ protected void registerSessionSynchronization(StatefulBeanContext ctx) throws RemoteException, SystemException
{
if (ctx.isTxSynchronized()) return;
Transaction tx = tm.getTransaction();
if (tx == null) return;
+ // tx.registerSynchronization will throw RollbackException, so no go
if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) return;
SFSBSessionSynchronization synch = new SFSBSessionSynchronization(ctx);
- SessionSynchronization bean = (SessionSynchronization) ctx.getInstance();
try
{
- bean.afterBegin();
+ tx.registerSynchronization(synch);
}
- catch (EJBException e)
+ catch(RollbackException e)
{
- throw e;
- }
- catch (RemoteException e)
- {
+ log.warn("Unexpected RollbackException from tx " + tx + " with status " + tx.getStatus());
throw new EJBException(e);
}
- try
- {
- tx.registerSynchronization(synch);
- }
- catch (RollbackException ignore)
- {
- }
+ // Notify StatefulInstanceInterceptor that the synch will take care of the release.
+ ctx.setTxSynchronized(true);
+ SessionSynchronization bean = (SessionSynchronization) ctx.getInstance();
+ // EJB 3 4.3.7 paragraph 2
+ bean.afterBegin();
}
public Object invoke(Invocation invocation) throws Throwable
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTBean.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -0,0 +1,154 @@
+/*
+ * 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.jbpapp2290;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remote;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ImplementsSessionSynchronizationBMTBean
+ *
+ * A test SFSB that directly implements SessionSynchronization
+ *
+ * JBPAPP-2290 (incorporates EJBTHREE-995)
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:tkobayas at redhat.com">Toshiya Kobayashi</a>
+ * @version $Revision$
+ */
+ at TransactionManagement(value=TransactionManagementType.BEAN)
+ at Stateful
+ at Remote(ImplementsSessionSynchronizationBMTRemoteBusiness.class)
+public class ImplementsSessionSynchronizationBMTBean
+ implements
+ ImplementsSessionSynchronizationBMTRemoteBusiness,
+ SessionSynchronization
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ImplementsSessionSynchronizationBMTBean.class);
+
+ /*
+ * Define some counters to be used by the test.
+ */
+ public int CALLS_AFTER_BEGIN = 0;
+
+ public int CALLS_AFTER_COMPLETION = 0;
+
+ public int CALLS_BEFORE_COMPLETION = 0;
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * A simple invocation that implements no business logic
+ */
+ public void call()
+ {
+ }
+
+ /**
+ * begin transaction
+ */
+ public void beginTx() throws Exception
+ {
+ Context context = new InitialContext();
+ UserTransaction ut = (UserTransaction)context.lookup("UserTransaction");
+ log.info("ut.begin()");
+ ut.begin();
+ }
+
+ /**
+ * commit transaction
+ */
+ public void commitTx() throws Exception
+ {
+ Context context = new InitialContext();
+ UserTransaction ut = (UserTransaction)context.lookup("UserTransaction");
+ log.info("ut.commit()");
+ ut.commit();
+ }
+
+
+
+ public void afterBegin() throws EJBException, RemoteException
+ {
+ log.info("afterBegin");
+ CALLS_AFTER_BEGIN++;
+ }
+
+ public void afterCompletion(boolean committed) throws EJBException, RemoteException
+ {
+ log.info("afterCompletion");
+ CALLS_AFTER_COMPLETION++;
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ log.info("beforeCompletion");
+ CALLS_BEFORE_COMPLETION++;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Resets the SessionSynchronization counters
+ */
+ public void resetCounters()
+ {
+ CALLS_AFTER_BEGIN = 0;
+ CALLS_AFTER_COMPLETION = 0;
+ CALLS_BEFORE_COMPLETION = 0;
+ }
+
+ public int getCounterAfterBegin() {
+ return CALLS_AFTER_BEGIN;
+ }
+
+ public int getCounterAfterCompletion() {
+ return CALLS_AFTER_COMPLETION;
+ }
+
+ public int getCounterBeforeCompletion() {
+ return CALLS_BEFORE_COMPLETION;
+ }
+
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTBean.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTRemoteBusiness.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTRemoteBusiness.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTRemoteBusiness.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -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.jbpapp2290;
+
+/**
+ * ImplementsSessionSynchronizationBMTRemoteBusiness
+ *
+ * Remote Business interface for an EJB directly implementing
+ * SessionSynchronization
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:tkobayas at redhat.com">Toshiya Kobayashi</a>
+ * @version $Revision$
+ */
+public interface ImplementsSessionSynchronizationBMTRemoteBusiness extends ImplementsSessionSynchronizationRemoteBusiness
+{
+ // --------------------------------------------------------------------------------||
+ // Contracts ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ void beginTx() throws Exception;
+ void commitTx() throws Exception;
+
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBMTRemoteBusiness.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBean.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -0,0 +1,129 @@
+/*
+ * 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.jbpapp2290;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remote;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ImplementsSessionSynchronizationBean
+ *
+ * A test SFSB that directly implements SessionSynchronization
+ *
+ * JBPAPP-2290 (incorporates EJBTHREE-995)
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:tkobayas at redhat.com">Toshiya Kobayashi</a>
+ * @version $Revision$
+ */
+ at Stateful
+ at Remote(ImplementsSessionSynchronizationRemoteBusiness.class)
+public class ImplementsSessionSynchronizationBean
+ implements
+ ImplementsSessionSynchronizationRemoteBusiness,
+ SessionSynchronization
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ImplementsSessionSynchronizationBean.class);
+
+ /*
+ * Define some counters to be used by the test.
+ */
+ public int CALLS_AFTER_BEGIN = 0;
+
+ public int CALLS_AFTER_COMPLETION = 0;
+
+ public int CALLS_BEFORE_COMPLETION = 0;
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * A simple invocation that implements no business logic
+ */
+ @TransactionAttribute(value=TransactionAttributeType.REQUIRED)
+ public void call()
+ {
+ }
+
+ public void afterBegin() throws EJBException, RemoteException
+ {
+ log.info("afterBegin");
+ CALLS_AFTER_BEGIN++;
+ }
+
+ public void afterCompletion(boolean committed) throws EJBException, RemoteException
+ {
+ log.info("afterCompletion");
+ CALLS_AFTER_COMPLETION++;
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ log.info("beforeCompletion");
+ CALLS_BEFORE_COMPLETION++;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Resets the SessionSynchronization counters
+ */
+ @TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
+ public void resetCounters()
+ {
+ CALLS_AFTER_BEGIN = 0;
+ CALLS_AFTER_COMPLETION = 0;
+ CALLS_BEFORE_COMPLETION = 0;
+ }
+
+ @TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
+ public int getCounterAfterBegin() {
+ return CALLS_AFTER_BEGIN;
+ }
+
+ @TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
+ public int getCounterAfterCompletion() {
+ return CALLS_AFTER_COMPLETION;
+ }
+
+ @TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)
+ public int getCounterBeforeCompletion() {
+ return CALLS_BEFORE_COMPLETION;
+ }
+
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationBean.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationRemoteBusiness.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationRemoteBusiness.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationRemoteBusiness.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -0,0 +1,53 @@
+/*
+ * 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.jbpapp2290;
+
+/**
+ * ImplementsSessionSynchronizationRemoteBusiness
+ *
+ * Remote Business interface for an EJB directly implementing
+ * SessionSynchronization
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:tkobayas at redhat.com">Toshiya Kobayashi</a>
+ * @version $Revision$
+ */
+public interface ImplementsSessionSynchronizationRemoteBusiness
+{
+ // --------------------------------------------------------------------------------||
+ // Contracts ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * A simple invocation that implements no business logic
+ */
+ void call();
+
+ /**
+ * Helper method for test
+ */
+ void resetCounters();
+ int getCounterAfterBegin();
+ int getCounterAfterCompletion();
+ int getCounterBeforeCompletion();
+
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/ImplementsSessionSynchronizationRemoteBusiness.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/ImplementsSessionSynchronizationUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/ImplementsSessionSynchronizationUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/ImplementsSessionSynchronizationUnitTestCase.java 2010-03-08 22:07:11 UTC (rev 102090)
@@ -0,0 +1,205 @@
+/*
+ * 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.
+ */
+/*
+ * 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.jbpapp2290.unit;
+
+import javax.ejb.SessionSynchronization;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.test.common.EJB3TestCase;
+
+import org.jboss.ejb3.test.jbpapp2290.ImplementsSessionSynchronizationBean;
+import org.jboss.ejb3.test.jbpapp2290.ImplementsSessionSynchronizationRemoteBusiness;
+import org.jboss.ejb3.test.jbpapp2290.ImplementsSessionSynchronizationBMTBean;
+import org.jboss.ejb3.test.jbpapp2290.ImplementsSessionSynchronizationBMTRemoteBusiness;
+import org.jboss.logging.Logger;
+
+/**
+ * ImplementsSessionSynchronizationUnitTestCase
+ *
+ * Test Cases to validate JBPAPP-2290 (incorporates EJBTHREE-995)
+ * is resolved
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:tkobayas at redhat.com">Toshiya Kobayashi</a>
+ * @version $Revision$
+ */
+public class ImplementsSessionSynchronizationUnitTestCase extends EJB3TestCase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ImplementsSessionSynchronizationUnitTestCase.class);
+
+ private ImplementsSessionSynchronizationRemoteBusiness sfsb;
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public ImplementsSessionSynchronizationUnitTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Tests that an invocation to a SFSB implementing SessionSynchronization for CMT
+ * does not result in 2 calls to any of the SessionSynchronization callbacks
+ */
+ public void testSfsbImplementingSessionSynchronizationForDoubleCallbacks() throws Throwable
+ {
+ // Define JNDI Target for Lookup
+ String jndiName = ImplementsSessionSynchronizationBean.class.getSimpleName() + "/" + "remote";
+
+ // Get JNDI Context
+ Context context = new InitialContext();
+
+ // Obtain
+ sfsb = (ImplementsSessionSynchronizationRemoteBusiness) context
+ .lookup(jndiName);
+
+ // Check callbacks are reset
+ this.assertCallbacksReset();
+
+ // Invoke
+ sfsb.call();
+
+ // Check callbacks have been made exactly once
+ this.assertCallsExpected(1);
+
+ // Invoke again
+ sfsb.call();
+
+ // Check callbacks have been made exactly twice
+ this.assertCallsExpected(2);
+
+ // Invoke again
+ sfsb.call();
+
+ // Check callbacks have been made exactly three times
+ this.assertCallsExpected(3);
+
+ // Reset
+ sfsb.resetCounters();
+
+ // Check callbacks are reset
+ this.assertCallbacksReset();
+ }
+
+ /**
+ * Tests that an invocation to a SFSB implementing SessionSynchronization for BMT
+ * does not result in duplicate calls to the SessionSynchronization callbacks after multiple method invocations within Tx.
+ */
+ public void testSfsbImplementingSessionSynchronizationBMTForDoubleCallbacks() throws Throwable
+ {
+ // Define JNDI Target for Lookup
+ String jndiName = ImplementsSessionSynchronizationBMTBean.class.getSimpleName() + "/" + "remote";
+
+ // Get JNDI Context
+ Context context = new InitialContext();
+
+ // Obtain
+ sfsb = (ImplementsSessionSynchronizationBMTRemoteBusiness) context
+ .lookup(jndiName);
+
+ // Check callbacks are reset
+ this.assertCallbacksReset();
+
+ // begin Tx
+ ((ImplementsSessionSynchronizationBMTRemoteBusiness)sfsb).beginTx();
+
+ // Invoke 3times
+ sfsb.call();
+ sfsb.call();
+ sfsb.call();
+
+ // commit Tx
+ ((ImplementsSessionSynchronizationBMTRemoteBusiness)sfsb).commitTx();
+
+ // Check callbacks have been made exactly once
+ this.assertCallsExpected(1);
+
+ // Reset
+ sfsb.resetCounters();
+
+ // Check callbacks are reset
+ this.assertCallbacksReset();
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that all SessionSynchronization callbacks are reset to 0
+ */
+ protected void assertCallbacksReset()
+ {
+ int expectedCalls = 0;
+ this.assertCallsExpected(expectedCalls);
+ }
+
+ /**
+ * Ensures that all SessionSynchronization callbacks have been
+ * made the specified number of times
+ *
+ * @param numCalls
+ */
+ protected void assertCallsExpected(int numCalls)
+ {
+ TestCase.assertEquals(numCalls, sfsb.getCounterAfterBegin());
+ TestCase.assertEquals(numCalls, sfsb.getCounterAfterCompletion());
+ TestCase.assertEquals(numCalls, sfsb.getCounterBeforeCompletion());
+ log.info("All " + SessionSynchronization.class.getSimpleName() + " callbacks were obtained expected " + numCalls
+ + " times.");
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(ImplementsSessionSynchronizationUnitTestCase.class, "jbpapp2290.jar");
+ }
+
+}
Property changes on: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2290/unit/ImplementsSessionSynchronizationUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list