'EmbeddedCassandraServerHelper returning that keyspace exists when it doesn't
I check for the keyspace, System.out.println(cluster.getMetadata().getKeyspace(finalKeyspace));, which returns null. However, when I try to create the keyspace it returns keyspace 'library' already exists from when I first ran the program.
public static void setupEmbeddedCassandra(String cqlFile, String keyspaceName)
throws IOException, TTransportException, InterruptedException {
synchronized (lock) {
if (finalKeyspace == null) {
System.out.println(CLASS_NAME + " Setting up local embedded cassandra environment");
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
int embeddedCassandraPort = EmbeddedCassandraServerHelper.getNativeTransportPort();
System.setProperty("embeddedCassandraPort", String.valueOf(embeddedCassandraPort));
cluster =
(new Cluster.Builder())
.addContactPoints(new String[] {"localhost"})
.withPort(embeddedCassandraPort)
.build();
session = cluster.connect();
cluster.getConfiguration();
System.out.println(cluster.getMetadata().getKeyspace("library"));
CQLDataLoader dataLoader = new CQLDataLoader(session);
System.out.println(cluster.getMetadata().getKeyspace("library"));
dataLoader.load(new ClassPathCQLDataSet(cqlFile, true, keyspaceName));
System.out.println(
CLASS_NAME
+ " Embedded Server started on port "
+ EmbeddedCassandraServerHelper.getNativeTransportPort());
}
finalKeyspace = keyspaceName;
System.out.println("here " + cluster.getMetadata().getKeyspace(finalKeyspace));
}
}
I also run a method at the end of each test that drops each keyspace. When i check for the existing keyspace after running the drop method, it returns null for the "library" keyspace as expected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
