From 5eb1a35b8c276dc7a5436094fe9e69dfe38fc2c1 Mon Sep 17 00:00:00 2001 From: Richard North Date: Thu, 5 Mar 2020 21:04:30 +0000 Subject: [PATCH] #1975: add example for Cassandra module (#2210) --- docs/modules/databases/cassandra.md | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/modules/databases/cassandra.md b/docs/modules/databases/cassandra.md index 0d9a52a0166..d15304afa81 100644 --- a/docs/modules/databases/cassandra.md +++ b/docs/modules/databases/cassandra.md @@ -1,5 +1,38 @@ # Cassandra Module +## Usage example + +This example connects to the Cassandra Cluster, creates a keyspaces and asserts that is has been created. + +```java tab="JUnit 4 example" +public class SomeTest { + + @Rule + public CassandraContainer cassandra = new CassandraContainer(); + + + @Test + public void test(){ + Cluster cluster = cassandra.getCluster(); + + try(Session session = cluster.connect()) { + + session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication = \n" + + "{'class':'SimpleStrategy','replication_factor':'1'};"); + + List keyspaces = session.getCluster().getMetadata().getKeyspaces(); + List filteredKeyspaces = keyspaces + .stream() + .filter(km -> km.getName().equals("test")) + .collect(Collectors.toList()); + + assertEquals(1, filteredKeyspaces.size()); + } + } + +} +``` + ## Adding this module to your project dependencies Add the following dependency to your `pom.xml`/`build.gradle` file: