Skip to content

Commit

Permalink
more accurate segment repair testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vadiminshakov committed Sep 18, 2023
1 parent 4dbab08 commit 71a185f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions voteslog/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ func TestSegmentRotationForMsgs(t *testing.T) {
log, err := NewOnDiskLog("./testlogdata")
require.NoError(t, err)

for i := 0; i < 49; i++ {
// here we exceed the segment size threshold (segmentThreshold), create new segment, keep old segment on disk until tmpIndexBufferThreshold
// is reached, then del old segment and write 10 more msgs
for i := 0; i < segmentThreshold+(tmpIndexBufferThreshold+10); i++ {
require.NoError(t, log.Set(uint64(i), "key"+strconv.Itoa(i), []byte("value"+strconv.Itoa(i))))
}

stat, err := log.msgs.Stat()
require.NoError(t, err)

// now we have only one segment on disk with tmpIndexBufferThreshold+10 msgs,
// load it in the memory
index, err := loadIndexesMsg(log.msgs, stat)
require.NoError(t, err)

for i := 41; i < 49; i++ {
// check all saved msgs in the index
// we have all msgs with height greater than segmentThreshold and less than segmentThreshold+(tmpIndexBufferThreshold+10)
for i := segmentThreshold; i < segmentThreshold+(tmpIndexBufferThreshold+10); i++ {
require.Equal(t, "key"+strconv.Itoa(i), index[uint64(i)].Key)
require.Equal(t, "value"+strconv.Itoa(i), string(index[uint64(i)].Value))
}
Expand All @@ -75,7 +81,7 @@ func TestServiceDownUpAndRepairIndex(t *testing.T) {
log, err := NewOnDiskLog("./testlogdata")
require.NoError(t, err)

for i := 0; i < 26; i++ {
for i := 0; i < segmentThreshold+(tmpIndexBufferThreshold/2); i++ {
require.NoError(t, log.Set(uint64(i), "key"+strconv.Itoa(i), []byte("value"+strconv.Itoa(i))))
require.NoError(t, log.SetVotes(uint64(i), []*entity.Vote{{"node" + strconv.Itoa(i), true}}))
}
Expand All @@ -85,7 +91,7 @@ func TestServiceDownUpAndRepairIndex(t *testing.T) {
log, err = NewOnDiskLog("./testlogdata")
require.NoError(t, err)

for i := 0; i < 26; i++ {
for i := 0; i < segmentThreshold+(tmpIndexBufferThreshold/2); i++ {
require.Equal(t, "key"+strconv.Itoa(i), log.indexMsgs[uint64(i)].Key)
require.Equal(t, "value"+strconv.Itoa(i), string(log.indexMsgs[uint64(i)].Value))
require.Equal(t, entity.Vote{"node" + strconv.Itoa(i), true}, *log.indexVotes[uint64(i)].Votes[0])
Expand Down

0 comments on commit 71a185f

Please sign in to comment.