gpt4 book ai didi

java - junit 等待外部资源准备好

转载 作者:行者123 更新时间:2023-12-01 13:57:24 25 4
gpt4 key购买 nike

我正在尝试使用 JUnit 外部资源测试 Cassandra。我有两个类 CassandraExternalResource 和 TestCassandra。以下是 TestCassandra 的片段:

    public class TestCassandra {

@Rule
public CassandraExternalResource cassandraExternalResource = new CassandraExternalResource();


@Test
public void test() throws InterruptedException {
System.out.println("During Test");
}
}

在 CassandraExternalResource 的 before 方法中,我使用单独的线程启动 Cassandra Server。我想要的是让测试用例等到 cassandra 服务器启动并运行。

由于服务器需要一些时间来启动,测试用例在服务器准备好之前开始运行。

感谢任何帮助。

最佳答案

您可以通过 ping cassandra 服务器直到其准备就绪来扩展规则的 before 方法。

关于java - junit 等待外部资源准备好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19557932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com