6 Replies Latest reply on Oct 19, 2014 5:51 AM by tibor17

    Wildfly TransactionManager implementation

    miroslav-24

      Heloo,

       

      I am developing web application which runs on Wildfly 8.1.0. In my JUnit tests I want to test my service classes. These service classes are using javax.inject.Inject and javax.transaction.Transactional annotations. I use  Deltapike Weld and Wildfly-Weld to enable these annotations. My dependecies are:

       

       

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.easytesting</groupId>

                  <artifactId>fest-assert-core</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.cdictrl</groupId>

                  <artifactId>deltaspike-cdictrl-weld</artifactId>

                  <version>1.0.1</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.weld.se</groupId>

                  <artifactId>weld-se</artifactId>

                  <version>2.1.2.Final</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.wildfly</groupId>

                  <artifactId>wildfly-weld</artifactId>

                  <version>8.1.0.Final</version>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>sun.jdk</groupId>

                          <artifactId>jconsole</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-test-control-module-impl</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-jpa-module-impl</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-jsf-module-impl</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <!--&lt;!&ndash; Deltaspike 1.0.1 workaround, see the unitests BOM. &ndash;&gt;-->

                  <groupId>org.apache.myfaces.test</groupId>

                  <artifactId>myfaces-test20</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>junit</groupId>

                          <artifactId>junit</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <!-- &lt;!&ndash; Deltaspike 1.0.1 workaround, see the unitests BOM. &ndash;&gt;-->

                  <groupId>org.apache.myfaces.core</groupId>

                  <artifactId>myfaces-impl-test</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

       

      My simple Junit test class is:

       

      @RunWith(CdiTestRunner.class)

      public class MyTest {

       

          @Inject

          TenantService tenantService;

       

          @Before

          public void before() {

              assertNotNull(tenantService);

          }

       

          @Test

          public void storeAndLoad() {

       

              TenantViewData tenantViewData = new TenantViewData();

              Tenant tenant = new Tenant(new TenantName("simple-tenant"));

              tenant.setTenantURL(new TenantURL("localhost:8080"));

              tenantViewData.setTenant(tenant);

       

               /* on this line i got the exception */

              tenantService.saveTenant(tenantViewData);

          }

      }

       

      Method saveTenant is annotated with @Transactional. My JUnit test throwas exception before it goes into this method. The exception is:

       

      javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager

        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.getTransactionManager(TransactionalInterceptorBase.java:169)

        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:45)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)

        at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNext(AbstractInterceptionChain.java:103)

        at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:81)

        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48)

        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:41)

        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)

        at com.scheidtbachmann.shared.tenant.crud.business.service.TenantServiceImpl$Proxy$_$$_WeldSubclass.saveTenant(Unknown Source)

        at com.scheidtbachmann.shared.tenant.crud.business.service.TenantServiceImpl$Proxy$_$$_WeldClientProxy.saveTenant(Unknown Source)

        at com.scheidtbachmann.shared.tenant.crud.MyTest.storeAndLoad(MyTest.java:76)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:335)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:307)

        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:169)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:67)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:361)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:387)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:136)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:160)

        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)

        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)

        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

      Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)

        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)

        at javax.naming.InitialContext.lookup(InitialContext.java:411)

        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.getTransactionManager(TransactionalInterceptorBase.java:167)

        ... 46 more

       

      It crashes in com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase on line:


      transactionManager = (TransactionManager) initialContext.lookup("java:jboss/TransactionManager");

       

      I tried to find an implementation of TransactionManager in Wildfly 8.1.0 project but I did not find any implementation, so I think Wildfly uses some implementation from external library. I would like to know which library (dependency) should I add to my maven project to get this implementation of Transactional manager. Thanks

        • 1. Re: Wildfly TransactionManager implementation
          rafabene

          Hi Miroslav,

           

          When you say that "Method saveTenant is annotated with @Transactional. ", Are you using @Transactional from DeltaSpike or from Java EE ?

           

          Did you declared org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor in your beans.xml file that is being used on your tests ?

          • 2. Re: Wildfly TransactionManager implementation
            miroslav-24

            Hello Rafael,

             

            Thanks for replying. I am using @Transactional from Java EE e.g.

            .javax.transaction.Transactional.

             

            On Tue, Oct 7, 2014 at 1:59 PM, Rafael Benevides <do-not-reply@jboss.com>

            • 3. Re: Wildfly TransactionManager implementation
              rafabene

              Hi Miroslav,

               

              Now I saw that you wrote javax.transaction.Transactional annotation, sorry.

               

              You said that you have used Deltapike Weld and Wildfly-Weld to enable this annotation but DeltaSpike enables its own org.apache.deltaspike.jpa.api.transaction.Transactional annotation. Would you mind trying that ?

               

              Thanks

              • 4. Re: Wildfly TransactionManager implementation
                tibor17

                @Rafael

                We are with Miroslav writing tests where Deltaspike is used as JUnit runner.

                We want to force the Weld using "javax.transaction.Transactional", as Miroslav said.

                The main code in src/main/java is using transactions with "javax.transaction.Transactional". Thus we won't use Deltaspike's @Transactional.

                The only problem is that the weld is not able to make look up for TransactionManager.

                It really looks like some kind of Weld configuration is missing with concrete implementation of TransactionManager.

                I guess this configuration has to be in Wildfly, but since we are reducing to unit tests we have to tell the Weld which implementation of TransactionManager to use.

                Any idea on how to configure TransactionManager implementation (maybe in some properties or xml file)?

                • 5. Re: Wildfly TransactionManager implementation
                  ochaloup

                  I think that the answer is put at stack overflow: http://stackoverflow.com/questions/25678766/how-to-use-narayana-jta-5-0-3-final-to-provide-support-for-xa-transactions-t…

                  I think that this is expected to be run on server (e.g. Arquillian) as it uses JNDI lookup to get transaction manager. Or create context on your own.

                   

                  WildFly uses Narayana as implementation Transaction Manager but from the exception "javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager" it seems that's loaded on classpath.

                  • 6. Re: Wildfly TransactionManager implementation
                    tibor17

                    @Ondřej

                    It does not seem to be helpful.

                    We may try to use

                    com.arjuna.ats.jbossatx.jts.TransactionManagerService

                    and bind the TM, or another alternative would be own interceptor.

                    Of course nothing of these two alternatives may work.