-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull some helper test stuff into a CassandraTestUtil class
- Loading branch information
Showing
3 changed files
with
93 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/org/pingles/cascading/cassandra/CassandraTestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.pingles.cascading.cassandra; | ||
|
||
import org.apache.cassandra.thrift.InvalidRequestException; | ||
import org.apache.cassandra.thrift.NotFoundException; | ||
import org.apache.cassandra.thrift.SchemaDisagreementException; | ||
import org.apache.thrift.TException; | ||
import org.apache.thrift.transport.TTransportException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.util.Map; | ||
|
||
public class CassandraTestUtil { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CassandraSchemeTest.class); | ||
private static final String CASSANDRA_YAML = "./src/test/resources/cassandra.yaml"; | ||
|
||
public static void ensureKeyspace(String name) throws TException, InterruptedException, InvalidRequestException, SchemaDisagreementException { | ||
CassandraClient client = new CassandraClient(getRpcHost(), getRpcPort()); | ||
client.open(); | ||
if (!client.keyspaceExists(name)) { | ||
LOGGER.info("Creating test keyspace {}", name); | ||
client.createKeyspace(name); | ||
} | ||
client.close(); | ||
} | ||
|
||
public static void ensureColumnFamily(String keyspace, String columnFamily) throws TException, InterruptedException, NotFoundException, InvalidRequestException, SchemaDisagreementException { | ||
CassandraClient client = new CassandraClient(getRpcHost(), getRpcPort()); | ||
client.open(); | ||
if (!client.columnFamilyExists(keyspace, columnFamily)) { | ||
LOGGER.info("Creating test column family {}", columnFamily); | ||
client.createColumnFamily(keyspace, columnFamily); | ||
} | ||
client.close(); | ||
} | ||
|
||
public static Integer getRpcPort() { | ||
return (Integer) getCassandraConfiguration("rpc_port"); | ||
} | ||
|
||
public static String getRpcHost() { | ||
return "127.0.0.1"; | ||
} | ||
|
||
public static Object getCassandraConfiguration(String fieldName) { | ||
Yaml y = new Yaml(); | ||
try { | ||
Map m = (Map) y.load(new FileReader(CASSANDRA_YAML)); | ||
return m.get(fieldName); | ||
} catch (FileNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
} |