milvus/internal/streamingnode/server/wal/utility/reorder_buffer_test.go
chyezh 7611128e57
enhance: wal adaptor implementation (#34122)
issue: #33285

- add adaptor to implement walimpls into wal interface.
- implement timetick sorted and filtering scanner.
- add test for wal.

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2024-07-04 15:23:08 +08:00

44 lines
1.0 KiB
Go

package utility
import (
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/pkg/mocks/streaming/util/mock_message"
)
func TestReOrderByTimeTickBuffer(t *testing.T) {
buf := NewReOrderBuffer()
timeticks := rand.Perm(25)
for i, timetick := range timeticks {
msg := mock_message.NewMockImmutableMessage(t)
msg.EXPECT().TimeTick().Return(uint64(timetick + 1))
buf.Push(msg)
assert.Equal(t, i+1, buf.Len())
}
result := buf.PopUtilTimeTick(0)
assert.Len(t, result, 0)
result = buf.PopUtilTimeTick(1)
assert.Len(t, result, 1)
for _, msg := range result {
assert.LessOrEqual(t, msg.TimeTick(), uint64(1))
}
result = buf.PopUtilTimeTick(10)
assert.Len(t, result, 9)
for _, msg := range result {
assert.LessOrEqual(t, msg.TimeTick(), uint64(10))
assert.Greater(t, msg.TimeTick(), uint64(1))
}
result = buf.PopUtilTimeTick(25)
assert.Len(t, result, 15)
for _, msg := range result {
assert.Greater(t, msg.TimeTick(), uint64(10))
assert.LessOrEqual(t, msg.TimeTick(), uint64(25))
}
}