question

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 org.apache.cassandra.io.util.FileUtils.getFileStore(java.nio.file.Path)' [error]
     at org.apache.cassandra.config.DatabaseDescriptor.guessFileStore(DatabaseDescriptor.java:1029) [error]
     at org.apache.cassandra.config.DatabaseDescriptor.applySimpleConfig(DatabaseDescriptor.java:470) [error]
     at org.apache.cassandra.config.DatabaseDescriptor.applyAll(DatabaseDescriptor.java:316) [error]
     at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization(DatabaseDescriptor.java:148) [error]
     at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization(DatabaseDescriptor.java:132) [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:145) [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:110) [error]
     at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:90)

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" % "3.11.2.0" % "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 ?

spark-cassandra-connector
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 o.a.c.io.util.FileUtils but the version of the class included there doesn't have a getFileStore() method (see https://github.com/apache/cassandra/blob/cassandra-3.9/src/java/org/apache/cassandra/io/util/FileUtils.java 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 3.11.2.0 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!

Share
10 |1000

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