The project demonstrates an approach to organize a client's API to deal with duplicating data when working with Apache Cassandra
By default, the test will use testcontainers to start cassandra, so the user is expected to simply run tests: mvn test
:
- Direct approach:
mvn test -Dtest=com.github.neshkeev.papers.cassandra.DirectApproachTest
- Factory Method + Builder:
mvn test -Dtest=com.github.neshkeev.papers.cassandra.FactoryTest
- Factory Method + State Machine based Builder:
mvn test -Dtest=com.github.neshkeev.papers.cassandra.FactoryStateMachineTest
IMPORTANT: Don't be alarmed with the Cannot assign requested address
messages in the output, that is how the testcontainers library waits for the cassandra docker container to start
If the user is not able to use testcontainers, it possible to run the tests against an external instance of Cassandra. There is the -Duse.cassandra.in.testcontainers system property to control how Cassandra is accessed: when it's false
, the external instance of Cassandra is used.
- Start cassandra:
docker compose up
- Wait for cassandra to start. The
cassandra
container should be in thehealthy
state:watch docker compose ps
- Set up the cluster:
docker compose exec -it cassandra cqlsh --file="/mnt/scripts/setup.cql"
- Set up the environment (skip if docker is on
localhost
):- set the
CONTACT_POINT
environment variable, if cassandra is not onlocalhost:9042
(default):export CONTACT_POINT=localhost:9042
- set the
KEYSPACE_NAME
environment variable, if the keyspace is notCONSISTENT_BUILDER_DEMO_CLUSTER
(default):export KEYSPACE_NAME=CONSISTENT_BUILDER_DEMO_CLUSTER
- set the
- Run tests:
- Direct approach:
mvn test -Duse.cassandra.in.testcontainers=false -Dtest=com.github.neshkeev.papers.cassandra.DirectApproachTest
- Factory Method + Builder:
mvn test -Duse.cassandra.in.testcontainers=false -Dtest=com.github.neshkeev.papers.cassandra.FactoryTest
- Factory Method + State Machine based Builder:
mvn test -Duse.cassandra.in.testcontainers=false -Dtest=com.github.neshkeev.papers.cassandra.FactoryStateMachineTest
- Direct approach: