2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed 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.
|
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2020-11-12 17:58:05 +08:00
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2020-11-12 12:04:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: start pulsar before test
|
2020-11-19 17:09:22 +08:00
|
|
|
func TestDataSyncService_Start(t *testing.T) {
|
2021-03-22 16:36:10 +08:00
|
|
|
collectionID := UniqueID(0)
|
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2020-11-12 12:04:12 +08:00
|
|
|
// test data generate
|
|
|
|
const msgLength = 10
|
|
|
|
const DIM = 16
|
|
|
|
const N = 10
|
|
|
|
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
// messages generate
|
2020-11-17 14:10:07 +08:00
|
|
|
insertMessages := make([]msgstream.TsMsg, 0)
|
2020-11-12 12:04:12 +08:00
|
|
|
for i := 0; i < msgLength; i++ {
|
|
|
|
var msg msgstream.TsMsg = &msgstream.InsertMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
2020-11-30 19:38:23 +08:00
|
|
|
HashValues: []uint32{
|
|
|
|
uint32(i), uint32(i),
|
2020-11-12 12:04:12 +08:00
|
|
|
},
|
|
|
|
},
|
2021-03-12 14:22:09 +08:00
|
|
|
InsertRequest: internalpb.InsertRequest{
|
2021-01-18 19:32:08 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_Insert,
|
2021-01-18 19:32:08 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: uint64(i + 1000),
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
2021-03-22 16:36:10 +08:00
|
|
|
CollectionID: collectionID,
|
2021-02-03 18:12:48 +08:00
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
SegmentID: int64(0),
|
|
|
|
ChannelID: "0",
|
|
|
|
Timestamps: []uint64{uint64(i + 1000), uint64(i + 1000)},
|
|
|
|
RowIDs: []int64{int64(i), int64(i)},
|
2020-11-12 12:04:12 +08:00
|
|
|
RowData: []*commonpb.Blob{
|
|
|
|
{Value: rawData},
|
|
|
|
{Value: rawData},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-11-17 14:10:07 +08:00
|
|
|
insertMessages = append(insertMessages, msg)
|
2020-11-12 12:04:12 +08:00
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:22 +08:00
|
|
|
// generate timeTick
|
|
|
|
timeTickMsgPack := msgstream.MsgPack{}
|
|
|
|
baseMsg := msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: 0,
|
|
|
|
EndTimestamp: 0,
|
2020-11-30 19:38:23 +08:00
|
|
|
HashValues: []uint32{0},
|
2020-11-19 17:09:22 +08:00
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
timeTickResult := internalpb.TimeTickMsg{
|
2021-01-18 19:32:08 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-01-18 19:32:08 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: math.MaxUint64,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
2020-11-19 17:09:22 +08:00
|
|
|
}
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: baseMsg,
|
|
|
|
TimeTickMsg: timeTickResult,
|
|
|
|
}
|
|
|
|
timeTickMsgPack.Msgs = append(timeTickMsgPack.Msgs, timeTickMsg)
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
// pulsar produce
|
|
|
|
const receiveBufSize = 1024
|
2020-12-10 16:31:09 +08:00
|
|
|
pulsarURL := Params.PulsarAddress
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2021-04-02 13:48:25 +08:00
|
|
|
msFactory := msgstream.NewPmsFactory()
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"receiveBufSize": receiveBufSize,
|
|
|
|
"pulsarAddress": pulsarURL,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err := msFactory.SetParams(m)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-06-15 20:06:10 +08:00
|
|
|
channels := []Channel{"0"}
|
2021-06-09 11:37:55 +08:00
|
|
|
err = node.streaming.dataSyncService.addCollectionFlowGraph(collectionID, channels)
|
|
|
|
assert.NoError(t, err)
|
2021-06-15 12:41:40 +08:00
|
|
|
err = node.streaming.dataSyncService.startCollectionFlowGraph(collectionID, channels)
|
2021-06-09 11:37:55 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
<-node.queryNodeLoopCtx.Done()
|
2021-01-21 15:20:23 +08:00
|
|
|
node.Stop()
|
2020-11-12 12:04:12 +08:00
|
|
|
}
|