randas avatar image
randas asked absurdfarce answered

Getting NoSuchMethodError running cassandra-unit through SBT

I have a unit tests that needs an Embedded cassandra. So I'm using "cassandra-unit" , The problem that I could run all my tests from intellij successfully, but when I run it via : sbt test

Embedded cassandra failed to restart due to this error:

java.lang.NoSuchMethodError: 'java.nio.file.FileStore' [error]
     at org.apache.cassandra.config.DatabaseDescriptor.guessFileStore( [error]
     at org.apache.cassandra.config.DatabaseDescriptor.applySimpleConfig( [error]
     at org.apache.cassandra.config.DatabaseDescriptor.applyAll( [error]
     at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization( [error]
     at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization( [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra( [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra( [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(

as I need to run the tests via sbt test because I want to integrate it with jenkins since I'm facing the same issue.

here's my dependencies with scala :2.12 :

    "com.datastax.spark" %% "spark-cassandra-connector-assembly" % "3.0.1" ,
    "spark.jobserver" %% "job-server-api" % "0.11.1" ,
    "org.apache.spark" %% "spark-core" % "3.0.2" ,
    "org.apache.spark" %% "spark-sql" % "3.0.2",   
    "org.scalatest" %% "scalatest" % "3.1.1" % "test" excludeAll(excludeJpountz),   
     "org.apache.cassandra" % "cassandra-clientutil" % "3.9" % "test" excludeAll(excludeJpountz),
    "org.cassandraunit" % "cassandra-unit" % "" % "test" excludeAll(excludeJpountz)

my cassandra.yaml have like these :

commitlog_directory: target/embeddedCassandra/commitlog
cdc_raw_directory: target/embeddedCassandra/
cdc saved_caches_directory: target/embeddedCassandra/saved_caches

I've cheeked my java home it's (build 1.8.0_271-b09) which is same what I'm using it intellij target 1.8,

and I tried to remove the target from these paths under cassandra.yaml, since I read that when sbt it's executing the Target folder will not be exists, but it gives me same error. is there any other way to edit these paths ?

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

absurdfarce avatar image
absurdfarce answered

Greetings @randas , and thanks for your question!

I'm pretty sure the cassandra-clientutil dependency is what's getting you into trouble here. You're including version 3.9 of this lib here which corresponds to a set of utility classes from Cassandra 3.9. This JAR includes but the version of the class included there doesn't have a getFileStore() method (see to validate).

In short, if you wind up with this JAR in the classpath ahead of the Cassandra 3.11.4 JAR specified as a dependency of cassandra-unti you'll get the 3.9 version (which doesn't have the desired method) instead of the 3.11.4 version (in the Cassandra JAR which does have the desired method). Note that DatabaseDescriptor is not included in the clientutil JAR (it's definitely a server-side thing) so that explains how you wind up in this condition at all.

I suspect you'll probably have similar problems if you keep the clientutil JAR in place. Unless you have a very strong reason to keep it around I'd suggest removing it.

Thanks again!

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.