-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathketama_test.go
executable file
·61 lines (56 loc) · 1.58 KB
/
ketama_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"io/ioutil"
"os"
"testing"
)
func TestReloadRing(t *testing.T) {
var stringToHash map[string]string = map[string]string{
"Google.com": "",
"Youtube.com": "",
"Facebook.com": "",
"Wikipedia.org": "",
"Yahoo.com": "",
"Amazon.com": "",
"Pages.tmall.com": "",
"Reddit.com": "",
"Live.com": "",
"Netflix.com": "",
"Blogspot.com": "",
"Office.com": "",
"Instagram.com": "",
"Yahoo.co.jp": "",
"Bing.com": "",
"Microsoft.com": "",
"Google.com.hk": "",
"Stackoverflow.com": "",
"Babytree.com": "",
"Twitter.com": "",
"Ebay.com": "",
"Amazon.co.jp": "",
"Twitch.tv": "",
"Apple.com": "",
"Google.co.in": "",
"Microsoftonline.com": "",
"Msn.com": "",
"Wordpress.com": "",
}
hashToServerFile, err := ioutil.TempFile(os.TempDir(), "ketama.ring")
if err != nil {
t.Error(err)
return
}
servers := getServers()
ketama := createRingFromServers(servers)
segmentId := persist(hashToServerFile.Name(), ketama)
for siteName := range stringToHash {
stringToHash[siteName] = ketama.getServerForString(siteName)
}
ketama = recreateKetama(hashToServerFile.Name(), segmentId)
for siteName, resultOne := range stringToHash {
resultTwo := ketama.getServerForString(siteName)
if resultOne != resultTwo {
t.Errorf("recreated Ring not returning expected server, expected %s, received %s", resultOne, resultTwo)
}
}
}