2023-10-31 02:30:16 +08:00
|
|
|
package syncmgr
|
|
|
|
|
|
|
|
import (
|
2024-06-25 14:22:04 +08:00
|
|
|
"context"
|
2023-10-31 02:30:16 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/cockroachdb/errors"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/datanode/broker"
|
2024-07-22 11:33:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/flushcommon/metacache"
|
2023-10-31 02:30:16 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/retry"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MetaWriterSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
broker *broker.MockBroker
|
|
|
|
metacache *metacache.MockMetaCache
|
|
|
|
|
|
|
|
writer MetaWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MetaWriterSuite) SetupSuite() {
|
|
|
|
paramtable.Get().Init(paramtable.NewBaseTable())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MetaWriterSuite) SetupTest() {
|
|
|
|
s.broker = broker.NewMockBroker(s.T())
|
|
|
|
s.metacache = metacache.NewMockMetaCache(s.T())
|
2024-02-21 11:54:53 +08:00
|
|
|
s.writer = BrokerMetaWriter(s.broker, 1, retry.Attempts(1))
|
2023-10-31 02:30:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MetaWriterSuite) TestNormalSave() {
|
2024-06-25 14:22:04 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-10-31 02:30:16 +08:00
|
|
|
s.broker.EXPECT().SaveBinlogPaths(mock.Anything, mock.Anything).Return(nil)
|
|
|
|
|
|
|
|
bfs := metacache.NewBloomFilterSet()
|
|
|
|
seg := metacache.NewSegmentInfo(&datapb.SegmentInfo{}, bfs)
|
|
|
|
metacache.UpdateNumOfRows(1000)(seg)
|
2024-05-28 14:19:42 +08:00
|
|
|
s.metacache.EXPECT().GetSegmentsBy(mock.Anything, mock.Anything).Return([]*metacache.SegmentInfo{seg})
|
2023-12-26 10:40:47 +08:00
|
|
|
s.metacache.EXPECT().GetSegmentByID(mock.Anything).Return(seg, true)
|
2023-11-17 21:46:20 +08:00
|
|
|
s.metacache.EXPECT().UpdateSegments(mock.Anything, mock.Anything).Return()
|
2023-10-31 02:30:16 +08:00
|
|
|
task := NewSyncTask()
|
|
|
|
task.WithMetaCache(s.metacache)
|
2024-06-25 14:22:04 +08:00
|
|
|
err := s.writer.UpdateSync(ctx, task)
|
2023-10-31 02:30:16 +08:00
|
|
|
s.NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MetaWriterSuite) TestReturnError() {
|
2024-06-25 14:22:04 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-10-31 02:30:16 +08:00
|
|
|
s.broker.EXPECT().SaveBinlogPaths(mock.Anything, mock.Anything).Return(errors.New("mocked"))
|
|
|
|
|
|
|
|
bfs := metacache.NewBloomFilterSet()
|
|
|
|
seg := metacache.NewSegmentInfo(&datapb.SegmentInfo{}, bfs)
|
|
|
|
metacache.UpdateNumOfRows(1000)(seg)
|
2023-12-26 10:40:47 +08:00
|
|
|
s.metacache.EXPECT().GetSegmentByID(mock.Anything).Return(seg, true)
|
2024-05-28 14:19:42 +08:00
|
|
|
s.metacache.EXPECT().GetSegmentsBy(mock.Anything, mock.Anything).Return([]*metacache.SegmentInfo{seg})
|
2023-10-31 02:30:16 +08:00
|
|
|
task := NewSyncTask()
|
|
|
|
task.WithMetaCache(s.metacache)
|
2024-06-25 14:22:04 +08:00
|
|
|
err := s.writer.UpdateSync(ctx, task)
|
2023-10-31 02:30:16 +08:00
|
|
|
s.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaWriter(t *testing.T) {
|
|
|
|
suite.Run(t, new(MetaWriterSuite))
|
|
|
|
}
|