cargo-maven2-plugin在执行集成测试之前不会等待jboss as7启动

时间:2012-11-27 10:11:17

标签: maven jboss7.x maven-cargo maven-failsafe-plugin

我无法获得成功的Maven pom.xml配置来启动JBoss AS 7,部署war工件,并让它等到工件成功部署之后再开始运行集成测试。

我已经咨询过......

我想使用已安装(并预配置)的JBoss AS 7容器。我不想让它一直运行起来。我想启动它,运行一些测试,并将其关闭。

我的环境:

  • cargo-maven2-plugin 1.3.1
  • jboss-as-7.1.1.Final
  • maven-failsafe-plugin 2.12.4

以下是Failsafe配置的内容......

        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${maven-failsafe-plugin.version}</version>
            <configuration>
                <forkMode>once</forkMode>
                <argLine>-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.framework.version}/spring-instrument-${spring.framework.version}.jar"</argLine>
                <useSystemClassLoader>true</useSystemClassLoader>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <!-- Uncomment the line below if you want the build to fail when any integration test fails -->
                        <!-- <goal>verify</goal> -->
                    </goals>
                </execution>
            </executions>
        </plugin>

以下是Cargo配置的内容......

                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>${cargo-maven2-plugin.version}</version>
                    <configuration>
                        <container>
                            <containerId>jboss71x</containerId>
                            <type>installed</type>
                            <home>${jboss71x.home}</home>
                            <output>${project.build.directory}/jboss71x/container.log</output>
                            <append>false</append>
                            <log>${project.build.directory}/jboss71x/cargo.log</log>
                        </container>
                        <configuration>
                            <type>standalone</type>
                            <home>${project.build.directory}/jboss71x/container</home>
                            <properties>
                                <cargo.jboss.configuration>default</cargo.jboss.configuration>
                                <cargo.rmi.port>1099</cargo.rmi.port>
                                <cargo.jvmargs>${servlet.container.jvmargs}</cargo.jvmargs>
                                <cargo.logging>high</cargo.logging>
                                <cargo.servlet.port>8080</cargo.servlet.port>
                            </properties>
                        </configuration>
                        <deployer>
                            <type>installed</type>
                            <deployables>
                                <deployable>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <type>war</type>
                                    <properties>
                                        <context>/ws</context>
                                    </properties>
                                    <pingURL>http://localhost:8080/ws/services</pingURL>
                                    <pingTimeout>30000</pingTimeout>
                                </deployable>
                            </deployables>
                        </deployer>
                    </configuration>
                    <!-- http://navinpeiris.com/2011/08/22/running-integrationacceptance-tests-in-jboss-7-using-cargo/ -->
                    <executions>
                        <execution>
                            <id>start-container</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>start</goal>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop-container</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

当我想用mvn clean package cargo:run手动启动容器时,上面的配置很有用。但在使用mvn clean integration-test的CI构建期间,它无法达到预期的效果。

提示?建议欢迎。

2 个答案:

答案 0 :(得分:0)

以上配置确实有效!

我不得不重新启动shell然后重新构建我的项目。我确实在容器的启动和停止时收到了弃用警告,但这是一个小小的担心。

[INFO] Building war: D:\workspaces\alstom-grid\Projects\SPP\SPP-MUI\spp-im-mui-ws\target\spp-im-mui-ws-1.0-SNAPSHOT.war
[INFO]
[INFO] --- cargo-maven2-plugin:1.3.1:start (start-container) @ spp-im-mui-ws ---
[WARNING] The <deployables> element under the <deployer> element is deprecated. Please use <deployables> under the plugin <configuration> instead.
[WARNING] The <deployables> element under the <deployer> element is deprecated. Please use <deployables> under the plugin <configuration> instead.
[WARNING] The <deployables> element under the <deployer> element is deprecated. Please use <deployables> under the plugin <configuration> instead.
[INFO]
[INFO] --- maven-failsafe-plugin:2.12.4:integration-test (default) @ spp-im-mui-ws ---
[INFO] Failsafe report directory: D:\workspaces\alstom-grid\Projects\SPP\SPP-MUI\spp-im-mui-ws\target\failsafe-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.spp.im.mui.jaxws.client.test.VirtualWebServiceClientITCase
Tests run: 1, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.032 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 1

[INFO]
[INFO] --- cargo-maven2-plugin:1.3.1:stop (stop-container) @ spp-im-mui-ws ---
[WARNING] The <deployables> element under the <deployer> element is deprecated. Please use <deployables> under the plugin <configuration> instead.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ spp-im-mui-ws ---
[INFO] Installing D:\workspaces\alstom-grid\Projects\SPP\SPP-MUI\spp-im-mui-ws\target\spp-im-mui-ws-1.0-SNAPSHOT.war to C:\.m2\repository\org\spp\im\mui\spp-im-mui-ws\1.0-SNAPSHOT\spp-im-mui-ws-1.0-SNAPSHOT.war

[INFO] Installing D:\workspaces\alstom-grid\Projects\SPP\SPP-MUI\spp-im-mui-ws\pom.xml to C:\.m2\repository\org\spp\im\mui\spp-im-mui-ws\1.0-SNAPSHOT\spp-im-mui-ws-1.0-SNAPSHOT.pom

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:16.016s
[INFO] Finished at: Wed Nov 28 11:51:39 PST 2012
[INFO] Final Memory: 14M/256M
[INFO] ------------------------------------------------------------------------

答案 1 :(得分:0)

由于我遇到了同样的问题,我想补充说明这需要做些什么。

请注意deployable部分中的ping属性。在继续之前,Cargo将重复调用给定的URL以获取可用性,但仅在达到超时之前。

 <deployable>
   <groupId>${project.groupId}</groupId>
   <artifactId>${project.artifactId}</artifactId>
   <type>war</type>
   <properties>
     <context>/example-app</context>
   </properties>
   <pingURL>http://localhost:8080/example-app/ping</pingURL>
   <pingTimeout>30000</pingTimeout>
 </deployable>

要使应用程序可ping,您必须提供ping端点。您可以将JAX-RS与RestEasy一起使用,以便于实现。

@Path("/ping")
public class PingResourceImpl {

    @GET
    @PermitAll // optional. Is needed if you protected your ressources f.e. with a SecurityInterceptor.
    public Response ping() {
        return Response.ok().build();
    }
}

确保正确配置servlet映射。

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/ping</url-pattern>
</servlet-mapping>