generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util_test.go
47 lines (37 loc) · 1021 Bytes
/
util_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
package traft
import (
fmt "fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_serveCluster(t *testing.T) {
ta := require.New(t)
ids := []int64{1, 2, 3}
ts := newCluster(ids)
defer stopAll(ts)
for i, tr := range ts {
// 110 101 011
ta.Equal([]uint64{3, 5, 6}, tr.Config.Quorums)
fmt.Println("===", tr.Config.Members)
fmt.Println("---", tr.Config.SortedReplicaInfos())
ta.Equal([]*ReplicaInfo{
&ReplicaInfo{Id: 1, Addr: ":5501", Position: 0},
&ReplicaInfo{Id: 2, Addr: ":5502", Position: 1},
&ReplicaInfo{Id: 3, Addr: ":5503", Position: 2},
}, tr.Config.SortedReplicaInfos())
ta.Equal(int64(0), tr.LogOffset)
ta.Equal([]*LogRecord{}, tr.Logs)
ta.Equal(ids[i], tr.Id)
for _, id := range ids {
st := tr.Status[id]
ta.Equal(&ReplicaStatus{
// voted for ones self at first.
VotedFor: &LeaderId{Term: 0, Id: id},
Committer: nil,
Accepted: NewTailBitmap(0),
Committed: NewTailBitmap(0),
Applied: NewTailBitmap(0),
}, st)
}
}
}