4 Replies Latest reply on Nov 23, 2009 11:04 AM by Bernard Labno

    SeamTest and Could not commit transaction

    Bernard Labno Master

      Hello. I'm having strange problems. I have two testing methods A and B. If A is executed before B , then B fails. I've expected that two different methods in seam test simulate two different sessions. So problem in first method should not influence the second. Btw. why does method A print errors, but not throw any exception ?


      Method A succeeds, but prints following :


      WARN  [org.jboss.seam.jsf.SeamPhaseListener] uncaught exception, passing to exception handler
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: TagHome
           at org.jboss.seam.Component.newInstance(Component.java:2106)
           at org.jboss.seam.Component.getInstance(Component.java:1988)
           at org.jboss.seam.Component.getInstance(Component.java:1950)
           at org.jboss.seam.Component.getInstance(Component.java:1944)
           at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
           at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
           at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
           at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
           at org.jboss.seam.core.Validators$ValidatingResolver.getValue(Validators.java:172)
           at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
           at org.jboss.el.parser.AstValue.getTarget(AstValue.java:34)
           at org.jboss.el.parser.AstValue.setValue(AstValue.java:83)
           at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
           at org.jboss.seam.core.Validators.validate(Validators.java:132)
           at org.jboss.seam.navigation.Param.validateConvertedValue(Param.java:243)
           at org.jboss.seam.navigation.Pages.convertAndValidateStringValuesInPageContext(Pages.java:818)
           at org.jboss.seam.navigation.Pages.postRestore(Pages.java:450)
           at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:546)
           at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:392)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:228)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
           at org.jboss.seam.mock.AbstractSeamTest$Request.restoreViewPhase(AbstractSeamTest.java:756)
           at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:583)
           at org.jboss.seam.mock.AbstractSeamTest$Request.access$300(AbstractSeamTest.java:177)
           at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:491)
           at x.TagCRUDTest.enterTagViewAsNonAdmin(TagCRUDTest.java:88)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:607)
           at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
           at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
           at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
           at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
           at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
           at org.testng.TestRunner.runWorkers(TestRunner.java:759)
           at org.testng.TestRunner.privateRun(TestRunner.java:592)
           at org.testng.TestRunner.run(TestRunner.java:486)
           at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
           at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
           at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
           at org.testng.SuiteRunner.run(SuiteRunner.java:204)
           at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:867)
           at org.testng.TestNG.runSuitesLocally(TestNG.java:832)
           at org.testng.TestNG.run(TestNG.java:748)
           at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
           at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
      Caused by: org.jboss.seam.security.AuthorizationException: Authorization check failed for expression [#{s:hasRole('ADMIN')}]
           at org.jboss.seam.security.Identity.checkRestriction(Identity.java:222)
           at org.jboss.seam.security.SecurityInterceptor$Restriction.check(SecurityInterceptor.java:113)
           at org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:159)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at x.TagHome_$$_javassist_6.create(TagHome_$$_javassist_6.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
           at org.jboss.seam.Component.newInstance(Component.java:2094)
           ... 64 more



      Method B prints following and fails :


      java.lang.IllegalStateException: Could not commit transaction
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:626)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:343)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:243)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
           at org.jboss.seam.mock.AbstractSeamTest$Request.invokeApplicationPhase(AbstractSeamTest.java:659)
           at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:595)
           at org.jboss.seam.mock.AbstractSeamTest$Request.access$300(AbstractSeamTest.java:177)
           at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:491)
           at x.XSeamTest.login(XSeamTest.java:104)
           at x.XSeamTest.loginAsAdmin(XSeamTest.java:120)
           at x.TagCRUDTest.editTag(TagCRUDTest.java:57)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:607)
           at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
           at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
           at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
           at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
           at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
           at org.testng.TestRunner.runWorkers(TestRunner.java:759)
           at org.testng.TestRunner.privateRun(TestRunner.java:592)
           at org.testng.TestRunner.run(TestRunner.java:486)
           at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
           at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
           at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
           at org.testng.SuiteRunner.run(SuiteRunner.java:204)
           at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:867)
           at org.testng.TestNG.runSuitesLocally(TestNG.java:832)
           at org.testng.TestNG.run(TestNG.java:748)
           at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
           at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
      Caused by: java.util.EmptyStackException
           at java.util.Stack.peek(Stack.java:85)
           at org.jboss.seam.transaction.SeSynchronizations.beforeTransactionCommit(SeSynchronizations.java:50)
           at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:49)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:614)
           ... 48 more



      Method A :


      @Test(groups = TAG_DEPENDANT_TESTS)
          public void enterTagViewAsNonAdmin() throws Exception {
              loginAsMember();
              try {
              new NonFacesRequest(TAG_VIEW) {
      
                  @Override
                  protected void beforeRequest() {
                      setParameter("id", id.toString());
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      assert Pages.instance().getPage(Pages.getCurrentViewId()).isRestricted();
                  }
      
              }.run();
              }catch(Throwable e) {
                  e.printStackTrace();
              }
          }



      Method B :


      @Test(groups = TAG_DEPENDANT_TESTS)
          public void editTag() throws Exception {
              loginAsAdmin();
              String conversationId = enterTagView(id);
              new InvokedApplicationFacesRequest(TAG_VIEW, conversationId) {
                  @Override
                  protected void invokeApplication() throws Exception {
                      invokeAction("#{tagHome.edit}");
                  }
              }.run();
              new InvokedApplicationFacesRequest(TAG_VIEW, conversationId) {
                  @Override
                  protected void updateModelValues() throws Exception {
                      setValue("#{tagHome.instance.name}", modifiedName);
                  }
      
                  @Override
                  protected void invokeApplication() throws Exception {
                      invokeAction("#{tagHome.update}");
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      Tag tag = (Tag) ((EntityManager) getInstance("entityManager")).createQuery("from Tag where id=?").setParameter(1, id).getSingleResult();
                      assert modifiedName.equals(tag.getName());
                  }
              }.run();
          }

        • 1. Re: SeamTest and Could not commit transaction
          Bernard Labno Master

          Btw. why does method A print errors, but not throw any exception ?

          Ok, i've fooled myself, i caught the exception and printed stack trace. But the rest of problem remains.

          • 2. Re: SeamTest and Could not commit transaction
            Bernard Labno Master

            Actually, no the code does not catch any exception. It is being just printed, not thrown. Even with removed printStackTrace the stack is being printed.

            • 3. Re: SeamTest and Could not commit transaction
              Bernard Labno Master

              Ok, so after long hours of debugging i found out that SeamPhaseListener does not finish transaction properly (transaction remains active and on the next request SeamPhaseListener will not try to begin a new one, but it will also not call getSynchronizations().afterTransactionBegin(), which populates synchronizations stack - the one causing EmptyStackException).


              There are two moments of improper behavior of SeamPhaseListener :
              1. in afterServletPhase method, cause in my case afterRestoreView (but other methods to) throws exception and handleTransactionsAfterPhase is not called, thus transaction remains active (i guess it remains active on server and will be reused on next request, but i might be wrong)
              2. in begin(String phaseString), cause condigion if ( !Transaction.instance().isActiveOrMarkedRollback() ) should also check if synchronizations are installed - what if buy any bug transaction remains active over requests ?


              My precious Seam developers, please comment on this. Also one more question - what is transaction on the server associated with ? I thought it should be with thread, but it seems it is being reused between requests as I experienced.

              • 4. Re: SeamTest and Could not commit transaction
                Bernard Labno Master

                Bump. Guys, this is critical issue. If we get exception thrown in afterServletPhase method i.e. due to permission check after restore view phase, it will not be handled causing problems in handleTransactionsAfterPhase method.


                This stack trace shows when exception may be thrown and left unhandled.


                        at org.jboss.seam.security.Identity.checkRestriction(Identity.java:222)
                        at org.jboss.seam.navigation.Page.checkPermission(Page.java:245)
                        at org.jboss.seam.navigation.Page.postRestore(Page.java:255)
                        at org.jboss.seam.navigation.Pages.postRestore(Pages.java:443)
                        at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:546)
                        at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:392)
                        at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:228)
                        at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
                        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)



                Am I missing something ?