| [ Web Proxy ] |
| Viewing: https://java.testcontainers.org/supported_docker_environment/../../modules/databases/cassandra/ | [Back] [Original] |
This example connects to the Cassandra cluster:
Define a container:
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
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 directory cassandra-auth-required-configuration:
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-auth-required-configuration")
.withInitScript("initial.cql")
If you override the default cassandra.yaml with a version setting the property client_encryption_options.optional
to false, you have to provide a valid client certificate and key (PEM format) when you initialize your container:
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)
.withConfigurationOverride("cassandra-ssl-configuration")
.withSsl("client-ssl/cassandra.cer.pem", "client-ssl/cassandra.key.pem")
Hint
To generate the client certificate and key, please refer to this documentation.
Add the following dependency to your pom.xml/build.gradle file:
testImplementation "org.testcontainers:testcontainers-cassandra:2.0.5"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-cassandra</artifactId>
<version>2.0.5</version>
<scope>test</scope>
</dependency>
| Web Proxy Viewer | New URL | Original Page |