cassandrascalatestcassandra-3.0embedded-cassandra

An exception or error caused a run to abort: Unable to start EmbeddedCassandra[name='cassandra-2', version='3.11.6']


I am using embedded-cassandra in my unit tests (Scalatest). When I try to run all the test cases as batch, I get error

An exception or error caused a run to abort: Unable to start EmbeddedCassandra[name='cassandra-2', version='3.11.6']
...
Caused by: java.io.IOException: 'WindowsCassandraNode[pid='-1', exitValue='0']' is not alive. Please see logs for more details
    Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file C:\Users\manuc\AppData\Local\Temp\apache-cassandra-3.11.6-5333812070060739596/logs/gc.log due to No such file or directory
...
ava.net.BindException: Address already in use: JVM_Bind
        java.net.BindException: Address already in use: JVM_Bind
    ERROR [main] 2020-09-17 06:27:11,872 CassandraDaemon.java:774 - Port already in use: 7199; nested exception is:

What I might be doing wrong? As the trace says cassandra-2, it seems that another instance of Cassandra is already running? Could it be that the tests are running simultaneously? What is the way to run tests serially in Intellij/Scalatest?

This answers mentions that Scalatest would run suits in parallel which might be causing the port conflict issue. Is there a way to avoid port conflict in embedded-cassandra or run suites serially? - How to run tests in a class sequentially in ScalaTest?


Solution

  • You can try to use random ports to solve your issue:

    EmbeddedCassandraFactory cassandraFactory = new EmbeddedCassandraFactory();
    cassandraFactory.setPort(0);
    cassandraFactory.setSslPort(0); // if SSL client options enabled
    cassandraFactory.setRpcPort(0);
    cassandraFactory.setJmxLocalPort(0);
    cassandraFactory.setStoragePort(0);
    cassandraFactory.setSslStoragePort(0); // // if SSL server options enabled