This repository has been archived by the owner on May 22, 2019. It is now read-only.
/
ConfiguredSpecification.scala
114 lines (95 loc) · 4 KB
/
ConfiguredSpecification.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.twitter.gizzard
import java.io.File
import org.specs.Specification
import net.lag.configgy.Configgy
import com.twitter.querulous.evaluator.QueryEvaluator
import com.twitter.rpcclient.{PooledClient, ThriftConnection}
import com.twitter.util.Eval
import com.twitter.gizzard
import testserver.{Priority, TestServer}
import testserver.config.TestServerConfig
trait ConfiguredSpecification extends Specification {
noDetailedDiffs()
val config = Eval[gizzard.config.GizzardServer](new File("config/test.scala"))
config.logging()
}
trait IntegrationSpecification extends Specification {
val evaluator = QueryEvaluator("localhost", "", "root", "", Map[String,String]())
trait TestServerFacts {
def enum: Int; def nsDatabaseName: String; def databaseName: String
def basePort: Int; def injectorPort: Int; def managerPort: Int
def sqlShardInfos: Seq[shards.ShardInfo]
def replicatingShardInfo: shards.ShardInfo
def forwarding: nameserver.Forwarding
def kestrelQueues: Seq[String]
}
def testServer(i: Int) = {
val port = 8000 + (i - 1) * 3
val name = "testserver" + i
new TestServer(TestServerConfig(name, port)) with TestServerFacts {
val enum = i
val nsDatabaseName = "gizzard_test_"+name+"_ns"
val databaseName = "gizzard_test_"+name
val basePort = port
val injectorPort = port + 1
val managerPort = port + 2
val sqlShardInfos = shards.ShardInfo(shards.ShardId("localhost", "t0_1"),
"TestShard", "int", "int", shards.Busy.Normal) ::
shards.ShardInfo(shards.ShardId("localhost", "t0_2"),
"TestShard", "int", "int", shards.Busy.Normal) ::
shards.ShardInfo(shards.ShardId("localhost", "t0_3"),
"TestShard", "int", "int", shards.Busy.Normal) :: Nil
val replicatingShardInfo = shards.ShardInfo(shards.ShardId("localhost", "replicating_0"),
"com.twitter.gizzard.shards.ReplicatingShard", "", "", shards.Busy.Normal)
val forwarding = nameserver.Forwarding(0, 0, replicatingShardInfo.id)
val kestrelQueues = Seq("gizzard_test_"+name+"_high_queue",
"gizzard_test_"+name+"_high_queue_errors",
"gizzard_test_"+name+"_low_queue",
"gizzard_test_"+name+"_low_queue_errors")
}
}
type WithFacts = TestServer with TestServerFacts
def testServerDBs(servers: WithFacts*) = {
servers.flatMap(s => List(
"gizzard_test_testserver" + s.enum + "_ns",
"gizzard_test_testserver" + s.enum))
}
def dropTestServerDBs(s: WithFacts*) = testServerDBs(s: _*).foreach { db =>
evaluator.execute("drop database if exists " + db)
}
def createTestServerDBs(s: WithFacts*) = testServerDBs(s: _*).foreach { db =>
evaluator.execute("create database if not exists " + db)
}
def resetTestServerDBs(s: WithFacts*) {
dropTestServerDBs(s: _*)
createTestServerDBs(s: _*)
}
def testServerClient(s: WithFacts) = {
val i = s.enum
val port = 8000 + (i - 1) * 3
new PooledClient[testserver.thrift.TestServer.Iface] {
val name = "testclient" + i
def createConnection =
new ThriftConnection[testserver.thrift.TestServer.Client]("localhost", port, true)
}.proxy
}
def setupServers(servers: WithFacts*) {
servers.foreach { s =>
createTestServerDBs(s)
s.nameServer.rebuildSchema()
s.nameServer.setForwarding(s.forwarding)
s.nameServer.createShard(s.replicatingShardInfo)
s.sqlShardInfos.foreach(s.nameServer.createShard(_))
s.sqlShardInfos.foreach(info => s.nameServer.addLink(s.replicatingShardInfo.id, info.id, 1))
s.nameServer.reload()
}
}
def startServers(servers: TestServer*) {
servers.foreach(_.start())
Thread.sleep(100)
}
def stopServers(servers: TestServer*) {
servers.foreach(_.shutdown(true))
Thread.sleep(100)
}
}