6 Replies Latest reply on Sep 11, 2013 7:19 AM by Cleverson Sacramento

    Arquillian fails to inject members after running a few tests

    stupidsheep Newbie

      Hello all

       

      I'm trying since some time to get Arquillian running with JPA (EclipseLink 2.5.0) on an Embedded GlassFish (3.1.2.2) using either a MySQL (5.1.25) or PostgreSQL (connector: 9.1-901.jdbc4) database.

      I used this guide as my initial setup: http://arquillian.org/guides/testing_java_persistence/

       

      Now I'd like to use PostgreSQL, so I changed my glassfish-resources.xml to use a XADataSource pointing to my PostgreSQL database.

      Everything works and I am able to read data from my database.

       

      As long as I only have one test class (with as many tests as I like) everything works.

      If I create a second test class Arquillian will give me the error "RuntimeException: Could not inject members" (the full stacktrace is attached below).

       

      Trying out various combinations I examined that I can have as many test classes as I want, as long as there are not more than 4 tests (methods annotated with @Test) in total.

       

      My tests look all the same:

       

      RunWith(Arquillian.class)
      public class GlobalModuleTest extends BaseTest {
      
          @PersistenceContext
          EntityManager em;
      
          @Inject
          UserTransaction utx;
      
          @Before
          public void setUp() throws Exception {
              utx.begin();
              em.joinTransaction();
          }
      
          @After
          public void tearDown() throws Exception {
              utx.rollback();
              em.clear();
          }
      
          @Test
          public void loadRoleDAO() throws Exception {
              List<SomeDAO> someDAOs = em.createQuery("SELECT r FROM SomeDAO r", SomeDAO.class).setMaxResults(10).getResultList(); 
              assertTrue(someDAOs.size() > 0);
          }
           [ ... snip ...]
      }
      

       

       

      Has anybody experienced the same? Or has some useful tips for me?

      I've played around with my connection settings (I used various DataSources) and tried to reproduce the issue in the sample application (without any luck).

       

      Every help is very much appreciated!

       

      Regards Matthias

       

      PS: I already asked the same question on StackOverflow some time ago without any answer.

      In case I (or somebody else) can solve my problem I'll post the answer to both sites.

       

      PPS: Here is the full stack trace:

       

      java.lang.RuntimeException: Could not inject members
           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:678)
           at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:136)
           at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:686)
           at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:695)
           at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:106)
           at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:134)
           at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
           at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102)
           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:145)
           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:125)
           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.enrich(CDIInjectionEnricher.java:78)
           at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:52)
           at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:606)
           at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
           at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
           at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
           at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
           at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:606)
           at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
           at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
           at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
           at sun.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:606)
           at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
           at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
           at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
           at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:606)
           at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
           at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
           at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
           at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
           at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:95)
           at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:222)
           at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
           at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
           at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
           at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
           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.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)
           at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
           at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
           at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
           at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
           at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
           at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
           at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
           at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)
           at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
           at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
           at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
           at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
           at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
           at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
           at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
           at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
           at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
           at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
           at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
           at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
           at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
           at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
           at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
           at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
           at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
           at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
           at java.lang.Thread.run(Thread.java:724)