2020-11-02 08:01:04 +00:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-11-03 06:53:36 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-11-02 08:01:04 +00:00
|
|
|
commonPb "github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
internalPb "github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func repackFunc(msgs []*TsMsg, hashKeys [][]int32) map[int32]*MsgPack {
|
|
|
|
result := make(map[int32]*MsgPack)
|
|
|
|
for i, request := range msgs {
|
|
|
|
keys := hashKeys[i]
|
|
|
|
for _, channelId := range keys {
|
|
|
|
_, ok := result[channelId]
|
|
|
|
if ok == false {
|
|
|
|
msgPack := MsgPack{}
|
|
|
|
result[channelId] = &msgPack
|
|
|
|
}
|
|
|
|
result[channelId].Msgs = append(result[channelId].Msgs, request)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-11-04 09:58:43 +00:00
|
|
|
func getTsMsg(msgType MsgType, reqId UniqueID, hashValue int32) *TsMsg {
|
2020-11-02 08:01:04 +00:00
|
|
|
var tsMsg TsMsg
|
2020-11-05 10:01:33 +00:00
|
|
|
baseMsg := BaseMsg{
|
|
|
|
HashValues: []int32{hashValue},
|
|
|
|
}
|
2020-11-02 08:01:04 +00:00
|
|
|
switch msgType {
|
2020-11-04 09:58:43 +00:00
|
|
|
case internalPb.MsgType_kInsert:
|
2020-11-02 08:01:04 +00:00
|
|
|
insertRequest := internalPb.InsertRequest{
|
2020-11-04 08:28:14 +00:00
|
|
|
MsgType: internalPb.MsgType_kInsert,
|
2020-11-02 08:01:04 +00:00
|
|
|
ReqId: reqId,
|
|
|
|
CollectionName: "Collection",
|
|
|
|
PartitionTag: "Partition",
|
|
|
|
SegmentId: 1,
|
|
|
|
ChannelId: 1,
|
|
|
|
ProxyId: 1,
|
2020-11-04 09:58:43 +00:00
|
|
|
Timestamps: []Timestamp{1},
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
2020-11-05 10:01:33 +00:00
|
|
|
insertMsg := &InsertMsg{
|
|
|
|
BaseMsg: baseMsg,
|
2020-11-02 08:01:04 +00:00
|
|
|
InsertRequest: insertRequest,
|
|
|
|
}
|
|
|
|
tsMsg = insertMsg
|
2020-11-04 09:58:43 +00:00
|
|
|
case internalPb.MsgType_kDelete:
|
2020-11-02 08:01:04 +00:00
|
|
|
deleteRequest := internalPb.DeleteRequest{
|
2020-11-04 08:28:14 +00:00
|
|
|
MsgType: internalPb.MsgType_kDelete,
|
2020-11-02 08:01:04 +00:00
|
|
|
ReqId: reqId,
|
|
|
|
CollectionName: "Collection",
|
|
|
|
ChannelId: 1,
|
|
|
|
ProxyId: 1,
|
2020-11-04 09:58:43 +00:00
|
|
|
Timestamps: []Timestamp{1},
|
|
|
|
PrimaryKeys: []IntPrimaryKey{1},
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
2020-11-05 10:01:33 +00:00
|
|
|
deleteMsg := &DeleteMsg{
|
|
|
|
BaseMsg: baseMsg,
|
2020-11-02 08:01:04 +00:00
|
|
|
DeleteRequest: deleteRequest,
|
|
|
|
}
|
|
|
|
tsMsg = deleteMsg
|
2020-11-04 09:58:43 +00:00
|
|
|
case internalPb.MsgType_kSearch:
|
2020-11-02 08:01:04 +00:00
|
|
|
searchRequest := internalPb.SearchRequest{
|
2020-11-04 08:28:14 +00:00
|
|
|
MsgType: internalPb.MsgType_kSearch,
|
2020-11-02 08:01:04 +00:00
|
|
|
ReqId: reqId,
|
|
|
|
ProxyId: 1,
|
|
|
|
Timestamp: 1,
|
|
|
|
ResultChannelId: 1,
|
|
|
|
}
|
2020-11-05 10:01:33 +00:00
|
|
|
searchMsg := &SearchMsg{
|
|
|
|
BaseMsg: baseMsg,
|
2020-11-02 08:01:04 +00:00
|
|
|
SearchRequest: searchRequest,
|
|
|
|
}
|
|
|
|
tsMsg = searchMsg
|
2020-11-04 09:58:43 +00:00
|
|
|
case internalPb.MsgType_kSearchResult:
|
2020-11-02 08:01:04 +00:00
|
|
|
searchResult := internalPb.SearchResult{
|
2020-11-05 11:11:12 +00:00
|
|
|
MsgType: internalPb.MsgType_kSearchResult,
|
2020-11-02 08:01:04 +00:00
|
|
|
Status: &commonPb.Status{ErrorCode: commonPb.ErrorCode_SUCCESS},
|
|
|
|
ReqId: reqId,
|
|
|
|
ProxyId: 1,
|
|
|
|
QueryNodeId: 1,
|
|
|
|
Timestamp: 1,
|
|
|
|
ResultChannelId: 1,
|
|
|
|
}
|
2020-11-05 10:01:33 +00:00
|
|
|
searchResultMsg := &SearchResultMsg{
|
|
|
|
BaseMsg: baseMsg,
|
2020-11-02 08:01:04 +00:00
|
|
|
SearchResult: searchResult,
|
|
|
|
}
|
|
|
|
tsMsg = searchResultMsg
|
2020-11-04 09:58:43 +00:00
|
|
|
case internalPb.MsgType_kTimeTick:
|
2020-11-04 08:28:14 +00:00
|
|
|
timeTickResult := internalPb.TimeTickMsg{
|
2020-11-05 11:11:12 +00:00
|
|
|
MsgType: internalPb.MsgType_kTimeTick,
|
2020-11-02 08:01:04 +00:00
|
|
|
PeerId: reqId,
|
|
|
|
Timestamp: 1,
|
|
|
|
}
|
2020-11-05 10:01:33 +00:00
|
|
|
timeTickMsg := &TimeTickMsg{
|
|
|
|
BaseMsg: baseMsg,
|
2020-11-04 08:28:14 +00:00
|
|
|
TimeTickMsg: timeTickResult,
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
tsMsg = timeTickMsg
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
return &tsMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
func initStream(pulsarAddress string,
|
|
|
|
producerChannels []string,
|
|
|
|
consumerChannels []string,
|
|
|
|
consumerSubName string,
|
|
|
|
msgPack *MsgPack,
|
|
|
|
inputMsgType MsgType,
|
2020-11-04 08:28:14 +00:00
|
|
|
outputMsgType MsgType,
|
|
|
|
broadCast bool) {
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
// set input stream
|
|
|
|
inputStream := PulsarMsgStream{}
|
|
|
|
inputStream.SetPulsarCient(pulsarAddress)
|
|
|
|
inputStream.SetMsgMarshaler(GetMarshaler(inputMsgType), nil)
|
|
|
|
inputStream.SetProducers(producerChannels)
|
|
|
|
inputStream.SetRepackFunc(repackFunc)
|
|
|
|
|
|
|
|
// set output stream
|
|
|
|
outputStream := PulsarMsgStream{}
|
|
|
|
outputStream.SetPulsarCient(pulsarAddress)
|
|
|
|
outputStream.SetMsgMarshaler(nil, GetMarshaler(outputMsgType))
|
|
|
|
outputStream.SetConsumers(consumerChannels, consumerSubName, 100)
|
|
|
|
outputStream.InitMsgPackBuf(100)
|
|
|
|
outputStream.Start()
|
|
|
|
|
|
|
|
//send msgPack
|
2020-11-04 08:28:14 +00:00
|
|
|
if broadCast {
|
|
|
|
inputStream.BroadCast(msgPack)
|
|
|
|
} else {
|
|
|
|
inputStream.Produce(msgPack)
|
|
|
|
//outputStream.Start()
|
|
|
|
}
|
|
|
|
|
2020-11-02 08:01:04 +00:00
|
|
|
// receive msg
|
|
|
|
receiveCount := 0
|
|
|
|
for {
|
|
|
|
result := outputStream.Consume()
|
|
|
|
if len(result.Msgs) > 0 {
|
|
|
|
msgs := result.Msgs
|
|
|
|
for _, v := range msgs {
|
|
|
|
receiveCount++
|
|
|
|
fmt.Println("msg type: ", (*v).Type(), ", msg value: ", *v)
|
|
|
|
}
|
|
|
|
}
|
2020-11-04 08:28:14 +00:00
|
|
|
if broadCast {
|
2020-11-04 09:58:43 +00:00
|
|
|
if receiveCount >= len(msgPack.Msgs)*len(producerChannels) {
|
2020-11-04 08:28:14 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if receiveCount >= len(msgPack.Msgs) {
|
|
|
|
break
|
|
|
|
}
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStream_Insert(t *testing.T) {
|
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
|
|
|
producerChannels := []string{"insert1", "insert2"}
|
|
|
|
consumerChannels := []string{"insert1", "insert2"}
|
|
|
|
consumerSubName := "subInsert"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kInsert, 1, 1))
|
2020-11-05 02:10:16 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kInsert, 3, 3))
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kInsert, internalPb.MsgType_kInsert, false)
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 11:11:12 +00:00
|
|
|
func TestStream_Delete(t *testing.T) {
|
2020-11-02 08:01:04 +00:00
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
|
|
|
producerChannels := []string{"delete"}
|
|
|
|
consumerChannels := []string{"delete"}
|
|
|
|
consumerSubName := "subDelete"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kDelete, 1, 1))
|
2020-11-04 09:58:43 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kDelete, 3, 3))
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kDelete, internalPb.MsgType_kDelete, false)
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStream_Search(t *testing.T) {
|
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
|
|
|
producerChannels := []string{"search"}
|
|
|
|
consumerChannels := []string{"search"}
|
|
|
|
consumerSubName := "subSearch"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kSearch, 1, 1))
|
2020-11-04 09:58:43 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kSearch, 3, 3))
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kSearch, internalPb.MsgType_kSearch, false)
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 11:11:12 +00:00
|
|
|
func TestStream_SearchResult(t *testing.T) {
|
2020-11-02 08:01:04 +00:00
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
|
|
|
producerChannels := []string{"search"}
|
|
|
|
consumerChannels := []string{"search"}
|
|
|
|
consumerSubName := "subSearch"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kSearchResult, 1, 1))
|
2020-11-04 09:58:43 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kSearchResult, 3, 3))
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kSearchResult, internalPb.MsgType_kSearchResult, false)
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 08:28:14 +00:00
|
|
|
func TestStream_TimeTick(t *testing.T) {
|
2020-11-02 08:01:04 +00:00
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
|
|
|
producerChannels := []string{"search"}
|
|
|
|
consumerChannels := []string{"search"}
|
|
|
|
consumerSubName := "subSearch"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kTimeTick, 1, 1))
|
2020-11-04 09:58:43 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kTimeTick, 3, 3))
|
2020-11-02 08:01:04 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kTimeTick, internalPb.MsgType_kTimeTick, false)
|
2020-11-02 08:01:04 +00:00
|
|
|
}
|
2020-11-03 03:25:47 +00:00
|
|
|
|
|
|
|
func TestStream_BroadCast(t *testing.T) {
|
|
|
|
pulsarAddress := "pulsar://localhost:6650"
|
2020-11-04 08:28:14 +00:00
|
|
|
producerChannels := []string{"insert1", "insert2"}
|
2020-11-05 02:10:16 +00:00
|
|
|
consumerChannels := []string{"insert1", "insert2"}
|
2020-11-03 03:25:47 +00:00
|
|
|
consumerSubName := "subInsert"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
2020-11-05 10:01:33 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kTimeTick, 1, 1))
|
2020-11-04 09:58:43 +00:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kTimeTick, 3, 3))
|
2020-11-03 03:25:47 +00:00
|
|
|
|
|
|
|
//run stream
|
2020-11-04 09:58:43 +00:00
|
|
|
initStream(pulsarAddress, producerChannels, consumerChannels, consumerSubName, &msgPack, internalPb.MsgType_kTimeTick, internalPb.MsgType_kTimeTick, true)
|
2020-11-03 03:25:47 +00:00
|
|
|
}
|