Cassandra Module
Usage example
This example connects to the Cassandra cluster:
-
Define a container:
CassandraContainer cassandraContainer = new CassandraContainer("cassandra:3.11.2")
-
Build a
CqlSession
:final CqlSession cqlSession = CqlSession .builder() .addContactPoint(cassandraContainer.getContactPoint()) .withLocalDatacenter(cassandraContainer.getLocalDatacenter()) .build();
-
Define a container with custom
cassandra.yaml
located in a directorycassandra-auth-required-configuration
:CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE) .withConfigurationOverride("cassandra-auth-required-configuration") .withInitScript("initial.cql")
Adding this module to your project dependencies
Add the following dependency to your pom.xml
/build.gradle
file:
testImplementation "org.testcontainers:cassandra:1.20.4"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>