Name: cassandra-extra
Owner: Spotify
Description: null
Created: 2015-06-11 08:48:16.0
Updated: 2018-04-19 21:11:41.0
Pushed: 2015-07-16 08:59:15.0
Homepage: null
Size: 186
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Set of tools enhancing the experience with Apache Cassandra. For now, the project includes only EmbeddedCassandra and CassandraRule.
The instalation is done by pulling an artifact from Maven central:
endency>
<groupId>com.spotify</groupId>
<artifactId>cassandra-extra</artifactId>
<version>0.0.1</version>
pendency>
EmbeddedCassandra allows spawning a 1-node Apache Cassandra cluster within the currently running JVM. This is useful for some tests that go beyond simple client requests. For example, it's very useful to test things like integration with data processing technologies.
EmbeddedCassandra's API is intentionaly rather raw and feature-less. Please, see CassandraRule for more convenience.
CassandraRule wraps EmbeddedCassandra and exposes it as a JUnit @Rule. An example usage:
ule
blic CassandraRule cassandraRule = CassandraRule.newBuilder()
.withManagedKeyspace()
.withManagedTable("CREATE TABLE user (id TEXT PRIMARY KEY, email TEXT);")
.build();
sert insertQuery = QueryBuilder
.insertInto("user")
.value("id", "zvo")
.value("email", "foo@bar.baz");
lect.Where selectQuery = QueryBuilder
.select("id", "email")
.from("user")
.where(eq("id", "zvo"));
est
blic void insertAndSelect() {
Session session = cassandraRule.getSession();
session.execute(insertQuery);
List<Row> rows = session.execute(selectQuery).all();
assertEquals(1, rows.size());
assertEquals("zvo", rows.get(0).getString("id"));
assertEquals("foo@bar.baz", rows.get(0).getString("email"));
In the above example, .withManagedKeyspace()
will create a randomly named keyspace and execute an USE
command. Next, .withManagedTable()
will create a table in the keyspace. Consequently, .getSession()
will return a session with the keyspace already created and initialised. Keyspaces and tables are created and destroyed during @Before
, resp. @After
each @Test
. Having the keyspace and table managed is optional; if this feature is not enabled, @Before
and @After
don't manipulate them.
This software is released under the Apache License 2.0. More information in the file LICENSE distributed with this project.