This repository has been archived by the owner on May 22, 2019. It is now read-only.
/
ShardsIntegrationSpec.scala
58 lines (44 loc) · 1.71 KB
/
ShardsIntegrationSpec.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
50
51
52
53
54
55
56
57
58
package com.twitter.gizzard.shards
import java.sql.SQLException
import scala.collection.mutable
import com.twitter.gizzard.thrift.conversions.Sequences._
import com.twitter.querulous.evaluator.QueryEvaluator
import org.specs.Specification
import org.specs.mock.{ClassMocker, JMocker}
import nameserver.{ManagingNameServer, SqlNameServer, ShardRepository}
object ShardsIntegrationSpec extends Specification with JMocker with ClassMocker with Database {
// SqlNameServer.rebuildSchema(queryEvaluator)
val shardInfo1 = new ShardInfo("com.example.UserShard", "table1", "localhost")
val shardInfo2 = new ShardInfo("com.example.UserShard", "table2", "localhost")
class UserShard(val shardInfo: ShardInfo, val weight: Int, val children: Seq[Shard]) extends Shard {
val data = new mutable.HashMap[Int, String]
def setName(id: Int, name: String) {
data(id) = name
}
def getName(id: Int) = data(id)
}
val factory = new ShardFactory[UserShard] {
def instantiate(shardInfo: ShardInfo, weight: Int, children: Seq[Shard]) = {
new UserShard(shardInfo, weight, children)
}
def materialize(shardInfo: ShardInfo) {
// nothing.
}
}
"Shards" should {
var shardRepository: ShardRepository[UserShard] = null
var nameServer: ManagingNameServer = null
doBefore {
shardRepository = new ShardRepository
shardRepository += (("com.example.UserShard", factory))
shardRepository += (("com.example.SqlShard", factory))
nameServer = new SqlNameServer(queryEvaluator, (a: ShardInfo) => ())
nameServer.createShard(shardInfo1)
nameServer.createShard(shardInfo2)
// nameServer.reload()
}
"WriteOnlyShard" in {
3 mustEqual 3
}
}
}