forked from jjneely/statsrelay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jump_test.go
107 lines (97 loc) · 2.42 KB
/
jump_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
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
package main
import (
"testing"
)
var jumpHashTestNodes = []string{
"graphite010-g5",
"graphite011-g5",
"graphite012-g5",
"graphite013-g5",
"graphite014-g5",
"graphite015-g5",
"graphite016-g5",
"graphite017-g5",
"graphite018-g5",
"graphite-data019-g5",
"graphite-data020-g5",
"graphite-data021-g5",
"graphite-data022-g5",
"graphite-data023-g5",
"graphite-data024-g5",
"graphite-data025-g5",
"graphite-data026-g5",
"graphite-data027-g5",
"graphite-data028-g5",
"graphite-data029-g5",
"graphite-data030-g5",
"graphite-data031-g5",
"graphite-data032-g5",
"graphite-data033-g5",
"graphite-data034-g5",
"graphite-data035-g5",
"graphite-data036-g5",
"graphite-data037-g5",
"graphite-data038-g5",
"graphite-data039-g5",
"graphite-data040-g5",
"graphite-data041-g5",
"graphite-data042-g5",
"graphite-data043-g5",
"graphite-data044-g5",
"graphite-data045-g5",
"graphite-data046-g5",
"graphite-data047-g5",
"graphite-data048-g5",
"graphite-data049-g5",
"graphite-data050-g5",
"graphite-data051-g5",
"graphite-data052-g5",
"graphite-data053-g5",
"graphite-data054-g5",
}
func makeJumpTestCHR(r int) *JumpHashRing {
chr := NewJumpHashRing(r)
for _, v := range jumpHashTestNodes {
chr.AddNode(Node{v, ""})
}
return chr
}
func TestFNV1a64(t *testing.T) {
data := map[string]uint64{
"foobar": 0x85944171f73967e8,
"changed": 0xdf38879af614707b,
"5min.prod.dc06.graphite-web006-g6.kernel.net.netfilter.nf_conntrack_max": 0xdb7b58ef171eee9f,
}
for s, hash := range data {
if Fnv1a64([]byte(s)) != hash {
t.Errorf("FNV1a64 implementation does not match reference %s => %x",
s, Fnv1a64([]byte(s)))
}
}
}
func TestOutOfRange(t *testing.T) {
chr := makeJumpTestCHR(1)
for _, v := range jumpHashTestNodes {
k := Fnv1a64([]byte(v))
i := Jump(k, len(chr.ring))
if i < 0 || i >= len(chr.ring) {
t.Errorf("Jump hash returned out of bounds bucket %s => %d", v, i)
}
}
}
func TestJumpCHR(t *testing.T) {
chr := makeJumpTestCHR(1)
t.Logf(chr.String())
data := map[string]string{
"foobar": "graphite-data043-g5",
"suebob.foo.honey.i.shrunk.the.kids": "graphite-data048-g5",
"5min.prod.dc06.graphite-web006-g6.kernel.net.netfilter.nf_conntrack_max": "graphite014-g5",
}
for key, node := range data {
n := chr.GetNode(key)
if n.Server != node {
t.Errorf("Hash not compatible with carbon-c-relay: %s => %s Should be %s",
key, n.Server, node)
}
}
}