@@ -1002,13 +1002,10 @@ func TestCandidateConcede(t *testing.T) {
10021002 if g := a .Term ; g != 1 {
10031003 t .Errorf ("term = %d, want %d" , g , 1 )
10041004 }
1005- wantLog := ltoa (& raftLog {
1006- storage : & MemoryStorage {
1007- ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Index : 2 , Data : data }},
1008- },
1009- unstable : unstable {offset : 3 },
1010- committed : 2 ,
1011- })
1005+
1006+ wantLog := ltoa (newLog (& MemoryStorage {
1007+ ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Index : 2 , Data : data }},
1008+ }, nil ))
10121009 for i , p := range tt .peers {
10131010 if sm , ok := p .(* raft ); ok {
10141011 l := ltoa (sm .raftLog )
@@ -1052,17 +1049,13 @@ func TestOldMessages(t *testing.T) {
10521049 // commit a new entry
10531050 tt .send (pb.Message {From : 1 , To : 1 , Type : pb .MsgProp , Entries : []pb.Entry {{Data : []byte ("somedata" )}}})
10541051
1055- ilog := & raftLog {
1056- storage : & MemoryStorage {
1057- ents : []pb.Entry {
1058- {}, {Data : nil , Term : 1 , Index : 1 },
1059- {Data : nil , Term : 2 , Index : 2 }, {Data : nil , Term : 3 , Index : 3 },
1060- {Data : []byte ("somedata" ), Term : 3 , Index : 4 },
1061- },
1052+ ilog := newLog (& MemoryStorage {
1053+ ents : []pb.Entry {
1054+ {}, {Data : nil , Term : 1 , Index : 1 },
1055+ {Data : nil , Term : 2 , Index : 2 }, {Data : nil , Term : 3 , Index : 3 },
1056+ {Data : []byte ("somedata" ), Term : 3 , Index : 4 },
10621057 },
1063- unstable : unstable {offset : 5 },
1064- committed : 4 ,
1065- }
1058+ }, nil )
10661059 base := ltoa (ilog )
10671060 for i , p := range tt .peers {
10681061 if sm , ok := p .(* raft ); ok {
@@ -1113,12 +1106,9 @@ func TestProposal(t *testing.T) {
11131106
11141107 wantLog := newLog (NewMemoryStorage (), raftLogger )
11151108 if tt .success {
1116- wantLog = & raftLog {
1117- storage : & MemoryStorage {
1118- ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Index : 2 , Data : data }},
1119- },
1120- unstable : unstable {offset : 3 },
1121- }
1109+ wantLog = newLog (& MemoryStorage {
1110+ ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Index : 2 , Data : data }},
1111+ }, nil )
11221112 }
11231113 base := ltoa (wantLog )
11241114 for i , p := range tt .peers {
@@ -1151,12 +1141,9 @@ func TestProposalByProxy(t *testing.T) {
11511141 // propose via follower
11521142 tt .send (pb.Message {From : 2 , To : 2 , Type : pb .MsgProp , Entries : []pb.Entry {{Data : []byte ("somedata" )}}})
11531143
1154- wantLog := & raftLog {
1155- storage : & MemoryStorage {
1156- ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Data : data , Index : 2 }},
1157- },
1158- unstable : unstable {offset : 3 },
1159- committed : 2 }
1144+ wantLog := newLog (& MemoryStorage {
1145+ ents : []pb.Entry {{}, {Data : nil , Term : 1 , Index : 1 }, {Term : 1 , Data : data , Index : 2 }},
1146+ }, nil )
11601147 base := ltoa (wantLog )
11611148 for i , p := range tt .peers {
11621149 if sm , ok := p .(* raft ); ok {
@@ -1577,10 +1564,9 @@ func testRecvMsgVote(t *testing.T, msgType pb.MessageType) {
15771564 sm .step = stepLeader
15781565 }
15791566 sm .Vote = tt .voteFor
1580- sm .raftLog = & raftLog {
1581- storage : & MemoryStorage {ents : []pb.Entry {{}, {Index : 1 , Term : 2 }, {Index : 2 , Term : 2 }}},
1582- unstable : unstable {offset : 3 },
1583- }
1567+ sm .raftLog = newLog (& MemoryStorage {
1568+ ents : []pb.Entry {{}, {Index : 1 , Term : 2 }, {Index : 2 , Term : 2 }},
1569+ }, nil )
15841570
15851571 // raft.Term is greater than or equal to raft.raftLog.lastTerm. In this
15861572 // test we're only testing MsgVote responses when the campaigning node
@@ -2617,10 +2603,9 @@ func TestLeaderAppResp(t *testing.T) {
26172603 // sm term is 1 after it becomes the leader.
26182604 // thus the last log term must be 1 to be committed.
26192605 sm := newTestRaft (1 , 10 , 1 , newTestMemoryStorage (withPeers (1 , 2 , 3 )))
2620- sm .raftLog = & raftLog {
2621- storage : & MemoryStorage {ents : []pb.Entry {{}, {Index : 1 , Term : 1 }, {Index : 2 , Term : 1 }}},
2622- unstable : unstable {offset : 3 },
2623- }
2606+ sm .raftLog = newLog (& MemoryStorage {
2607+ ents : []pb.Entry {{}, {Index : 1 , Term : 1 }, {Index : 2 , Term : 1 }},
2608+ }, nil )
26242609 sm .becomeCandidate ()
26252610 sm .becomeLeader ()
26262611 sm .readMessages ()
@@ -2732,7 +2717,9 @@ func TestRecvMsgBeat(t *testing.T) {
27322717
27332718 for i , tt := range tests {
27342719 sm := newTestRaft (1 , 10 , 1 , newTestMemoryStorage (withPeers (1 , 2 , 3 )))
2735- sm .raftLog = & raftLog {storage : & MemoryStorage {ents : []pb.Entry {{}, {Index : 1 , Term : 1 }, {Index : 2 , Term : 1 }}}}
2720+ sm .raftLog = newLog (& MemoryStorage {
2721+ ents : []pb.Entry {{}, {Index : 1 , Term : 1 }, {Index : 2 , Term : 1 }},
2722+ }, nil )
27362723 sm .Term = 1
27372724 sm .state = tt .state
27382725 switch tt .state {
0 commit comments