Arquillian:嵌入野蝇?

Posted

技术标签:

【中文标题】Arquillian:嵌入野蝇?【英文标题】:Arquillian: Wildfly embedded? 【发布时间】:2014-01-20 15:10:01 【问题描述】:

到目前为止,我的集成测试都是使用 Arquillian 和嵌入式 Glassfish 4.x 运行的。由于我遇到了错误 ARQ-1458,我尝试迁移到 Wildfly 8.0.0.Beta1。

我在 Maven 中的部门是:

<dependency>
    <groupId>org.jboss.arquillian</groupId>
    <artifactId>arquillian-bom</artifactId>
    <version>1.1.2.Final</version>
    <scope>import</scope>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-container</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-arquillian-container-embedded</artifactId>
    <version>8.0.0.Beta1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-embedded</artifactId>
    <version>8.0.0.Beta1</version>
    <scope>test</scope>
</dependency>

运行测试时,我收到 jbossHome 为空的错误。我没有 arquillian.xml。在检查 Wildfly-arquillian-container-embedded (POM) 的 Github 源时,我想知道为什么嵌入式容器需要 JBOSS_HOME?我知道将它用于托管和远程变体,但为什么我需要它用于嵌入式变体? Arquillian 页面也只有 JBoss AS 作为托管服务器的示例,所以我想知道它是否有可能(但为什么会有 wildfly-arquillian-container-embedded 呢?)?

或者我应该坚持使用 maven-dependency-plugin 下载容器的托管容器(请参阅http://arquillian.org/guides/getting_started/#add_more_containers - 底部)?

谢谢和最好的问候!

确切的错误是:


org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist
    at org.jboss.arquillian.container.spi.client.deployment.Validate.configurationDirectoryExists(Validate.java:139)
    at org.jboss.as.arquillian.container.embedded.EmbeddedContainerConfiguration.validate(EmbeddedContainerConfiguration.java:102)
    at org.jboss.arquillian.container.impl.ContainerImpl.createDeployableConfiguration(ContainerImpl.java:115)
    at org.jboss.arquillian.container.impl.ContainerImpl.setup(ContainerImpl.java:181)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$7.perform(ContainerLifecycleController.java:149)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$7.perform(ContainerLifecycleController.java:145)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:255)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.setupContainer(ContainerLifecycleController.java:144)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    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.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    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.core.impl.EventImpl.fire(EventImpl.java:67)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$1.perform(ContainerLifecycleController.java:62)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$1.perform(ContainerLifecycleController.java:55)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forEachContainer(ContainerLifecycleController.java:209)
    at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.setupContainers(ContainerLifecycleController.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    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.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)

【问题讨论】:

我有一种感觉,wildfly-embedded 并不是真正的嵌入式容器或尚未完成。因为我做了一些挖掘并查看了“EmbeddedContainerConfiguration”java 类。他们在那里明确地检查 jbossHome、moduleHome 和 bundleHome。因此,您必须下载一个“真正的”wildfly,在我看来它不是嵌入式容器;)我目前正在使用托管/远程适配器,一切正常。对于嵌入式测试,我将使用 glassfish-embedded :) 是的,看到了相同的代码 :( 所以恐怕我必须选择相同的选项并等待 ARQ-1458 的狐狸。我不会放弃,因为使用嵌入式 Wildfly 会通过我的第一个选项,这样人们就可以签出项目并进行 Maven 构建,而无需大量安装或使用插件或 ANT 任务的其他帮助。 我知道这个帖子已经很老了,但如果有人能告诉我你们最终对这个错误的结论是什么,我将不胜感激? 【参考方案1】:

使用系统属性变量

<profile>
<id>INTEGRATION_TESTS</id>
<dependencies>
    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-arquillian-container-embedded</artifactId>
        <version>8.2.0.Final</version>
    </dependency>
    <!-- this is the wildfly emb.container - BUT eventually it is not a fully blown emb.container-->
    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-embedded</artifactId>
        <version>8.2.0.Final</version>
    </dependency>

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.wildfly</groupId>
                                <artifactId>wildfly-dist</artifactId>
                                <version>8.2.0.Final</version>
                                <type>zip</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>1.0.2.Final</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jdbc</id>
                    <phase>package</phase>
                    <goals>
                        <goal>deploy-artifact</goal>
                    </goals>
                    <configuration>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                        <name>ojdbc6.jar</name>
                    </configuration>
                </execution>
                <execution>
                    <id>datasource</id>
                    <phase>package</phase>
                    <goals>
                        <goal>add-resource</goal>
                    </goals>
                    <configuration>
                        <address>subsystem=datasources,data-source=tests</address>
                        <resources>
                            <resource>
                                <properties>
                                    <connection-url>jdbc:oracle:thin:@***:1521:xe</connection-url>
                                    <jndi-name>java:jboss/datasources/tests</jndi-name>
                                    <enabled>true</enabled>
                                    <enable>true</enable>
                                    <user-name>***</user-name>
                                    <password>***</password>
                                    <driver-name>ojdbc6.jar</driver-name>
                                    <use-ccm>false</use-ccm>
                                </properties>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <systemPropertyVariables>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <jboss.home>$project.basedir/target/wildfly-8.2.0.Final</jboss.home>
                    <module.path>$project.basedir/target/wildfly-8.2.0.Final/modules</module.path>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
                <execution>
                    <id>verify</id>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


    </plugins>

</build>

【讨论】:

【参考方案2】:

嗯,我猜它与 Wildfly 的工作方式与 Glassfish 的工作方式不同:

https://community.jboss.org/thread/236562

:(

编辑:Docker 增加了对此问题的另一种看法。我可以使用 Docker 和 Maven 轻松管理外部容器,同时仍然使用 Arquillian。还没有测试它,但如果有人偶然发现这个......

【讨论】:

没错,但我个人更喜欢远程(或托管)适配器,因为它可以为我们提供更准确的测试结果(并且问题也更少)。【参考方案3】:

看看 Dan Allen 写的this nice article。

简而言之:一般不要使用嵌入式容器(特别是带有 EclipseLink 的 glassfish)。独立服务器为我们提供更准确的测试结果。

另外,由于开发速度,我更喜欢远程适配器(每次测试启动时都不会启动服务器,只需手动启动一次)。 如果您希望容器像嵌入式一样自动启动,请切换到托管容器。

希望对你有帮助。

【讨论】:

您好 Grzesiek,非常感谢您提供的信息丰富且重要的链接。我想我会因此改用远程容器,特别是因为编织对我来说很重要。最初的(并且在某种程度上仍然有效)的想法是有人可以下载一个 Maven 项目并运行单元/集成测试而无需安装容器。再次,非常感谢! @TimoBoewing 不客气:]我很理解你,因为曾经我也被这个诱人的想法所困。【参考方案4】:

应该将环境变量 JBOSS_HOME 设置为 jBoss 安装的路径。否则,应在容器标签内的 arquillian.xml 中添加标签 property

<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian_1_0.xsd">


<container qualifier="jboss" default="true">
    <configuration>
        <property name="jbossHome">/path/to/jboss/as</property>
    </configuration>
</container>

来自示例应用程序 jboss-javaee6-webapp

【讨论】:

以上是关于Arquillian:嵌入野蝇?的主要内容,如果未能解决你的问题,请参考以下文章

来自IDEA官方指南的arquillian运行时问题

加速休眠初始化

阻止野蝇战争初始化 mojarra

使用 Arquillian 和 Wildfly 进行集成测试

使用arquillian测试远程客户端jndi查找

Arquillian,Runclient测试为远程