2023-03-27 00:42:00 +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
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package pipeline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
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/mq/msgstream/mqwrapper"
|
2023-03-27 00:42:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type StreamPipelineSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
pipeline StreamPipeline
|
|
|
|
inChannel chan *msgstream.MsgPack
|
|
|
|
outChannel chan msgstream.Timestamp
|
2023-09-21 09:45:27 +08:00
|
|
|
// data
|
2023-03-27 00:42:00 +08:00
|
|
|
length int
|
|
|
|
channel string
|
2023-09-21 09:45:27 +08:00
|
|
|
// mock
|
2023-03-27 00:42:00 +08:00
|
|
|
msgDispatcher *msgdispatcher.MockClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StreamPipelineSuite) SetupTest() {
|
|
|
|
suite.channel = "test-channel"
|
|
|
|
suite.inChannel = make(chan *msgstream.MsgPack, 1)
|
|
|
|
suite.outChannel = make(chan msgstream.Timestamp)
|
|
|
|
suite.msgDispatcher = msgdispatcher.NewMockClient(suite.T())
|
2023-09-08 09:51:17 +08:00
|
|
|
suite.msgDispatcher.EXPECT().Register(mock.Anything, suite.channel, mock.Anything, mqwrapper.SubscriptionPositionUnknown).Return(suite.inChannel, nil)
|
2023-03-27 00:42:00 +08:00
|
|
|
suite.msgDispatcher.EXPECT().Deregister(suite.channel)
|
|
|
|
suite.pipeline = NewPipelineWithStream(suite.msgDispatcher, 0, false, suite.channel)
|
|
|
|
suite.length = 4
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *StreamPipelineSuite) TestBasic() {
|
|
|
|
for i := 1; i <= suite.length; i++ {
|
|
|
|
suite.pipeline.Add(&testNode{
|
|
|
|
BaseNode: &BaseNode{
|
|
|
|
name: fmt.Sprintf("test-node-%d", i),
|
|
|
|
maxQueueLength: 8,
|
|
|
|
},
|
|
|
|
outChannel: suite.outChannel,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
err := suite.pipeline.ConsumeMsgStream(&msgpb.MsgPosition{})
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
suite.pipeline.Start()
|
|
|
|
defer suite.pipeline.Close()
|
|
|
|
suite.inChannel <- &msgstream.MsgPack{}
|
|
|
|
|
|
|
|
for i := 1; i <= suite.length; i++ {
|
|
|
|
output := <-suite.outChannel
|
|
|
|
suite.Equal(msgstream.Timestamp(i), output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamPipeline(t *testing.T) {
|
|
|
|
suite.Run(t, new(StreamPipelineSuite))
|
|
|
|
}
|