Skip to content

Commit

Permalink
#1975: add example for Cassandra module (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Mar 5, 2020
1 parent f43e799 commit 16e9be9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 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<KeyspaceMetadata> keyspaces = session.getCluster().getMetadata().getKeyspaces();
List<KeyspaceMetadata> 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:
Expand Down

0 comments on commit 16e9be9

Please sign in to comment.