Permalink
Browse files

Fixed some minor issues reported by static checks.

  • Loading branch information...
lni committed Jan 5, 2019
1 parent dda33e8 commit 44ae12bb82c15c958222f112d00595cb1581a8f4
@@ -1089,7 +1089,7 @@ func getRequestAddress(ctx context.Context,
readNodeIdx := rand.Int() % len(ci.RPCAddresses)
writeNodeIdx := rand.Int() % len(ci.RPCAddresses)
nodeIDList := make([]uint64, 0)
for nodeID, _ := range ci.RPCAddresses {
for nodeID := range ci.RPCAddresses {
nodeIDList = append(nodeIDList, nodeID)
}
for nodeID, addr := range ci.RPCAddresses {
@@ -175,7 +175,7 @@ func TestCompactBatchFieldsPanicWhenBatchIsTooSmall(t *testing.T) {
compactBatchFields(eb)
}
f(pb.EntryBatch{})
f(pb.EntryBatch{Entries: []pb.Entry{pb.Entry{}}})
f(pb.EntryBatch{Entries: []pb.Entry{{}}})
}

func TestRestoreBatchFieldsPanicWhenBatchIsTooSmall(t *testing.T) {
@@ -188,12 +188,12 @@ func TestRestoreBatchFieldsPanicWhenBatchIsTooSmall(t *testing.T) {
restoreBatchFields(eb)
}
f(pb.EntryBatch{})
f(pb.EntryBatch{Entries: []pb.Entry{pb.Entry{}}})
f(pb.EntryBatch{Entries: []pb.Entry{{}}})
}

func TestMergeFirstBatchPanicWhenInputBatchIsEmpty(t *testing.T) {
empty := pb.EntryBatch{}
nonEmpty := pb.EntryBatch{Entries: []pb.Entry{pb.Entry{Index: 1, Term: 1}}}
nonEmpty := pb.EntryBatch{Entries: []pb.Entry{{Index: 1, Term: 1}}}
f := func(eb pb.EntryBatch, lb pb.EntryBatch) {
defer func() {
if r := recover(); r == nil {
@@ -207,8 +207,8 @@ func TestMergeFirstBatchPanicWhenInputBatchIsEmpty(t *testing.T) {
}

func TestMergeFirstBatchPanicWhenIncomingBatchIsNotMoreRecent(t *testing.T) {
eb := pb.EntryBatch{Entries: []pb.Entry{pb.Entry{Index: batchSize, Term: 1}}}
lb := pb.EntryBatch{Entries: []pb.Entry{pb.Entry{Index: 2 * batchSize, Term: 1}}}
eb := pb.EntryBatch{Entries: []pb.Entry{{Index: batchSize, Term: 1}}}
lb := pb.EntryBatch{Entries: []pb.Entry{{Index: 2 * batchSize, Term: 1}}}
defer func() {
if r := recover(); r == nil {
t.Errorf("panic not triggered")
@@ -218,8 +218,8 @@ func TestMergeFirstBatchPanicWhenIncomingBatchIsNotMoreRecent(t *testing.T) {
}

func TestIncomingBatchIsTheMergedBatchWhenMoreRecentThanLastBatch(t *testing.T) {
eb := pb.EntryBatch{Entries: []pb.Entry{pb.Entry{Index: 2 * batchSize, Term: 1}}}
lb := pb.EntryBatch{Entries: []pb.Entry{pb.Entry{Index: batchSize, Term: 1}}}
eb := pb.EntryBatch{Entries: []pb.Entry{{Index: 2 * batchSize, Term: 1}}}
lb := pb.EntryBatch{Entries: []pb.Entry{{Index: batchSize, Term: 1}}}
result := getMergedFirstBatch(eb, lb)
if !reflect.DeepEqual(&result, &eb) {
t.Errorf("unexpected result")
@@ -29,8 +29,8 @@ func TestMergeOperator(t *testing.T) {
wo := NewDefaultWriteOptions()
ensure.Nil(t, db.Put(wo, givenKey, givenVal1))
ensure.Nil(t, db.Merge(wo, givenKey, givenVal2))
// trigger a compaction to ensure that a merge is performed

// trigger a compaction to ensure that a merge is performed
db.CompactRange(Range{nil, nil})

ro := NewDefaultReadOptions()
@@ -555,7 +555,7 @@ func TestRLLTIsOutOfBounds(t *testing.T) {
l := raft.NewLog(stable)

for i := uint64(1); i <= num; i++ {
l.Append([]pb.Entry{pb.Entry{Index: i + offset}})
l.Append([]pb.Entry{{Index: i + offset}})
}

first := offset + 1
@@ -641,7 +641,7 @@ func TestRLLTTerm(t *testing.T) {
stable.ApplySnapshot(pb.Snapshot{Index: offset, Term: 1})
l := raft.NewLog(stable)
for i = 1; i < num; i++ {
l.Append([]pb.Entry{pb.Entry{Index: offset + i, Term: i}})
l.Append([]pb.Entry{{Index: offset + i, Term: i}})
}

tests := []struct {
@@ -693,7 +693,7 @@ func TestRLLTSlice(t *testing.T) {
}
l := raft.NewLog(stable)
for i = num / 2; i < num; i++ {
l.Append([]pb.Entry{pb.Entry{Index: offset + i, Term: offset + i}})
l.Append([]pb.Entry{{Index: offset + i, Term: offset + i}})
}

tests := []struct {
@@ -139,7 +139,7 @@ func TestBootstrapInfoCanBeSavedAndChecked(t *testing.T) {
func TestSnapshotHasMaxIndexSet(t *testing.T) {
tf := func(t *testing.T, db raftio.ILogDB) {
ud1 := pb.Update{
EntriesToSave: []pb.Entry{pb.Entry{Index: 2}, pb.Entry{Index: 3}, pb.Entry{Index: 4}},
EntriesToSave: []pb.Entry{{Index: 2}, {Index: 3}, {Index: 4}},
ClusterID: 3,
NodeID: 4,
}
@@ -178,7 +178,7 @@ func TestSnapshotHasMaxIndexSet(t *testing.T) {
func TestSaveSnapshotTogetherWithUnexpectedEntriesWillPanic(t *testing.T) {
tf := func(t *testing.T, db raftio.ILogDB) {
ud1 := pb.Update{
EntriesToSave: []pb.Entry{pb.Entry{Index: 2}, pb.Entry{Index: 3}, pb.Entry{Index: 4}},
EntriesToSave: []pb.Entry{{Index: 2}, {Index: 3}, {Index: 4}},
ClusterID: 3,
NodeID: 4,
Snapshot: pb.Snapshot{Index: 5},
@@ -39,11 +39,11 @@ func TestLimitSizeOnEmptyEntryList(t *testing.T) {
func TestCheckEntriesToAppend(t *testing.T) {
checkEntriesToAppend(nil, nil)
checkEntriesToAppend([]pb.Entry{}, []pb.Entry{})
checkEntriesToAppend(nil, []pb.Entry{pb.Entry{Index: 101}})
checkEntriesToAppend([]pb.Entry{pb.Entry{Index: 100}},
[]pb.Entry{pb.Entry{Index: 101}})
checkEntriesToAppend([]pb.Entry{pb.Entry{Index: 100, Term: 90}},
[]pb.Entry{pb.Entry{Index: 101, Term: 100}})
checkEntriesToAppend(nil, []pb.Entry{{Index: 101}})
checkEntriesToAppend([]pb.Entry{{Index: 100}},
[]pb.Entry{{Index: 101}})
checkEntriesToAppend([]pb.Entry{{Index: 100, Term: 90}},
[]pb.Entry{{Index: 101, Term: 100}})
}

func TestCheckEntriesToAppendWillPanicWhenIndexHasHole(t *testing.T) {
@@ -53,7 +53,7 @@ func TestCheckEntriesToAppendWillPanicWhenIndexHasHole(t *testing.T) {
}
t.Errorf("not panic")
}()
checkEntriesToAppend([]pb.Entry{pb.Entry{Index: 100}}, []pb.Entry{pb.Entry{Index: 102}})
checkEntriesToAppend([]pb.Entry{{Index: 100}}, []pb.Entry{{Index: 102}})
}

func TestCheckEntriesToAppendWillPanicWhenTermMovesBack(t *testing.T) {
@@ -63,6 +63,6 @@ func TestCheckEntriesToAppendWillPanicWhenTermMovesBack(t *testing.T) {
}
t.Errorf("not panic")
}()
checkEntriesToAppend([]pb.Entry{pb.Entry{Index: 100, Term: 100}},
[]pb.Entry{pb.Entry{Index: 101, Term: 99}})
checkEntriesToAppend([]pb.Entry{{Index: 100, Term: 100}},
[]pb.Entry{{Index: 101, Term: 99}})
}
@@ -25,8 +25,8 @@ func TestInMemCheckMarkerIndex(t *testing.T) {
im.checkMarkerIndex()
im = inMemory{
entries: []pb.Entry{
pb.Entry{Index: 1, Term: 2},
pb.Entry{Index: 2, Term: 2},
{Index: 1, Term: 2},
{Index: 2, Term: 2},
},
markerIndex: 1,
}
@@ -42,8 +42,8 @@ func TestInMemCheckMarkerIndexPanicOnInvalidInMem(t *testing.T) {
}()
im := inMemory{
entries: []pb.Entry{
pb.Entry{Index: 1, Term: 2},
pb.Entry{Index: 2, Term: 2},
{Index: 1, Term: 2},
{Index: 2, Term: 2},
},
markerIndex: 2,
}
@@ -105,8 +105,8 @@ func TestInMemGetEntries(t *testing.T) {
im := &inMemory{
markerIndex: 2,
entries: []pb.Entry{
pb.Entry{Index: 2, Term: 2},
pb.Entry{Index: 3, Term: 2},
{Index: 2, Term: 2},
{Index: 3, Term: 2},
},
}
ents := im.getEntries(2, 3)
@@ -225,8 +225,8 @@ func TestInMemRestore(t *testing.T) {
im := inMemory{
markerIndex: 10,
entries: []pb.Entry{
pb.Entry{Index: 10, Term: 1},
pb.Entry{Index: 11, Term: 1},
{Index: 10, Term: 1},
{Index: 11, Term: 1},
},
}
ss := pb.Snapshot{Index: 100}
@@ -256,14 +256,14 @@ func TestInMemMergeFullAppend(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
}
ents := []pb.Entry{
pb.Entry{Index: 8, Term: 8},
pb.Entry{Index: 9, Term: 9},
{Index: 8, Term: 8},
{Index: 9, Term: 9},
}
im.merge(ents)
if len(im.entries) != 5 || im.markerIndex != 5 {
@@ -278,14 +278,14 @@ func TestInMemMergeReplace(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
}
ents := []pb.Entry{
pb.Entry{Index: 2, Term: 2},
pb.Entry{Index: 3, Term: 3},
{Index: 2, Term: 2},
{Index: 3, Term: 3},
}
im.merge(ents)
if len(im.entries) != 2 || im.markerIndex != 2 {
@@ -306,14 +306,14 @@ func TestInMemMergeWithHoleCausePanic(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
}
ents := []pb.Entry{
pb.Entry{Index: 9, Term: 9},
pb.Entry{Index: 10, Term: 10},
{Index: 9, Term: 9},
{Index: 10, Term: 10},
}
im.merge(ents)
}
@@ -322,14 +322,14 @@ func TestInMemMerge(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
}
ents := []pb.Entry{
pb.Entry{Index: 6, Term: 7},
pb.Entry{Index: 7, Term: 10},
{Index: 6, Term: 7},
{Index: 7, Term: 10},
}
im.merge(ents)
if len(im.entries) != 3 || im.markerIndex != 5 {
@@ -350,9 +350,9 @@ func TestInMemEntriesToSaveReturnNotStabledEntries(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
}
im.savedTo = 4
@@ -395,9 +395,9 @@ func TestInMemSaveLogToUpdatesStableTo(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
savedTo: 4,
}
@@ -413,7 +413,7 @@ func TestInMemSetStableToWhenRestoringSnapshot(t *testing.T) {
im := inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
{Index: 5, Term: 5},
},
savedTo: 4,
}
@@ -427,8 +427,8 @@ func TestInMemMergeSetStableTo(t *testing.T) {
im := inMemory{
markerIndex: 6,
entries: []pb.Entry{
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
savedTo: 5,
}
@@ -440,12 +440,12 @@ func TestInMemMergeSetStableTo(t *testing.T) {
im = inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
pb.Entry{Index: 8, Term: 8},
pb.Entry{Index: 9, Term: 9},
pb.Entry{Index: 10, Term: 10},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
{Index: 8, Term: 8},
{Index: 9, Term: 9},
{Index: 10, Term: 10},
},
savedTo: 4,
}
@@ -456,12 +456,12 @@ func TestInMemMergeSetStableTo(t *testing.T) {
im = inMemory{
markerIndex: 5,
entries: []pb.Entry{
pb.Entry{Index: 5, Term: 5},
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
pb.Entry{Index: 8, Term: 8},
pb.Entry{Index: 9, Term: 9},
pb.Entry{Index: 10, Term: 10},
{Index: 5, Term: 5},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
{Index: 8, Term: 8},
{Index: 9, Term: 9},
{Index: 10, Term: 10},
},
savedTo: 6,
}
@@ -472,8 +472,8 @@ func TestInMemMergeSetStableTo(t *testing.T) {
im = inMemory{
markerIndex: 6,
entries: []pb.Entry{
pb.Entry{Index: 6, Term: 6},
pb.Entry{Index: 7, Term: 7},
{Index: 6, Term: 6},
{Index: 7, Term: 7},
},
savedTo: 5,
}
Oops, something went wrong.

0 comments on commit 44ae12b

Please sign in to comment.