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"
|
2021-09-09 15:36:01 +08:00
|
|
|
"errors"
|
2021-09-08 19:12:00 +08:00
|
|
|
"testing"
|
|
|
|
|
2022-03-24 10:15:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
|
|
|
|
2022-03-03 21:57:56 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/mq/msgstream/mqwrapper"
|
2021-09-08 19:12:00 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-10-04 17:37:57 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
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
|
|
|
}
|
|
|
|
|
2021-09-09 15:36:01 +08:00
|
|
|
var _ msgstream.Factory = &mockMsgStreamFactory{}
|
|
|
|
|
2022-03-24 10:15:25 +08:00
|
|
|
func (mm *mockMsgStreamFactory) Init(params *paramtable.ComponentParam) error {
|
|
|
|
if !mm.InitReturnNil {
|
|
|
|
return errors.New("Init Error")
|
2021-09-09 15:36:01 +08:00
|
|
|
}
|
2021-09-08 19:12:00 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mm *mockMsgStreamFactory) NewQueryMsgStream(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:28:11 +08:00
|
|
|
func (mm *mockMsgStreamFactory) NewMsgStreamDisposer(ctx context.Context) func([]string, string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-08 19:12:00 +08:00
|
|
|
type mockTtMsgStream struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mtm *mockTtMsgStream) Start() {}
|
|
|
|
func (mtm *mockTtMsgStream) Close() {}
|
|
|
|
func (mtm *mockTtMsgStream) Chan() <-chan *msgstream.MsgPack {
|
|
|
|
return make(chan *msgstream.MsgPack, 100)
|
|
|
|
}
|
|
|
|
|
2021-10-15 11:46:33 +08:00
|
|
|
func (mtm *mockTtMsgStream) AsProducer(channels []string) {}
|
|
|
|
func (mtm *mockTtMsgStream) AsConsumer(channels []string, subName string) {}
|
2022-03-03 21:57:56 +08:00
|
|
|
func (mtm *mockTtMsgStream) AsConsumerWithPosition(channels []string, subName string, position mqwrapper.SubscriptionInitialPosition) {
|
2021-10-15 11:46:33 +08:00
|
|
|
}
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) SetRepackFunc(repackFunc msgstream.RepackFunc) {}
|
|
|
|
func (mtm *mockTtMsgStream) ComputeProduceChannelIndexes(tsMsgs []msgstream.TsMsg) [][]int32 {
|
|
|
|
return make([][]int32, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mtm *mockTtMsgStream) GetProduceChannels() []string {
|
|
|
|
return make([]string, 0)
|
|
|
|
}
|
|
|
|
func (mtm *mockTtMsgStream) Produce(*msgstream.MsgPack) error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-11 11:38:57 +08:00
|
|
|
func (mtm *mockTtMsgStream) ProduceMark(*msgstream.MsgPack) (map[string][]msgstream.MessageID, error) {
|
|
|
|
return map[string][]msgstream.MessageID{}, nil
|
|
|
|
}
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) Broadcast(*msgstream.MsgPack) error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-27 14:10:09 +08:00
|
|
|
func (mtm *mockTtMsgStream) BroadcastMark(*msgstream.MsgPack) (map[string][]msgstream.MessageID, error) {
|
|
|
|
return map[string][]msgstream.MessageID{}, nil
|
|
|
|
}
|
2021-09-08 19:12:00 +08:00
|
|
|
func (mtm *mockTtMsgStream) Seek(offset []*internalpb.MsgPosition) error {
|
|
|
|
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
|
|
|
|
|
|
|
func TestNewDmInputNode(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2021-10-13 11:16:32 +08:00
|
|
|
_, err := newDmInputNode(ctx, new(internalpb.MsgPosition), &nodeConfig{msFactory: &mockMsgStreamFactory{}})
|
2021-10-04 17:37:57 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-08 19:12:00 +08:00
|
|
|
}
|