I'm in the midst of a project using Apache Cassandra.  Because it's a web service, and because I'm using Maven, I want to take advantage of it's built-in unit-testing capabilities.  I found an amazing starter article by Ran Tavory over at PrettyPrint.me entitled "Running Cassandra as an Embedded Service" which details how to use the EmbeddedCassandraService to set up an Cassandra server for the subsequent test services.  Since I'm using the Restlet 2.0 API inside of a Jetty container, this will allow me to test my application against an extant Cassandra setup without requiring complicated development server setups.  Since I also have integration tests configured inside my Maven setup, I will be able to do end-to-end functionality testing of my application just by typing 'mvn integration-test.'  As I head towards a CI-based infrastructure for this project, this sort of setup will help facilitate constantly-improving quality and reliability - my project is the sort that requires it! 

I'm currently using TestNG as my testing framework, but there is no reason this setup shouldn't work as well with JUnit or any other testing framework.  It's mostly about getting the Cassandra server to start in-process - the Thrift/cassandra client APIs will still communicate over the Thrift port via the network.

 

Firstly, you have to add a few jar files to your maven repository, because currently these artifacts are not available in any online repositories:

 

       mvn install:install-file -Dfile=apache-cassandra-0.6.5.jar -DgroupId=org.apache -DartifactId=cassandra -Dversion=0.6.5 -Dpackaging=jar

       mvn install:install-file -Dfile=libthrift-r917130.jar -DgroupId=org.apache -DartifactId=thrift -Dversion=r917130 -Dpackaging=jar

       mvn install:install-file -Dfile=high-scale-lib.jar -DgroupId=org.cliffc -DartifactId=high_scale_lib -Dversion=1.0 -Dpackaging=jar

       mvn install:install-file -Dfile=clhm-production.jar -DgroupId=com.reardencommerce -DartifactId=reardencommerce -Dversion=1.0 -Dpackaging=jar

 

 Then you need to add a few dependencies to your pom.xml: 

        <dependencies>
                <!-- Apache Cassandra dependencies -->
                <dependency>
                        <groupId>org.apache</groupId>
                        <artifactId>cassandra</artifactId>
                        <version>0.6.5</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.apache</groupId>
                        <artifactId>thrift</artifactId>
                        <version>r917130</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.6.0</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.cliffc</groupId>
                        <artifactId>high_scale_lib</artifactId>
                        <version>1.0</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>com.reardencommerce</groupId>
                        <artifactId>reardencommerce</artifactId>
                        <version>1.0</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>commons-collections</groupId>
                        <artifactId>commons-collections</artifactId>
                        <version>3.2.1</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                        <version>2.5</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>

 

Attached is a slightly modified version of that file from Ran Tavory's site, which fixes a few compilation errors and switches to TestNG (the framework I've chosen).  I've only just gotten the parts working - I'm off to actually start integrating my service now - stick around for future updates!