Merge pull request #5869 from gyuho/raft_log_test

raft: minor updates and clean up in log.go
This commit is contained in:
Gyu-Ho Lee 2016-07-04 21:51:13 -07:00 committed by GitHub
commit c7dd74d8d3
2 changed files with 2 additions and 3 deletions

View File

@ -74,8 +74,8 @@ func (l *raftLog) String() string {
// maybeAppend returns (0, false) if the entries cannot be appended. Otherwise, // maybeAppend returns (0, false) if the entries cannot be appended. Otherwise,
// it returns (last index of new entries, true). // it returns (last index of new entries, true).
func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) { func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) {
lastnewi = index + uint64(len(ents))
if l.matchTerm(index, logTerm) { if l.matchTerm(index, logTerm) {
lastnewi = index + uint64(len(ents))
ci := l.findConflict(ents) ci := l.findConflict(ents)
switch { switch {
case ci == 0: case ci == 0:

View File

@ -29,7 +29,6 @@ func TestFindConflict(t *testing.T) {
}{ }{
// no conflict, empty ent // no conflict, empty ent
{[]pb.Entry{}, 0}, {[]pb.Entry{}, 0},
{[]pb.Entry{}, 0},
// no conflict // no conflict
{[]pb.Entry{{Index: 1, Term: 1}, {Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0}, {[]pb.Entry{{Index: 1, Term: 1}, {Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0},
{[]pb.Entry{{Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0}, {[]pb.Entry{{Index: 2, Term: 2}, {Index: 3, Term: 3}}, 0},
@ -73,7 +72,7 @@ func TestIsUpToDate(t *testing.T) {
{raftLog.lastIndex() - 1, 2, false}, {raftLog.lastIndex() - 1, 2, false},
{raftLog.lastIndex(), 2, false}, {raftLog.lastIndex(), 2, false},
{raftLog.lastIndex() + 1, 2, false}, {raftLog.lastIndex() + 1, 2, false},
// equal term, lager lastIndex wins // equal term, equal or lager lastIndex wins
{raftLog.lastIndex() - 1, 3, false}, {raftLog.lastIndex() - 1, 3, false},
{raftLog.lastIndex(), 3, true}, {raftLog.lastIndex(), 3, true},
{raftLog.lastIndex() + 1, 3, true}, {raftLog.lastIndex() + 1, 3, true},