milvus/internal/util/flowgraph/input_node_test.go
XuanYang-cn 7f1ae35e72
Add timeout in dispatcher, AsConsumer and Seek (#26686)
See also: #25309

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
2023-09-08 09:51:17 +08:00

69 lines
2.2 KiB
Go

// 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 flowgraph
import (
"context"
"testing"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
)
func TestInputNode(t *testing.T) {
t.Setenv("ROCKSMQ_PATH", "/tmp/MilvusTest/FlowGraph/TestInputNode")
factory := dependency.NewDefaultFactory(true)
msgStream, _ := factory.NewMsgStream(context.TODO())
channels := []string{"cc"}
msgStream.AsConsumer(context.Background(), channels, "sub", mqwrapper.SubscriptionPositionEarliest)
msgPack := generateMsgPack()
produceStream, _ := factory.NewMsgStream(context.TODO())
produceStream.AsProducer(channels)
produceStream.Produce(&msgPack)
nodeName := "input_node"
inputNode := NewInputNode(msgStream.Chan(), nodeName, 100, 100, "", 0, 0, "")
defer inputNode.Close()
isInputNode := inputNode.IsInputNode()
assert.True(t, isInputNode)
name := inputNode.Name()
assert.Equal(t, name, nodeName)
output := inputNode.Operate(nil)
assert.NotNil(t, output)
msg, ok := output[0].(*MsgStreamMsg)
assert.True(t, ok)
assert.False(t, msg.isCloseMsg)
}
func Test_NewInputNode(t *testing.T) {
nodeName := "input_node"
var maxQueueLength int32
var maxParallelism int32 = 100
node := NewInputNode(nil, nodeName, maxQueueLength, maxParallelism, "", 0, 0, "")
assert.NotNil(t, node)
assert.Equal(t, node.name, nodeName)
assert.Equal(t, node.maxQueueLength, maxQueueLength)
assert.Equal(t, node.maxParallelism, maxParallelism)
}