有没有maven睡眠功能? [英] Is there any maven sleep functionality?

查看:162
本文介绍了有没有maven睡眠功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有maven配置文件集用于测试在预集成测试中maven启动两个jetty服务器,然后开始测试。我偶然发现的问题是在服务器中,测试开始时它们没有完全加载。似乎通过在测试中添加5秒的睡眠时间来解决问题,但我希望将其添加到maven中并从测试中删除。无论如何我能做到吗?请查看下面的代码示例以获取更多信息

I have maven profile set for testing where in pre-integration-tests maven starts two jetty servers and afterwards tests are started. The problem I've stumbled into is in the servers, they aren't fully loaded when tests start. It seems like the problem is fixed by adding 5 second sleep time into the tests, but I wish to add it in maven and remove from tests. Is there anyway I could do that? Please look into code sample below for additional information

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.work.projectname</groupId>
                                <artifactId>projectname-web</artifactId>
                                <version>${project.version}</version>
                                <type>war</type>
                                <destFileName>projectname-${project.version}.war</destFileName>
                            </artifactItem>
                            <artifactItem>
                                <groupId>com.work.projectname</groupId>
                                <artifactId>projectname-stubs-web</artifactId>
                                <version>${project.version}</version>
                                <type>war</type>
                                <destFileName>projectname-stubs-${project.version}.war</destFileName>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty-server.version}</version>
            <executions>
                <execution>
                    <id>start-projectname</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy-war</goal>
                    </goals>
                    <configuration>
                        <daemon>true</daemon>
                        <reload>manual</reload>
                        <war>${project.build.directory}/projectname-${project.version}.war</war>
                        <webAppXml>${basedir}/src/jetty/jetty-loginService.xml</webAppXml>
                        <webAppConfig>
                            <contextPath>/projectname</contextPath>
                            <parentLoaderPriority>true</parentLoaderPriority>
                            <tempDirectory>${project.build.directory}/tmp-projectname</tempDirectory>
                        </webAppConfig>
                        <stopPort>8006</stopPort>
                        <stopKey>STOP</stopKey>
                    </configuration>
                </execution>
                <execution>
                    <id>start-projectname-stubs</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy-war</goal>
                    </goals>
                    <configuration>
                        <daemon>true</daemon>
                        <reload>manual</reload>
                        <war>${project.build.directory}/projectname-stubs-${project.version}.war</war>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <port>${stub-jetty-server.port}</port>
                                <maxIdleTime>300000</maxIdleTime>
                            </connector>
                        </connectors>
                        <stopPort>8008</stopPort>
                        <stopKey>STOP</stopKey>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-projectname</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                    <configuration>
                        <stopPort>8006</stopPort>
                        <stopKey>STOP</stopKey>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-projectname-stubs</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                    <configuration>
                        <stopPort>8008</stopPort>
                        <stopKey>STOP</stopKey>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <parallel>classes</parallel>
                <threadCountClasses>33</threadCountClasses>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
            </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>


推荐答案

你可以在maven antrun的帮助下完成插入。这样的事情:

You can do it with the help of the maven antrun plugin. Something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <configuration>
        <tasks>
            <sleep seconds="5" />
        </tasks>
    </configuration>
    <executions>
        <execution>
            <id>sleep-for-a-while</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

编辑:万一有人会抓住这个。基于来自jl的评论,任务确实已被弃用,并且基于使用目标而言,这是相同的事情。 Sligthly重组但具有相同的功能。

In case someone will catch this. Based on the comment from jl, tasks have indeed been deprecated and here is the same thing based on using targets instead. Sligthly reorganized but has the same function.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>sleep-for-a-while</id>
            <phase>pre-integration-test</phase>
            <configuration>
                <target>
                    <sleep seconds="5" />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这篇关于有没有maven睡眠功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆