i am using Cassandra in several JUnit Tests Classes. The Problem: I do not know how to tear down/drop the cassandra correct after finishing a Test. I do not want to reuse the same instance of the Cassandra in other Tests or Testclasses, this is thre reason why i want to stop and tear down the DB after each Test.
The Question: How can i tear down the Embedded Cassandra ?
@Before
public void setUp() throws Exception {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.DEFAULT_CASSANDRA_YML_FILE,
CASSANDRA_SETUP_TIMEOUT_IN_MILLIS);
cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST).withPort(CASSANDRA_PORT).build();
final Session session = cluster.connect();
String cql = "create keyspace IF NOT EXISTS " + CASSANDRA_KEYSPACE
+ " with replication={'class':'NetworkTopologyStrategy','datacenter1':1};";
System.out.println(cql);
session.execute(cql);
cql = "USE " + CASSANDRA_KEYSPACE + ";";
System.out.println(cql);
session.execute(cql);
}
@After
public void tearDown() throws Exception {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
session.close();
cluster.close();
//Stop is not working, due to deprectated:
//EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}