gpt4 book ai didi

java - 如果 org.gradle.parallel=true,一套 Java UT 的 cassandra-unit 会出现间歇性故障

转载 作者:行者123 更新时间:2023-11-30 06:55:03 28 4
gpt4 key购买 nike

我正在尝试为 spring-boot 应用程序的一组使用 org.gradle.parallel=true 运行的 UT 引入 cassandra-unit

运行所有测试并不可靠,尽管偶尔会起作用。

我猜这与描述的问题有关 https://github.com/jsevellec/cassandra-unit/issues/155即,当下一个 UT 开始时,第一个实例仍在徘徊,并且似乎没有办法强制它“快速”关闭。

我最初的方法给出了不可靠的结果,即使用 org.gradle.parallel=true

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@TestExecutionListeners(
listeners = CassandraUnitTestExecutionListener.class,
mergeMode = MERGE_WITH_DEFAULTS
)
@CassandraDataSet
@EmbeddedCassandra
public class MyCassandraUnitTest {

@Test
public void xxx_xxx() {
}

}

cassandra-unit/wiki 中所述和 StephanPraetsch github example

作为一种解决方法,我尝试删除注释并使用 native API,即尝试在所有测试中保持一个运行,并且使用 org.gradle.parallel=false 这似乎是可靠的,但会减慢整体速度 build 。 (仍在测试以确保其不重合)使用这种方法

单元级别之前:

EmbeddedCassandraServerHelper.startEmbeddedCassandra();

以及单元类(class)之后:

EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();

如所述 -https://github.com/jsevellec/cassandra-unit/wiki/How-to-use-it-in-your-code .

我使用第一种方法得到的错误是像

这样的超时
00:27:31.826 [Test worker] ERROR org.cassandraunit.utils.EmbeddedCassandraServerHelper - Cassandra daemon did not start after 20000 ms. Consider increasing the timeout

否则端口冲突,例如

 2017-02-02 19:44:41.741 ERROR 40053 --- [pool-2-thread-1] o.a.cassandra.service.CassandraDaemon    : Fatal configuration error

org.apache.cassandra.exceptions.ConfigurationException: /127.0.0.1:7010 is in use by another process. Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services
at org.apache.cassandra.net.MessagingService.getServerSockets(MessagingService.java:557)
at org.apache.cassandra.net.MessagingService.listen(MessagingService.java:501)
at org.apache.cassandra.net.MessagingService.listen(MessagingService.java:485)
at org.apache.cassandra.service.StorageService.prepareToJoin(StorageService.java:745)
at org.apache.cassandra.service.StorageService.initServer(StorageService.java:648)
at org.apache.cassandra.service.StorageService.initServer(StorageService.java:548)
at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:385)
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:601)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper$1.run(EmbeddedCassandraServerHelper.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

2017-02-02 19:44:41.745 INFO 40053 --- [ Thread-7] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@7ffd8dee: startup date [Thu Feb 02 19:44:17 GMT 2017]; root of context hierarchy
2017-02-02 19:44:41.972 WARN 40053 --- [iceShutdownHook] org.apache.cassandra.gms.Gossiper : No local state or state is in silent shutdown, not announcing shutdown
2017-02-02 19:44:41.972 INFO 40053 --- [iceShutdownHook] o.apache.cassandra.net.MessagingService : Waiting for messaging service to quiesce
2017-02-02 19:44:41.982 INFO 40053 --- [iceShutdownHook] org.apache.cassandra.hints.HintsService : Paused hints dispatch
2017-02-02 19:44:42.072 INFO 40053 --- [iceShutdownHook] org.apache.cassandra.hints.HintsService : Paused hints dispatch

最佳答案

回答我自己的问题:我牺牲了 gradle 中的并行项目构建,即 org.gradle.parallel=false在我的gradle.properties

在我的测试中有:

@BeforeClass
public static void before() throws InterruptedException, IOException, TTransportException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000);
}

@AfterClass
public static void after() throws InterruptedException, IOException, TTransportException {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}

cleanEmbeddedCassandra()只是删除键空间,但让 Cassandra 服务器保持运行。

我更希望通过清理来停止 EmbeddedCassandraServer,而不是让它一直运行直到进程退出。

该方法工作可靠,但不是我想要的,也许有人会发布更好的方法!

关于java - 如果 org.gradle.parallel=true,一套 Java UT 的 cassandra-unit 会出现间歇性故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42011189/

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