3 Replies Latest reply on Mar 16, 2009 8:51 PM by Agata Przybyszewska

    DBUnitSeamTest

    Tom Goring Apprentice

      Hi,


      I'm trying to do some transactional tests using DBUnitSeamTest.


      To simulate 2 hibernate sessions (say an update at a later point) I'm doing:



      public class TestContractManager extends DBUnitSeamTest {
      ..
         @Test
         public void testCRUD() throws Exception {
            new ComponentTest() {
               @Override
               protected void testComponents() throws Exception {
                   // Setup Data
               }
            }.run();
      
            new ComponentTest() {
               @Override
               protected void testComponents() throws Exception {
                   // Do some stuff in another transaction
               }
            }.run();
         }
      



      However I get the attached stack.  Is creating 2 ComponentTest's a valid way to simulate 2 sessions ?


      N.B. My code is working OK when deployed for real in Jboss.
      I think it's an issue with how i'm using DBUnitSeamTest or my test env test up.



      java.lang.RuntimeException: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
           at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
           at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
           at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:193)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
           at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:105)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
           at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
           at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
           at $Proxy81.updateContract(Unknown Source)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
           at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
           at org.javassist.tmp.java.lang.Object_$$_javassist_16.updateContract(Object_$$_javassist_16.java)
           at jnet.emtest.bl.company.TestContractManager$3.testComponents(TestContractManager.java:150)
           at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:170)
           at jnet.emtest.bl.company.TestContractManager.testCRUDKids(TestContractManager.java:153)
      Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
           at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1267)
           at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
           at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
           at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
           ... 54 more
      Caused by: javax.persistence.PersistenceException: java.lang.IllegalArgumentException: Removing a detached instance jnet.dm.company.ContractRate#2
           at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
           at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
           at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
           at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
           at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
           at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
           ... 57 more
      Caused by: java.lang.IllegalArgumentException: Removing a detached instance jnet.dm.company.ContractRate#2
           at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:47)
           at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:75)
           at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:775)
           at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:758)
           at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:355)
           at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:324)
           at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
           at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
           at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
           at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
           at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
           at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
           at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
           at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
           at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
           at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
           at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
      


        • 1. Re: DBUnitSeamTest
          Pete Muir Master

          Try doing it in a FacesRequest

          • 2. Re: DBUnitSeamTest
            Tom Goring Apprentice

            Hi Pete,


            Yep that worked.  I was testing my service layer (not my web actions) so figured that a ComponentTest was the way do go.  It seems to work for some things but not in my example. 


            Changed to:



            public class TestContractManager extends DBUnitSeamTest {
            ..
               @Test
               public void testCRUD() throws Exception {
                  new FacesRequest() {
                     @Override
                     protected void invokeApplication() throws Exception {
                         // Setup Data
                     }
                  }.run();
            
                  new FacesRequest() {
                     @Override
                     protected void invokeApplication() throws Exception {
                         // Do some stuff in another transaction
                     }
                  }.run();
               }


            • 3. Re: DBUnitSeamTest
              Agata Przybyszewska Newbie

              Perhaps you could share your setup for running DBUnitSeamTests ?
              We managed to get up and running with FacesRequests, but have a hard time convincing DBUnitSeamTest to run ...
              Agata