2013-07-23 36 views
2

我有一個稍微奇怪的問題。 我目前使用Arquillian(1.1.0.Final)和Embedded GlassFish(3.1.2.2)一起使用。 我用下面的guide來設置我的小測試項目。 一切正常工作與集成的Derby數據庫。 我真正的應用程序使用的PostgreSQL作爲數據庫,所以我配置我的GlassFish資源如下:Arquillian未能在第一個測試類後注入依賴關係

<!-- See http://jdbc.postgresql.org/documentation/91/ds-cpds.html --> 
    <jdbc-connection-pool name="MyPostgresqlPool" 
          res-type="javax.sql.DataSource" 
          datasource-classname="org.postgresql.ds.PGSimpleDataSource" 
          is-isolation-level-guaranteed="false"> 

     <property name="user" value="..." /> 
     <property name="databaseName" value="..." /> 
     <property name="password" value="..." /> 
     <property name="serverName" value="..." /> 
     <property name="portNumber" value="..." /> 

    </jdbc-connection-pool> 

我訪問持久上下文和用戶交易如上述指南中所述:

@RunWith(Arquillian.class) 
public class AddressModuleTest extends BaseTest { 
    @PersistenceContext 
    protected EntityManager em; 

    @Inject 
    protected UserTransaction utx; 

    @Before 
    public void setUp() throws Exception { 
     utx.begin(); 
     em.joinTransaction(); 
    } 

    @After 
    public void tearDown() throws Exception { 
     utx.rollback(); 
    } 

[ ... snip ...] 
} 

如果我運行我的測試類(AddressModuleTest,請注意,「BaseTest」有一個用@Deployment爲Arquillian註解的靜態方法),一切都很好,我可以從PostgreSQL數據庫讀取我的數據。

不幸的是,如果我創建第二個測試類,它不會工作:

@RunWith(Arquillian.class) 
public class CommunicationModuleTest extends BaseTest { 
    @PersistenceContext 
    protected EntityManager em; 

    @Inject 
    protected UserTransaction utx; 

    @Before 
    public void setUp() throws Exception { 
     utx.begin(); 
     em.joinTransaction(); 
    } 

    @After 
    public void tearDown() throws Exception { 
     utx.rollback(); 
    } 

    [ ... snip ... ] 
} 

的Maven(分別爲神火)給了我以下錯誤:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.758 sec <<< FAILURE! 
loadMessageDAO(package.CommunicationModuleTest) Time elapsed: 0.027 sec <<< ERROR! 
java.lang.RuntimeException: Could not inject members 
    at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:135) 
    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.GeneratedMethodAccessor67.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
[ ... snip ... ] 

..用下面的根例外:

Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001324 Argument bean must not be null 
    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) 
    ... 79 more 

我回到了指南,並試圖重現我的問題與他們的代碼 - 無線沒有成功(即他們不受我的問題影響)。因此,我認爲我的UserTransaction處理是錯誤的,或者這是我的PostgreSQL配置的問題。 我沒有成功嘗試了不同的數據源,即

  • org.postgresql.ds.PGSimpleDataSource
  • org.postgresql.ds.PGPoolingDataSource

除了javax.xa.XADataSource連同org.postgresql.xa.PGXADataSource

有人有線索有什麼問題嗎?我必須承認,我對於不同的數據源以及交易管理(經理)都很缺乏經驗。


UPDATE

看起來好像問題是獨立的PostgreSQL,因爲它發生在MySQL(MariaDB的)爲好。堆棧跟蹤是一樣的,所以我想這個問題就在於我的事務管理中..


親切的問候,併爲您的幫助

stupidSheep

回答

6

該錯誤是由ARQ-1071在1.0.4.Final中引入的,並且在當前版本(1.1.1.Final)中保留。原因是所有的ThreadLocal事件都被InheritableThreadLocal所取代,以修復@Timeout用法上的NPE。

建議修復由上的InheritableThreadLocal的復歸只是一個occurence到ThreadLocal的像它已經在下面拉入請求完成: https://github.com/arquillian/arquillian-core/pull/53

請,在這個問題上的投票將在下一版本1.1.2.Final發佈: https://issues.jboss.org/browse/ARQ-1458

1

非常感謝我有一個類似的問題(唯一不同的是,我收到消息「WELD-001456 Argument resolvedBean不能爲空」)。已解決的bean存儲在微部署中的所有測試之間共享的類org.jboss.weld.manager.BeanManagerImpl的實例中。在我的情況下,失敗的原因是當一些測試完成時,它的線程將與舊的TestRunnerAdaptor實例保持綁定,該舊實例已鏈接到已清理的Bean管理器(請參閱org.jboss.weld.manager.BeanManagerImpl.cleanup()方法)) 。如果來自下一個微部署的一些測試將使用這樣的線程之一,則失敗。問題與Arquillian版本> 1.0.3.Final有關(在新版本中,字段類型org.jboss.arquillian.junit.State.lastCreatedRunner從ThreadLocal更改爲InheritableThreadLocal,現在更改爲org.jboss.arquillian.junit.State方法。 isLastRunner()總是返回false)。

我不知道如何解決這個問題。唯一的方法是使用Arquillian 1.0.3.Final。

+0

嗨postiveCoder!感謝您的回答!我將我的版本更改爲Arquillian 1.0.3.Final,現在它可以工作。我會向Arquillian社區(JBoss)詢問他們是否可以幫忙...(請參閱https://community.jboss.org/message/830718),如果我知道更多信息,請通知您! – stupidSheep

+0

無論是在SO還是在Arquillian論壇,都沒有人知道答案,所以我會接受你的答案,因爲它確實爲我的問題提供瞭解決方法:) – stupidSheep

+0

謝謝。似乎只有我們有這個問題。 :) – briarheart

1

的承諾在1.0.3.Final在後續版本中恢復來解決這個問題,直到1.1.4.Final版本時,它終於解決了。

<dependency> 
    <groupId>org.jboss.arquillian</groupId> 
    <artifactId>arquillian-bom</artifactId> 
    <version>1.1.4.Final</version> 
    <type>pom</type> 
    <scope>import</scope> 
</dependency> 
相關問題