498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package writebuffer
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/samber/lo"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v3/msgpb"
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/paramtable"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/tsoutil"
|
|
)
|
|
|
|
type DeltaBufferSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *DeltaBufferSuite) TestBuffer() {
|
|
s.Run("int64_pk", func() {
|
|
deltaBuffer := NewDeltaBuffer()
|
|
|
|
tss := lo.RepeatBy(100, func(idx int) uint64 { return tsoutil.ComposeTSByTimeWithLogical(time.Now(), int64(idx)) })
|
|
pks := lo.Map(tss, func(ts uint64, _ int) storage.PrimaryKey { return storage.NewInt64PrimaryKey(int64(ts)) })
|
|
|
|
memSize := deltaBuffer.Buffer(pks, tss, &msgpb.MsgPosition{Timestamp: 100}, &msgpb.MsgPosition{Timestamp: 200})
|
|
// 24 = 16(pk) + 8(ts)
|
|
s.EqualValues(100*24, memSize)
|
|
})
|
|
|
|
s.Run("string_pk", func() {
|
|
deltaBuffer := NewDeltaBuffer()
|
|
|
|
tss := lo.RepeatBy(100, func(idx int) uint64 { return tsoutil.ComposeTSByTimeWithLogical(time.Now(), int64(idx)) })
|
|
pks := lo.Map(tss, func(ts uint64, idx int) storage.PrimaryKey {
|
|
return storage.NewVarCharPrimaryKey(fmt.Sprintf("%03d", idx))
|
|
})
|
|
|
|
memSize := deltaBuffer.Buffer(pks, tss, &msgpb.MsgPosition{Timestamp: 100}, &msgpb.MsgPosition{Timestamp: 200})
|
|
// 19 = (3+8)(string pk) + 8(ts)
|
|
s.EqualValues(100*19, memSize)
|
|
})
|
|
}
|
|
|
|
func (s *DeltaBufferSuite) TestYield() {
|
|
deltaBuffer := NewDeltaBuffer()
|
|
|
|
result := deltaBuffer.Yield()
|
|
s.Nil(result)
|
|
|
|
deltaBuffer = NewDeltaBuffer()
|
|
|
|
tss := lo.RepeatBy(100, func(idx int) uint64 { return tsoutil.ComposeTSByTimeWithLogical(time.Now(), int64(idx)) })
|
|
pks := lo.Map(tss, func(ts uint64, _ int) storage.PrimaryKey { return storage.NewInt64PrimaryKey(int64(ts)) })
|
|
|
|
deltaBuffer.Buffer(pks, tss, &msgpb.MsgPosition{Timestamp: 100}, &msgpb.MsgPosition{Timestamp: 200})
|
|
|
|
result = deltaBuffer.Yield()
|
|
s.NotNil(result)
|
|
|
|
s.ElementsMatch(tss, result.Tss)
|
|
s.ElementsMatch(pks, result.Pks)
|
|
}
|
|
|
|
func (s *DeltaBufferSuite) SetupSuite() {
|
|
paramtable.Init()
|
|
}
|
|
|
|
func TestDeltaBuffer(t *testing.T) {
|
|
suite.Run(t, new(DeltaBufferSuite))
|
|
}
|