This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
forked from nkallen/Rowz
/
SqlShardSpec.scala
49 lines (41 loc) · 1.64 KB
/
SqlShardSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.twitter.rowz.unit
import org.specs.Specification
import org.specs.mock.{ClassMocker, JMocker}
import com.twitter.xrayspecs.Time
import com.twitter.xrayspecs.TimeConversions._
import com.twitter.gizzard.shards.{ShardInfo, Busy}
object SqlShard extends Specification with JMocker with ClassMocker {
"SqlShard" should {
import Database._
Time.freeze()
val shardFactory = new SqlShardFactory(queryEvaluatorFactory, config)
val shardInfo = new ShardInfo("com.twitter.service.flock.edges.SqlShard",
"table_001", "localhost", "INT UNSIGNED", "INT UNSIGNED", Busy.Normal, 1)
val sqlShard = shardFactory.instantiate(shardInfo, 1, List[Shard]())
val queryEvaluator = queryEvaluatorFactory(shardInfo.hostname, null, config("rowz.db.username"), config("rowz.db.password"))
val row = new Row(1, "a row", Time.now, Time.now, State.Normal)
doBefore {
queryEvaluator.execute("DROP DATABASE IF EXISTS " + config("rowz.db.name"))
shardFactory.materialize(shardInfo)
}
"create & read" in {
sqlShard.create(row.id, row.name, row.createdAt)
sqlShard.read(row.id) mustEqual Some(row)
}
"create, destroy then read" in {
sqlShard.create(row.id, row.name, row.createdAt)
sqlShard.destroy(row, row.createdAt + 1.second)
sqlShard.read(row.id) mustEqual None
}
"idempotent" in {
"read a nonexistent row" in {
sqlShard.read(row.id) mustEqual None
}
"destroy, create, then read" in {
sqlShard.destroy(row, row.createdAt)
sqlShard.create(row.id, row.name, row.createdAt - 1.second)
sqlShard.read(row.id) mustEqual None
}
}
}
}