Skip to content

Commit

Permalink
Merge pull request outworkers#235 from websudos/release/indexes
Browse files Browse the repository at this point in the history
Release/indexes
  • Loading branch information
alexflav23 committed May 10, 2015
2 parents 2dbc495 + a50886b commit 56d80d5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ trait PartitionKey[ValueType] extends Key[ValueType, PartitionKey[ValueType]] wi
/**
* A trait mixable into Column definitions to allow storing them as keys.
*/
trait Index[ValueType] extends Key[ValueType, Index[ValueType]] with Unmodifiable with Indexed with Undroppable {
trait Index[ValueType] extends Key[ValueType, Index[ValueType]] with Indexed with Undroppable {
self: AbstractColumn[ValueType] => override val isSecondaryKey = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CountTest extends PhantomCassandraTestSuite {
chain successful {
res => {
res.isDefined shouldBe true
res.get shouldEqual 999L
res.get shouldEqual limit.toLong
}
}
}
Expand All @@ -105,7 +105,7 @@ class CountTest extends PhantomCassandraTestSuite {
chain successful {
res => {
res.isDefined shouldBe true
res.get shouldEqual 999L
res.get shouldEqual limit.toLong
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MapOperationsTest extends PhantomCassandraTestSuite {
it should "support a single item map put operation" in {
val recipe = gen[Recipe]
val id = gen[UUID]
val props = genMap[String, String]()
val props = genMap[String, String](5)
val item = gen[String, String]

val insert = Recipes.insert
Expand Down Expand Up @@ -81,7 +81,7 @@ class MapOperationsTest extends PhantomCassandraTestSuite {
val recipe = gen[Recipe]
val id = gen[UUID]

val props = genMap[String, String]()
val props = genMap[String, String](5)
val item = gen[String, String]

val insert = Recipes.insert
Expand Down Expand Up @@ -112,8 +112,8 @@ class MapOperationsTest extends PhantomCassandraTestSuite {
it should "support a multiple item map put operation" in {
val recipe = gen[Recipe]
val id = gen[UUID]
val props = genMap[String, String]()
val mapItems = genMap[String, String]()
val props = genMap[String, String](5)
val mapItems = genMap[String, String](5)

val insert = Recipes.insert
.value(_.uid, id)
Expand Down Expand Up @@ -143,8 +143,8 @@ class MapOperationsTest extends PhantomCassandraTestSuite {
it should "support a multiple item map put operation with Twitter futures" in {
val recipe = gen[Recipe]
val id = gen[UUID]
val props = genMap[String, String]()
val mapItems = genMap[String, String]()
val props = genMap[String, String](5)
val mapItems = genMap[String, String](5)

val insert = Recipes.insert
.value(_.uid, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {

var i = 0

val recordList = genList[TimeSeriesRecord](6).map(
val number = 5

val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(1000, i))
Expand All @@ -72,7 +74,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.future()
insert <- batch.future()
chunks <- TimeSeriesTable.select.limit(5).fetch()
chunks <- TimeSeriesTable.select.limit(number).fetch()
} yield chunks


Expand All @@ -86,8 +88,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
it should "allow using naturally fetch the records in descending order for a descending clustering order with Twitter Futures" in {
var i = 0

val number = 5

val recordList = genList[TimeSeriesRecord](6).map(
val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(1000, i))
Expand All @@ -108,7 +111,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.execute()
insert <- batch.execute()
chunks <- TimeSeriesTable.select.limit(5).collect()
chunks <- TimeSeriesTable.select.limit(number).collect()
} yield chunks

chain.successful {
Expand All @@ -120,8 +123,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {

it should "allow fetching the records in ascending order for a descending clustering order using order by clause" in {
var i = 0
val number = 5

val recordList = genList[TimeSeriesRecord](6).map(
val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(500, i))
Expand All @@ -138,7 +142,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.future()
insert <- batch.future()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.asc).limit(5).fetch()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.asc).limit(number).fetch()
} yield chunks

chain.successful {
Expand All @@ -152,7 +156,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
it should "allow fetching the records in ascending order for a descending clustering order using order by clause with Twitter Futures" in {
var i = 0

val recordList = genList[TimeSeriesRecord](6).map(
val number = 5

val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(500, i))
Expand All @@ -169,7 +175,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.execute()
insert <- batch.execute()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.asc).limit(5).collect()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.asc).limit(number).collect()
} yield chunks

chain.successful {
Expand All @@ -182,7 +188,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
it should "allow fetching the records in descending order for a descending clustering order using order by clause" in {
var i = 0

val recordList = genList[TimeSeriesRecord](6).map(
val number = 5

val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(500, i))
Expand All @@ -198,7 +206,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.future()
insert <- batch.future()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.descending).limit(5).fetch()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.descending).limit(number).fetch()
} yield chunks

chain.successful {
Expand All @@ -210,8 +218,9 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {

it should "allow fetching the records in descending order for a descending clustering order using order by clause with Twitter Futures" in {
var i = 0
val number = 5

val recordList = genList[TimeSeriesRecord](6).map(
val recordList = genList[TimeSeriesRecord](number).map(
item => {
i += 1
item.copy(id = TimeSeriesTable.testUUID, timestamp = item.timestamp.withDurationAdded(500, i))
Expand All @@ -227,7 +236,7 @@ class TimeSeriesTest extends PhantomCassandraTestSuite {
val chain = for {
truncate <- TimeSeriesTable.truncate.execute()
insert <- batch.execute()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.desc).limit(5).collect()
chunks <- TimeSeriesTable.select.where(_.id eqs TimeSeriesTable.testUUID).orderBy(_.timestamp.desc).limit(number).collect()
} yield chunks

chain.successful {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ class SecondaryIndexTest extends PhantomCassandraTestSuite {
}
}

it should "allow updating the value of a secondary index" in {
val sample = gen[SecondaryIndexRecord]
val updated = gen[UUID]

val chain = for {
insert <- SecondaryIndexTable.store(sample).future()
selected <- SecondaryIndexTable.select.where(_.secondary eqs sample.secondary).allowFiltering().one()
select <- SecondaryIndexTable.update.where(_.id eqs sample.primary).modify(_.secondary setTo updated).future()
updated <- SecondaryIndexTable.select.where(_.secondary eqs updated).allowFiltering().one()
} yield (selected, updated)

chain.successful {
res => {
val primary = res._1
val secondary = res._2

info("Querying by primary key should return the record")
primary.isDefined shouldBe true
primary.get shouldEqual sample

info("Querying by the secondary index key should also return the record")
secondary.isDefined shouldEqual true
secondary.get shouldEqual sample.copy(secondary = updated)
}
}
}

it should "not throw an error if filtering is not enabled when querying by secondary keys" in {
val sample = gen[SecondaryIndexRecord]
val chain = for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ package object tables {
}

implicit object SimpleMapOfStringsClassSampler extends Sample[SimpleMapOfStringsClass] {
def sample: SimpleMapOfStringsClass = SimpleMapOfStringsClass(genMap[Int, String]())
def sample: SimpleMapOfStringsClass = SimpleMapOfStringsClass(genMap[String, Int](5))
}

implicit object RecipeSampler extends Sample[Recipe] {
Expand Down Expand Up @@ -187,9 +187,9 @@ package object tables {
gen[String],
genList[String](),
genList[String]().toSet,
genMap[String, String](),
genMap[String, String](5),
genList[Int]().toSet,
genMap[Int, String]().map(_.swap)
genMap[Int, String](5)
)
}

Expand All @@ -208,7 +208,7 @@ package object tables {
genOpt[Int],
gen[SimpleMapOfStringsClass],
genOpt[SimpleMapOfStringsClass],
genMap[SimpleMapOfStringsClass, String]()
genMap[String, SimpleMapOfStringsClass](5)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
*/
package com.websudos.phantom.testkit.suites

import com.websudos.phantom.connectors.{KeySpace, SimpleCassandraConnector}
import org.scalatest.concurrent.{AsyncAssertions, ScalaFutures}
import scala.concurrent.duration._

import org.scalatest.concurrent.{PatienceConfiguration, AsyncAssertions, ScalaFutures}
import org.scalatest.{Assertions, BeforeAndAfterAll, FeatureSpec, FlatSpec, Matchers, Suite}

import com.websudos.phantom.connectors.{KeySpace, SimpleCassandraConnector}

trait SimpleCassandraTest extends ScalaFutures
with SimpleCassandraConnector
with Matchers
Expand All @@ -42,6 +45,12 @@ trait SimpleCassandraTest extends ScalaFutures
with CassandraSetup {
self : BeforeAndAfterAll with Suite =>

/**
* The default timeout value for phantom tests, passed implicitly to the testing framework.
* @return The default timeout value.
*/
implicit def patience: PatienceConfiguration.Timeout = timeout(5 seconds)

override def beforeAll() {
super.beforeAll()
setupCassandra()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ package com.websudos.phantom.zookeeper

import java.net.InetSocketAddress

import org.scalatest.{Matchers, FlatSpec}
import org.scalatest.{FlatSpec, Matchers}

class DefaultClusterStoreTest extends FlatSpec with Matchers {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@
package com.websudos.phantom.zookeeper

import java.net.InetSocketAddress
import scala.concurrent.duration._

import com.websudos.phantom.connectors.{CassandraProperties, DefaultCassandraManager}
import com.websudos.util.testing._
import com.websudos.util.zookeeper.ZooKeeperInstance
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}


class ZookeeperConnectorTest extends FlatSpec with Matchers with BeforeAndAfterAll with CassandraSetup {

implicit def patience: PatienceConfiguration.Timeout = timeout(5 seconds)

val instance = new ZooKeeperInstance("/cassandra")

override def beforeAll(): Unit = {
Expand Down
22 changes: 16 additions & 6 deletions project/PhantomBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import sbt._

object PhantomBuild extends Build {

val UtilVersion = "0.6.12"
val UtilVersion = "0.7.5"
val DatastaxDriverVersion = "2.1.5"
val ScalaTestVersion = "2.2.1"
val ShapelessVersion = "2.2.0-RC4"
val FinagleVersion = "6.24.0"
val TwitterUtilVersion = "6.23.0"
val FinagleVersion = "6.25.0"
val TwitterUtilVersion = "6.24.0"
val ScroogeVersion = "3.17.0"
val ThriftVersion = "0.9.1"
val ScalatraVersion = "2.3.0"
Expand Down Expand Up @@ -87,7 +87,7 @@ object PhantomBuild extends Build {

def liftVersion(scalaVersion: String): String = {
scalaVersion match {
case "2.10.4" => "3.0-M1"
case "2.10.5" => "3.0-M1"
case _ => "3.0-M2"
}
}
Expand All @@ -111,11 +111,21 @@ object PhantomBuild extends Build {
val PerformanceTest = config("perf").extend(Test)
def performanceFilter(name: String): Boolean = name endsWith "PerformanceTest"

val bintrayPublishing: Seq[Def.Setting[_]] = Seq(
publishMavenStyle := false,
bintray.BintrayKeys.bintrayOrganization := Some("websudos"),
bintray.BintrayKeys.bintrayRepository := "oss-releases",
publishArtifact in Test := false,
pomIncludeRepository := { _ => true},
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))
)


val sharedSettings: Seq[Def.Setting[_]] = Defaults.coreDefaultSettings ++ Seq(
organization := "com.websudos",
version := "1.8.1",
version := "1.8.3",
scalaVersion := "2.11.6",
crossScalaVersions := Seq("2.10.4", "2.11.6"),
crossScalaVersions := Seq("2.10.5", "2.11.6"),
resolvers ++= Seq(
"Typesafe repository snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
"Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4")

addSbtPlugin("me.lessis" % "bintray-sbt" % "0.2.1")
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")

0 comments on commit 56d80d5

Please sign in to comment.