Reusable Containers (Experimental)
Cassandra Module
登录后可跨设备保存划线和私人笔记登录
Cassandra Module
Usage example
This example connects to the Cassandra cluster:
Define a container:
Container definition
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE)Build a
CqlSession:Building CqlSession
final CqlSession cqlSession = CqlSession .builder() .addContactPoint(cassandraContainer.getContactPoint()) .withLocalDatacenter(cassandraContainer.getLocalDatacenter()) .build();Define a container with custom
cassandra.yamllocated in a directorycassandra-auth-required-configuration:Running init script with required authentication
CassandraContainer cassandraContainer = new CassandraContainer(CASSANDRA_IMAGE) .withConfigurationOverride("cassandra-auth-required-configuration") .withInitScript("initial.cql")
Using secure connection (TLS)
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:
SSL setup
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.
Adding this module to your project dependencies
Add the following dependency to your pom.xml/build.gradle file:
GradleMaven
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>评论
登录后参与评论
正在加载评论…
KnowForge