Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vadiminshakov committed Oct 13, 2024
1 parent f0abb56 commit 16a3c20
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func TestLoadIndexMsg(t *testing.T) {
require.NoError(t, log.Set(uint64(i), "key"+strconv.Itoa(i), []byte("value"+strconv.Itoa(i))))
}

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

index, err := loadIndexes(log.log, stat)
index, err := loadIndexes(log.log)
require.NoError(t, err)

for i := 0; i < 10; i++ {
Expand All @@ -88,35 +85,32 @@ func TestLoadIndexMsg(t *testing.T) {
}

func TestSegmentRotationForMsgs(t *testing.T) {
segmentThreshold := 10
segmentThreshold := 5
segmentsNumber := 2

log, err := NewWAL(Config{
Dir: "./testlogdata",
Prefix: "log_",
SegmentThreshold: segmentThreshold,
MaxSegments: 5,
MaxSegments: segmentsNumber,
IsInSyncDiskMode: false,
})
require.NoError(t, err)

segmentsNumber := 6
// 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 log
for i := 0; i < segmentThreshold*segmentsNumber+10; i++ {
for i := 0; i < segmentThreshold*segmentsNumber+8; i++ {
require.NoError(t, log.Set(uint64(i), "key"+strconv.Itoa(i), []byte("value"+strconv.Itoa(i))))
}

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

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

// check all saved log in the index
// we have all log with height greater than segmentThreshold and less than segmentThreshold+(tmpIndexBufferThreshold+10)
for i := segmentThreshold * segmentsNumber; i < segmentThreshold*segmentsNumber+10; i++ {
for i := segmentThreshold * segmentsNumber; i < segmentThreshold*segmentsNumber+8; 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 Down

0 comments on commit 16a3c20

Please sign in to comment.