Skip to content

Commit

Permalink
use the converter to make a sane data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Mar 18, 2010
1 parent 1f4e09a commit 94dc0d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/main/scala/Cassandra.scala
Expand Up @@ -39,15 +39,16 @@ class Cassandra(val keyspace: String,
}

def get(columnFamily: String, key: String,
reversed: Boolean, limit: Int): JList[KeySlice] = {
reversed: Boolean, limit: Int): Map[Array[Byte], Array[Byte]] = {
val parent = converter.makeColumnParent(columnFamily)
val predicate = converter.makeSlicePredicate(reversed, limit)
val keyRange = converter.makeKeyRange(key)
val list = client.get_range_slices(keyspace, parent, predicate, keyRange, 1)

client.get_range_slices(keyspace, parent, predicate, keyRange, 1)
converter.toMap(list)
}

def get(columnFamily: String, key: String): JList[KeySlice] = {
def get(columnFamily: String, key: String): Map[Array[Byte], Array[Byte]] = {
get(columnFamily, key, false, 100)
}
}
18 changes: 16 additions & 2 deletions src/test/scala/CassandraSpec.scala
Expand Up @@ -10,6 +10,7 @@ import java.util.{List => JList}
import org.apache.cassandra.thrift.{Cassandra => TCassandra}
import org.apache.cassandra.thrift.ColumnParent
import org.apache.cassandra.thrift.KeyRange
import org.apache.cassandra.thrift.KeySlice
import org.apache.cassandra.thrift.{Mutation => TMutation}
import org.apache.cassandra.thrift.SlicePredicate

Expand All @@ -35,31 +36,44 @@ object CassandraSpec extends Specification with Mockito {
val columnParent = mock[ColumnParent]
val slicePredicate = mock[SlicePredicate]
val keyRange = mock[KeyRange]
val keySlices = mock[JList[KeySlice]]
val map = mock[Map[Array[Byte], Array[Byte]]]

client.get_range_slices(keyspace, columnParent, slicePredicate, keyRange, 1) returns keySlices
converter.toMap(keySlices) returns map

"with all the options specified" in {
converter.makeColumnParent("Users") returns columnParent
converter.makeSlicePredicate(false, 10) returns slicePredicate
converter.makeKeyRange("1") returns keyRange

cassandra.get("Users", "1", false, 10)
val returned = cassandra.get("Users", "1", false, 10)

"converts to thrift data types and queries thrift" in {
client.get_range_slices(keyspace, columnParent,
slicePredicate, keyRange, 1) was called
}

"returns the converted map" in {
returned must_== map
}
}

"with only the cf and key specified" in {
converter.makeColumnParent("Users") returns columnParent
converter.makeSlicePredicate(false, 100) returns slicePredicate
converter.makeKeyRange("1") returns keyRange

cassandra.get("Users", "1")
val returned = cassandra.get("Users", "1")

"converts to thrift data types and queries thrift" in {
client.get_range_slices(keyspace, columnParent,
slicePredicate, keyRange, 1) was called
}

"returns the converted map" in {
returned must_== map
}
}
}
}

0 comments on commit 94dc0d2

Please sign in to comment.