JUnit Testing Cassandra with embedded server
We use an embedded cassandra server, and I think that is the best approach when testing cassandra, mocking the cassandra API is too error prone.
EmbeddedServerHelper.cleanup()
just removes files rom the file system, but data may still exist in memory.
There is a teardown()
method in EmbeddedServerHelper
, but I a not sure how effective that is, as cassandra has a lot of static singletons whose state is not cleaned up by teardown()
What we do is we have a method that calls truncate on each column family between tests. That will remove all data.
I think you can take a look at cassandra-unit : https://github.com/jsevellec/cassandra-unit/wiki
I use the Mojo Cassandra maven plugin.
Here's an example plugin configuration that I use to spin up a Cassandra server for use by my unit tests:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cassandra-maven-plugin</artifactId>
<version>1.1.0-1</version>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>flush</goal>
<goal>cleanup</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugins>
<build>
I did manage to get Hector's embedded server helper class working which can be very useful, however I ran into classloader conflicts due to this bug.