Skip to content

Instantly share code, notes, and snippets.

View adamdougal's full-sized avatar

Adam Dougal adamdougal

  • Microsoft
  • UK
  • 18:47 (UTC +01:00)
View GitHub Profile
@adamdougal
adamdougal / CassandraSessionFactoryTest.java
Last active August 29, 2015 14:17
CassandraSessionFactoryTest
import com.datastax.driver.core.Session;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.scassandra.http.client.ActivityClient;
import org.scassandra.http.client.Query;
import org.scassandra.junit.ScassandraServerRule;
import static org.hamcrest.MatcherAssert.assertThat;
@adamdougal
adamdougal / CassandraSessionFactory.java
Last active August 29, 2015 14:17
CassandraSessionFactory
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class CassandraSessionFactory {
public Session create(String[] hosts, int port, String keyspace) {
return Cluster.builder()
.addContactPoints(hosts)
.withPort(port)
.build()
@adamdougal
adamdougal / animals.cql
Created January 1, 2015 12:25
Cassandra Unit Example
CREATE TABLE animals(
name text,
type text,
PRIMARY KEY(name)
);
INSERT INTO animals (name, type) values ('eagle', 'bird');
INSERT INTO animals (name, type) values ('clown fish', 'fish');
INSERT INTO animals (name, type) values ('reindeer', 'mammal');
INSERT INTO animals (name, type) values ('frog', 'amphibian');
@adamdougal
adamdougal / AnimalsDaoTest.java
Created January 1, 2015 12:25
Cassandra Unit Example
public class AnimalsDaoTest {
@Rule
public CassandraCQLUnit cassandraCQLUnit =
new CassandraCQLUnit(new ClassPathCQLDataSet("animals.cql", "AnimalsKeyspace"));
private AnimalsDao animalsDao;
@Before
public void setUp() throws Exception {
@adamdougal
adamdougal / AnimalsDao.java
Last active August 29, 2015 14:12
Cassandra Unit Example
public class AnimalsDao {
private final Session session;
public AnimalsDao(Session session) {
this.session = session;
}
public List<Animal> find() {
ResultSet resultSet = session.execute("SELECT name, type FROM animals");