我正在尝试为一组运行org.gradle.parallel=true
的UT用于spring-boot应用程序引入 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
所述作为一种解决方法,我尝试删除注释,而是使用本机API,即尝试保持一个运行以进行所有测试,并使用org.gradle.parallel=false
这似乎是可靠的,但会降低整体构建速度。 (仍在进行测试以确保其不一致)使用此方法
在单元级之前:
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
和单位班后:
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
答案 0 :(得分:1)
回答我自己的问题:
我牺牲了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,而不是让它继续运行,直到进程退出。
这种方法工作可靠,但不是我想要的,也许有人会发布更好的方法!
答案 1 :(得分:0)
EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.CASSANDRA_RNDPORT_YML_FILE);