Permalink
Browse files

jobs actually work!

  • Loading branch information...
Nick Kallen
Nick Kallen committed Apr 4, 2010
1 parent 982ac13 commit 1e90fce23d63bba775381bab0fc0ed99da560821
@@ -2,9 +2,17 @@ package com.twitter.rowz.jobs
import com.twitter.gizzard.jobs.UnboundJob
import com.twitter.xrayspecs.Time
+import com.twitter.xrayspecs.TimeConversions._
case class Create(id: Long, name: String, at: Time) extends UnboundJob[ForwardingManager] {
+ def this(attributes: Map[String, AnyVal]) = {
+ this(
+ attributes("id").toLong,
+ attributes("name").toString,
+ Time(attributes("at").toInt.seconds))
+ }
+
def toMap = {
Map("id" -> id, "name" -> name, "at" -> at.inSeconds)
}
@@ -6,8 +6,25 @@ import com.twitter.gizzard.jobs.UnboundJob
case class Destroy(row: Row, at: Time) extends UnboundJob[ForwardingManager] {
+ def this(attributes: Map[String, AnyVal]) = {
+ this(
+ new Row(
+ attributes("id").toLong,
+ attributes("name").toString,
+ Time(attributes("createdAt").toInt.seconds),
+ Time(attributes("updatedAt").toInt.seconds),
+ State(attributes("state").toInt)),
+ Time(attributes("at").toInt.seconds))
+ }
+
def toMap = {
- Map("id" -> row.id, "name" -> row.name, "createdAt" -> row.createdAt.inSeconds, "at" -> at.inSeconds)
+ Map(
+ "id" -> row.id,
+ "name" -> row.name,
+ "createdAt" -> row.createdAt.inSeconds,
+ "updatedAt" -> row.updatedAt.inSeconds,
+ "state" -> row.state.id,
+ "at" -> at.inSeconds)
}
def apply(forwardingManager: ForwardingManager) = {
@@ -21,11 +21,14 @@ object Database {
config("rowz.db.connection_pool.size_min").toInt,
config("rowz.db.connection_pool.size_max").toInt,
config("rowz.db.connection_pool.test_idle_msec").toLong.millis,
- config("rowz.db.connection_pool.max_wait").toLong.millis,
+ config("rowz.db.connection_pool.max_wait").toLong.millis,gi
config("rowz.db.connection_pool.test_on_borrow").toBoolean,
config("rowz.db.connection_pool.min_evictable_idle_msec").toLong.millis))
val queryEvaluatorFactory = new StandardQueryEvaluatorFactory(databaseFactory, new SqlQueryFactory)
- val queryEvaluator = queryEvaluatorFactory("localhost", null, "root", "") // XXX FIXME
- queryEvaluator.execute("DROP DATABASE IF EXISTS rowz_nameserver")
- queryEvaluator.execute("CREATE DATABASE rowz_nameserver")
+
+ config.getList("rowz.nameserver.hostnames").foreach { hostname =>
+ val queryEvaluator = queryEvaluatorFactory(hostname, null, config("rowz.nameserver.username"), config("rowz.nameserver.password"))
+ queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.nameserver.name"))
+ queryEvaluator.execute("CREATE DATABASE " + config("rowz.nameserver.name"))
+ }
}
@@ -27,17 +27,16 @@ object RowzSpec extends Specification with Eventually {
"row create & read" in {
println("1")
val id = rowzService.create("row", Time.now.inSeconds)
- Thread.sleep(5.seconds.inMillis)
println("2")
- rowzService.read(id)
+ rowzService.read(id) must eventually(not(throwA[Exception]))
println("3")
val row = rowzService.read(id)
println("4")
row.name mustEqual "row"
println("5")
rowzService.destroy(row, 1.second.fromNow.inSeconds)
println("6")
- rowzService.read(id) must eventually(throwA[thrift.RowzException])
+ rowzService.read(id) must eventually(throwA[Exception])
}
}
}

0 comments on commit 1e90fce

Please sign in to comment.