-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer_test.go
45 lines (39 loc) · 897 Bytes
/
peer_test.go
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
package cache
import (
"flag"
"fmt"
"log"
"testing"
)
func createGroup() *Group {
return NewGroup("score", 2<<10, GetterFunc(
func(key string) ([]byte, error) {
log.Println("[SlowDB] search key", key)
if v, ok := db[key]; ok {
return []byte(v), nil
}
return nil, fmt.Errorf("%s not exist", key)
}))
}
func TestPeer(t *testing.T) {
var port int
var api bool
flag.IntVar(&port, "port", 8001, "MiniCache server port")
flag.BoolVar(&api, "api", false, "Start a api server?")
flag.Parse()
apiAddr := "http://localhost:9999"
addrMap := map[int]string{
8001: "http://localhost:8001",
8002: "http://localhost:8002",
8003: "http://localhost:8003",
}
var addrs []string
for _, v := range addrMap {
addrs = append(addrs, v)
}
group := createGroup()
if api {
go startAPIServer(apiAddr, group)
}
startCacheServer(addrMap[port], []string(addrs), group)
}