有没有 Maven 睡眠功能?

2024-01-02

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

<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 插件来完成此操作。像这样的东西:

<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 的评论,任务确实已被弃用,这里是基于使用目标的相同内容。稍微重组但具有相同的功能。

<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有 Maven 睡眠功能? 的相关文章

随机推荐

  • 有 Ruby 语法的权威参考文档吗? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找有关 Ruby 语法的权威文档 我知道核心 API 和标准库的权威文档 但是语法本身呢 例如
  • 如何从左侧而不是顶部滑动导航栏?

    Bootstrap 支持从顶部切换导航栏 屏幕较小时如何从左侧滑动 例如 在上面提供的屏幕截图中 当调整屏幕大小时 导航栏会切换并从顶部向下滑动 我宁愿希望导航栏从左侧滑动 在Bootstrap中如何实现这个功能呢 目前 根据代码 导航栏从
  • Keycloak 模板可用变量

    我在谷歌上搜索了一段时间 以便找到我可以在各种 Keycloak 模板中使用的所有可用的 变量 的文档 我所说的变量是指所有的 xxx yyy 我可以用它来在模板中注入一些动态值 通过文档我可以在这里和那里找到其中的一些 例如 user a
  • cypress - 访问主站点时出现 403 禁止错误

    我正在尝试 cy visit 我的单页应用程序 该应用程序需要在浏览器中加载我的证书才能正确运行 运行测试时 它失败并出现 403 禁止错误 有一个可怕的解决方法 我在 cypress chrome 浏览器窗口中打开一个新选项卡 然后直接转
  • C++ 中指针“this+1”指的是什么?

    我正在浏览代码G2P 推理 https www i6 informatik rwth aachen de web Software g2p html并发现了一行非常奇怪的代码 public const Node childrenEnd co
  • 按服务数据 UUID 进行 BLE 扫描过滤器

    我们有使用 服务数据 128 位 UUID AD 类型信标数据的设备 0x21 对于 Android 扫描 我们通过 MAC 地址过滤 BLE 设备 效果很好 因为我们需要更大的灵活性 所以我们想通过 UUID 进行过滤 我的代码仅适用于小
  • 处理数学函数中的错误

    数学相关函数中错误处理的良好做法是什么 我正在构建一个专门函数的库 模块 我的主要目的是使调用这些函数的代码更容易调试 而不是创建一个闪亮的用户友好的错误处理工具 下面是 VBA 中的一个简单示例 但我也有兴趣听到其他语言的信息 我不太确定
  • 创建帖子时创建 Woocommerce 产品

    我在我的 WordPress 网站上使用 Woocommerce 我在我的网站上销售各种物品 我想要的是 每次我创建有关特定商品的小帖子时 它还会创建一个 Woocommerce 产品页面 其中包含可供出售的商品 例如 我创建了一篇关于定制
  • 在实体框架中创建动态 linq 排序和搜索顺序语句时

    我正在尝试构建一个函数来根据某些参数动态生成不同的查询 我对 LINQ 语法有点困惑 不确定我是否做对了 字符串类型参数集是 search 用于搜索文本框值 searchfield 搜索内容 limit begin limit end 用于
  • Gradle 混合构建风味

    有没有办法在gradle中 混合 多种口味 例如 假设我有两种口味 Red and Blue 现在假设我有两种口味 我希望它们有 子口味 如果你喜欢的话 Complex and Simple 到目前为止我所知道的是 这需要我创建四种口味 R
  • Getview里面的Click方法被多次调用

    我希望 click 方法只被调用一次 我该怎么做才能得到这个结果 这是我的代码 public override View GetView int position View convertView ViewGroup parent View
  • 限制多个 MongoDB 数组大小

    我有一个文档 其中列出了按主题分隔的作者的帖子项 ID 这会产生如下所示的文档 id sdkafjsadkfjads3023 Author SomeGuy RecentPosts topic 1 Count 4 Posts postitem
  • 预定义类型 microsoft.csharp.runtimebinder 未定义或导入

    我在我的 C 项目中使用动态关键字 我收到以下错误 找不到编译动态表达式所需的一种或多种类型 下面是我的代码 我们使用 VS 2013 和 NET Framework 4 5 1 dynamic cstmDocProp Microsoft
  • 如何让JVM默认使用给定的源IP?

    在使用默认的内置 java xml SOAPConnectionFactory 时 有什么方法可以强制 JVM 使用特定的源 IP 地址吗 看起来默认最终会创建 HttpSOAPConnection 对象 sun 私有 API 然后在底层使
  • 在zend框架中设置cookie

    我是 zend 框架的新手 我已经编写了这段代码来在我的网站中设置 cookie public function setCookie data email cookie new Zend Http Cookie user email id
  • 最小的音频文件:MP3、Ogg 还是 Wav?

    我正在寻找最小类型的音频文件 以便某些 JavaScript 能够更流畅地工作 在这三个人中 Ogg通常会小于MP3 两者都会比未压缩的小得多WAV 当然 可能还有其他因素对您的网站产生影响 例如质量 对于大多数用途来说没有太大的明显差异
  • Catch 动态地将参数传递给测试用例

    我有一个 C 项目 正在使用它进行测试捕获 cpp https github com philsquared Catch 我编译并运行以下文件来运行我的测试 define CATCH CONFIG MAIN include catch hp
  • 如何分离多机集群配置的各个阶段?

    假设我有 4 个 Vagrant 盒子 3 种是相同配置的变体 例如 Consul 而一种具有完全不同的配置 例如数据库 我需要在三个配置相似的 Consul VM 上运行一个略有不同的配置步骤 然后 我需要针对其中 1 个 Vault V
  • 在 cygwin 上安装 uwsgi

    有人设法在 cygwin python 2 7 上安装 uwsgi 吗 uwsgi 2 0 11 2 python setup py install running install using profile buildconf defau
  • 有没有 Maven 睡眠功能?

    我设置了 Maven 配置文件用于测试 在预集成测试中 maven 启动两个 jetty 服务器 然后启动测试 我偶然发现的问题是在服务器中 测试开始时它们没有完全加载 看来问题是通过在测试中添加 5 秒睡眠时间来解决的 但我希望将其添加到