2021-10-15 18:07:09 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-09-08 19:12:00 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-15 18:07:09 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-08 19:12:00 +08:00
|
|
|
//
|
2021-10-15 18:07:09 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-09-08 19:12:00 +08:00
|
|
|
|
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-02-13 16:38:33 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-03-24 10:15:25 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
2023-09-27 11:07:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2024-06-26 13:36:05 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/common"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgdispatcher"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2021-09-08 19:12:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockMsgStreamFactory struct {
|
2022-03-24 10:15:25 +08:00
|
|
|
InitReturnNil bool
|
2021-09-09 15:36:01 +08:00
|
|
|
NewMsgStreamNoError bool
|
2021-09-08 19:12:00 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 11:07:25 +08:00
|
|
|
var (
|
|
|
|
_ msgstream.Factory = &mockMsgStreamFactory{}
|
|
|
|
_ dependency.Factory = (*mockMsgStreamFactory)(nil)
|
|
|
|
)
|
2021-09-09 15:36:01 +08:00
|
|
|
|
2023-09-27 11:07:25 +08:00
|
|
|
func (mm *mockMsgStreamFactory) Init(params *paramtable.ComponentParam) {}
|
|
|
|
func (mm *mockMsgStreamFactory) NewPersistentStorageChunkManager(ctx context.Context) (storage.ChunkManager, error) {
|
|
|
|
return nil, nil
|
2021-09-08 19:12:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mm *mockMsgStreamFactory) NewMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
2021-09-09 15:36:01 +08:00
|
|
|
if !mm.NewMsgStreamNoError {
|
|
|
|
return nil, errors.New("New MsgStream error")
|
|
|
|
}
|
|
|
|
return &mockTtMsgStream{}, nil
|
2021-09-08 19:12:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mm *mockMsgStreamFactory) NewTtMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return &mockTtMsgStream{}, nil
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:28:11 +08:00
|
|
|
func (mm *mockMsgStreamFactory) NewMsgStreamDisposer(ctx context.Context) func([]string, string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
type mockTtMsgStream struct{}
|
2021-09-08 19:12:00 +08:00
|
|
|
|
|
|
|
func (mtm *mockTtMsgStream) Close() {}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) Chan() <-chan *msgstream.MsgPack {
|
|
|
|
return make(chan *msgstream.MsgPack, 100)
|
|
|
|
}
|
|
|
|
|
2022-10-25 13:23:30 +08:00
|
|
|
func (mtm *mockTtMsgStream) AsProducer(channels []string) {}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2024-06-26 13:36:05 +08:00
|
|
|
func (mtm *mockTtMsgStream) AsConsumer(ctx context.Context, channels []string, subName string, position common.SubscriptionInitialPosition) error {
|
2023-09-08 09:51:17 +08:00
|
|
|
return nil
|
2021-10-15 11:46:33 +08:00
|
|
|
}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) SetRepackFunc(repackFunc msgstream.RepackFunc) {}
|
|
|
|
|
|
|
|
func (mtm *mockTtMsgStream) GetProduceChannels() []string {
|
|
|
|
return make([]string, 0)
|
|
|
|
}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) Produce(*msgstream.MsgPack) error {
|
|
|
|
return nil
|
|
|
|
}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2022-12-05 20:55:17 +08:00
|
|
|
func (mtm *mockTtMsgStream) Broadcast(*msgstream.MsgPack) (map[string][]msgstream.MessageID, error) {
|
|
|
|
return nil, nil
|
2021-09-27 14:10:09 +08:00
|
|
|
}
|
2023-03-04 23:21:50 +08:00
|
|
|
|
2024-06-11 15:01:55 +08:00
|
|
|
func (mtm *mockTtMsgStream) Seek(ctx context.Context, msgPositions []*msgstream.MsgPosition, includeCurrentMsg bool) error {
|
2021-09-08 19:12:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-19 15:57:12 +08:00
|
|
|
|
2022-03-15 14:45:22 +08:00
|
|
|
func (mtm *mockTtMsgStream) GetLatestMsgID(channel string) (msgstream.MessageID, error) {
|
2021-11-19 15:57:12 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
2021-09-08 19:12:00 +08:00
|
|
|
|
2023-04-03 16:44:23 +08:00
|
|
|
func (mtm *mockTtMsgStream) CheckTopicValid(channel string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
func (mtm *mockTtMsgStream) EnableProduce(can bool) {
|
|
|
|
}
|
|
|
|
|
2021-09-08 19:12:00 +08:00
|
|
|
func TestNewDmInputNode(t *testing.T) {
|
2023-02-13 16:38:33 +08:00
|
|
|
client := msgdispatcher.NewClient(&mockMsgStreamFactory{}, typeutil.DataNodeRole, paramtable.GetNodeID())
|
2023-09-20 16:03:23 +08:00
|
|
|
_, err := newDmInputNode(context.Background(), client, new(msgpb.MsgPosition), &nodeConfig{
|
2023-02-13 16:38:33 +08:00
|
|
|
msFactory: &mockMsgStreamFactory{},
|
|
|
|
vChannelName: "mock_vchannel_0",
|
|
|
|
})
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-08 19:12:00 +08:00
|
|
|
}
|