2021-12-28 21:56:57 +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-07 09:39:47 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-28 21:56:57 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-07 09:39:47 +08:00
|
|
|
//
|
2021-12-28 21:56:57 +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-07 09:39:47 +08:00
|
|
|
|
|
|
|
package flowgraph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-09-07 09:39:47 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-04-07 22:05:32 +08:00
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
|
2021-09-07 09:39:47 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInputNode(t *testing.T) {
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv("ROCKSMQ_PATH", "/tmp/MilvusTest/FlowGraph/TestInputNode")
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
2021-09-07 09:39:47 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
msgStream, _ := factory.NewMsgStream(context.TODO())
|
2021-09-07 09:39:47 +08:00
|
|
|
channels := []string{"cc"}
|
2023-09-08 09:51:17 +08:00
|
|
|
msgStream.AsConsumer(context.Background(), channels, "sub", mqwrapper.SubscriptionPositionEarliest)
|
2021-09-07 09:39:47 +08:00
|
|
|
|
|
|
|
msgPack := generateMsgPack()
|
2022-04-07 22:05:32 +08:00
|
|
|
produceStream, _ := factory.NewMsgStream(context.TODO())
|
2021-09-07 09:39:47 +08:00
|
|
|
produceStream.AsProducer(channels)
|
|
|
|
produceStream.Produce(&msgPack)
|
|
|
|
|
|
|
|
nodeName := "input_node"
|
2023-02-13 16:38:33 +08:00
|
|
|
inputNode := NewInputNode(msgStream.Chan(), nodeName, 100, 100, "", 0, 0, "")
|
2021-09-29 20:19:59 +08:00
|
|
|
defer inputNode.Close()
|
2021-09-07 09:39:47 +08:00
|
|
|
|
|
|
|
isInputNode := inputNode.IsInputNode()
|
|
|
|
assert.True(t, isInputNode)
|
|
|
|
|
|
|
|
name := inputNode.Name()
|
|
|
|
assert.Equal(t, name, nodeName)
|
|
|
|
|
2022-10-10 22:15:22 +08:00
|
|
|
output := inputNode.Operate(nil)
|
|
|
|
assert.NotNil(t, output)
|
|
|
|
msg, ok := output[0].(*MsgStreamMsg)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.False(t, msg.isCloseMsg)
|
2021-09-07 09:39:47 +08:00
|
|
|
}
|
|
|
|
|
2021-09-13 16:34:26 +08:00
|
|
|
func Test_NewInputNode(t *testing.T) {
|
2021-09-07 09:39:47 +08:00
|
|
|
nodeName := "input_node"
|
2021-12-14 15:31:07 +08:00
|
|
|
var maxQueueLength int32
|
2021-09-07 09:39:47 +08:00
|
|
|
var maxParallelism int32 = 100
|
2022-11-07 10:15:02 +08:00
|
|
|
node := NewInputNode(nil, nodeName, maxQueueLength, maxParallelism, "", 0, 0, "")
|
2021-09-07 09:39:47 +08:00
|
|
|
assert.NotNil(t, node)
|
|
|
|
assert.Equal(t, node.name, nodeName)
|
|
|
|
assert.Equal(t, node.maxQueueLength, maxQueueLength)
|
|
|
|
assert.Equal(t, node.maxParallelism, maxParallelism)
|
|
|
|
}
|