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
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; |
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
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() |
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
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'); |
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
public class AnimalsDaoTest { | |
@Rule | |
public CassandraCQLUnit cassandraCQLUnit = | |
new CassandraCQLUnit(new ClassPathCQLDataSet("animals.cql", "AnimalsKeyspace")); | |
private AnimalsDao animalsDao; | |
@Before | |
public void setUp() throws Exception { |
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
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"); |