generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clusterconfig_test.go
74 lines (61 loc) · 1.17 KB
/
clusterconfig_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
package traft
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestClusterConfig_SortedReplicaInfos(t *testing.T) {
ta := require.New(t)
cc := &Cluster{
Members: map[int64]*ReplicaInfo{
1: {1, "111", 0},
2: {2, "222", 2},
3: {3, "333", 4},
},
}
sorted := cc.SortedReplicaInfos()
cases := []struct {
input int64
want *ReplicaInfo
}{
{0, &ReplicaInfo{1, "111", 0}},
{1, nil},
{2, &ReplicaInfo{2, "222", 2}},
{3, nil},
{4, &ReplicaInfo{3, "333", 4}},
}
for i, c := range cases {
got := sorted[c.input]
ta.Equal(c.want, got, "%d-th: case: %+v", i+1, c)
}
}
func TestClusterConfig_IsQuorum(t *testing.T) {
ta := require.New(t)
cc := &Cluster{
Members: map[int64]*ReplicaInfo{
1: {1, "111", 0},
2: {2, "222", 2},
3: {3, "333", 4},
},
}
// quorums are:
// 10100
// 00101
// 10001
cc.Quorums = buildMajorityQuorums(1 | 4 | 16)
cases := []struct {
input uint64
want bool
}{
{1, false},
{4, false},
{16, false},
{1 | 4, true},
{4 | 16, true},
{1 | 16, true},
{1 | 4 | 16, true},
}
for i, c := range cases {
got := cc.IsQuorum(c.input)
ta.Equal(c.want, got, "%d-th: case: %+v", i+1, c)
}
}