Java 有maven睡眠功能吗?
我为测试设置了maven概要文件,在预集成测试中,maven启动两台jetty服务器,然后启动测试。我遇到的问题是,服务器在测试开始时没有完全加载。通过在测试中添加5秒的睡眠时间,似乎问题已经解决了,但我希望在maven中添加它并从测试中删除它。不管怎样,我能做到吗?请查看下面的代码示例以获取更多信息Java 有maven睡眠功能吗?,java,maven,jetty,Java,Maven,Jetty,我为测试设置了maven概要文件,在预集成测试中,maven启动两台jetty服务器,然后启动测试。我遇到的问题是,服务器在测试开始时没有完全加载。通过在测试中添加5秒的睡眠时间,似乎问题已经解决了,但我希望在maven中添加它并从测试中删除它。不管怎样,我能做到吗?请查看下面的代码示例以获取更多信息 <build> <plugins> <plugin> <groupId>org.apache.mav
<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>
org.apache.maven.plugins
maven依赖插件
2.7
复制
编译
复制
com.work.projectname
项目名称网站
${project.version}
战争
projectname-${project.version}.war
com.work.projectname
projectname存根web
${project.version}
战争
projectname存根-${project.version}.war
${project.build.directory}
假的
真的
org.apache.maven.plugins
maven surefire插件
2.16
真的
org.mortbay.jetty
jetty maven插件
${jetty server.version}
启动项目名称
预集成测试
部署战争
真的
手册
${project.build.directory}/projectname-${project.version}.war
${basedir}/src/jetty/jetty-loginService.xml
/项目名称
真的
${project.build.directory}/tmp projectname
8006
停止
启动项目名称存根
预集成测试
部署战争
真的
手册
${project.build.directory}/projectname存根-${project.version}.war
${stub jetty server.port}
300000
8008
停止
停止项目名称
整合后测试
停止
8006
停止
停止项目名称存根
整合后测试
停止
8008
停止
org.apache.maven.plugins
maven故障保护插件
2.16
班级
33
**/*Test.java
集成测试
集成测试
验证
验证
您可以在maven antrun插件的帮助下完成。大概是这样的:
<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>
org.apache.maven.plugins
maven antrun插件
睡一会儿
预集成测试
跑
编辑:以防有人发现。根据jl的评论,任务确实已经被弃用了,下面是基于使用目标的相同内容。略微重组,但具有相同的功能
<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>
org.apache.maven.plugins
maven antrun插件
1.8
睡一会儿
预集成测试
跑
我已经创建了一次。不确定它现在能起多大作用,你可以试着让我们知道
用法(在检查源和建筑后):
org.jboss.maven.plugins
maven睡眠插件
1
睡眠5秒
预集成测试
睡觉
5.
谢谢,请您在交互测试之前解释一下如何启动此功能。我曾尝试将阶段设置为预集成测试,但这对我不起作用。正在使用的Maven目标是干净的,我添加了一个示例。在什么方面它对你不起作用?我希望您使用预集成测试作为
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-sleep-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>sleep-5-seconds</id>
<phase>pre-integration-test</phase>
<goals>
<goal>sleep</goal>
</goals>
<configuration>
<delay>5</delay>
</configuration>
</execution>
</executions>
</plugin>