Skip to content

Cassandra Module

Usage example

This example connects to the Cassandra cluster:

  1. Define a container:

    CassandraContainer cassandraContainer = new CassandraContainer("cassandra:3.11.2")
    
  2. Build a CqlSession:

    final CqlSession cqlSession = CqlSession
        .builder()
        .addContactPoint(cassandraContainer.getContactPoint())
        .withLocalDatacenter(cassandraContainer.getLocalDatacenter())
        .build();
    
  3. Define a container with custom cassandra.yaml located in a directory cassandra-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>