2020-11-09 17:52:47 +08:00
|
|
|
package msgstream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-11-12 11:18:23 +08:00
|
|
|
"log"
|
2020-11-09 17:52:47 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-11 09:54:01 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2020-11-09 17:52:47 +08:00
|
|
|
internalPb "github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
)
|
|
|
|
|
2020-11-17 14:10:07 +08:00
|
|
|
func newInsertMsgUnmarshal(input []byte) (TsMsg, error) {
|
2020-11-09 17:52:47 +08:00
|
|
|
insertRequest := internalPb.InsertRequest{}
|
|
|
|
err := proto.Unmarshal(input, &insertRequest)
|
|
|
|
insertMsg := &InsertMsg{InsertRequest: insertRequest}
|
|
|
|
fmt.Println("use func newInsertMsgUnmarshal unmarshal")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-17 14:10:07 +08:00
|
|
|
|
|
|
|
return insertMsg, nil
|
2020-11-09 17:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStream_unmarshal_Insert(t *testing.T) {
|
2020-11-21 15:06:46 +08:00
|
|
|
pulsarAddress, _ := Params.Load("_PulsarAddress")
|
2020-11-09 17:52:47 +08:00
|
|
|
producerChannels := []string{"insert1", "insert2"}
|
|
|
|
consumerChannels := []string{"insert1", "insert2"}
|
|
|
|
consumerSubName := "subInsert"
|
|
|
|
|
|
|
|
msgPack := MsgPack{}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kInsert, 1, 1))
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, getTsMsg(internalPb.MsgType_kInsert, 3, 3))
|
|
|
|
|
|
|
|
inputStream := NewPulsarMsgStream(context.Background(), 100)
|
2020-11-18 19:46:18 +08:00
|
|
|
inputStream.SetPulsarClient(pulsarAddress)
|
2020-11-09 17:52:47 +08:00
|
|
|
inputStream.CreatePulsarProducers(producerChannels)
|
|
|
|
inputStream.Start()
|
|
|
|
|
|
|
|
outputStream := NewPulsarMsgStream(context.Background(), 100)
|
2020-11-18 19:46:18 +08:00
|
|
|
outputStream.SetPulsarClient(pulsarAddress)
|
2020-11-09 17:52:47 +08:00
|
|
|
unmarshalDispatcher := NewUnmarshalDispatcher()
|
|
|
|
|
|
|
|
//add a new unmarshall func for msgType kInsert
|
|
|
|
unmarshalDispatcher.AddMsgTemplate(internalPb.MsgType_kInsert, newInsertMsgUnmarshal)
|
|
|
|
|
|
|
|
outputStream.CreatePulsarConsumers(consumerChannels, consumerSubName, unmarshalDispatcher, 100)
|
|
|
|
outputStream.Start()
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
err := inputStream.Produce(&msgPack)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("produce error = %v", err)
|
|
|
|
}
|
2020-11-09 17:52:47 +08:00
|
|
|
receiveCount := 0
|
|
|
|
for {
|
|
|
|
result := (*outputStream).Consume()
|
|
|
|
if len(result.Msgs) > 0 {
|
|
|
|
msgs := result.Msgs
|
|
|
|
for _, v := range msgs {
|
|
|
|
receiveCount++
|
2020-11-17 14:10:07 +08:00
|
|
|
fmt.Println("msg type: ", v.Type(), ", msg value: ", v, "msg tag: ")
|
2020-11-09 17:52:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if receiveCount >= len(msgPack.Msgs) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputStream.Close()
|
|
|
|
outputStream.Close()
|
|
|
|
}
|