我在几个JUnit测试类中使用Cassandra。 问题: 完成测试后,我不知道如何拆卸/放下卡桑德拉。 我不想在其他测试或测试类中重用相同的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();
}