2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2021-01-20 10:02:59 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream/pulsarms"
|
2021-01-19 11:37:16 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2021-03-12 14:22:09 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: start pulsar before test
|
|
|
|
func TestDataSyncService_Start(t *testing.T) {
|
|
|
|
const ctxTimeInMillisecond = 2000
|
|
|
|
const closeWithDeadline = true
|
|
|
|
var ctx context.Context
|
|
|
|
|
|
|
|
if closeWithDeadline {
|
|
|
|
var cancel context.CancelFunc
|
|
|
|
d := time.Now().Add(ctxTimeInMillisecond * time.Millisecond)
|
|
|
|
ctx, cancel = context.WithDeadline(context.Background(), d)
|
|
|
|
defer cancel()
|
|
|
|
} else {
|
|
|
|
ctx = context.Background()
|
|
|
|
}
|
|
|
|
|
|
|
|
// init data node
|
|
|
|
pulsarURL := Params.PulsarAddress
|
2021-01-22 19:36:09 +08:00
|
|
|
|
2021-01-24 21:20:11 +08:00
|
|
|
Factory := &MetaFactory{}
|
2021-01-22 19:36:09 +08:00
|
|
|
collMeta := Factory.CollectionMetaFactory(UniqueID(0), "coll1")
|
2021-01-24 21:20:11 +08:00
|
|
|
|
|
|
|
chanSize := 100
|
|
|
|
flushChan := make(chan *flushMsg, chanSize)
|
|
|
|
replica := newReplica()
|
|
|
|
allocFactory := AllocatorFactory{}
|
2021-02-08 14:30:54 +08:00
|
|
|
msFactory := pulsarms.NewFactory()
|
|
|
|
m := map[string]interface{}{
|
|
|
|
"pulsarAddress": pulsarURL,
|
|
|
|
"receiveBufSize": 1024,
|
|
|
|
"pulsarBufSize": 1024}
|
|
|
|
err := msFactory.SetParams(m)
|
2021-03-24 16:35:38 +08:00
|
|
|
sync := newDataSyncService(ctx, flushChan, replica, &allocFactory, msFactory)
|
2021-01-25 18:33:10 +08:00
|
|
|
sync.replica.addCollection(collMeta.ID, collMeta.Schema)
|
2021-02-03 17:30:10 +08:00
|
|
|
sync.init()
|
2021-01-24 21:20:11 +08:00
|
|
|
go sync.start()
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
timeRange := TimeRange{
|
|
|
|
timestampMin: 0,
|
|
|
|
timestampMax: math.MaxUint64,
|
|
|
|
}
|
2021-02-03 17:30:10 +08:00
|
|
|
dataFactory := NewDataFactory()
|
|
|
|
insertMessages := dataFactory.GetMsgStreamTsInsertMsgs(2)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
msgPack := msgstream.MsgPack{
|
|
|
|
BeginTs: timeRange.timestampMin,
|
|
|
|
EndTs: timeRange.timestampMax,
|
|
|
|
Msgs: insertMessages,
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate timeTick
|
|
|
|
timeTickMsgPack := msgstream.MsgPack{}
|
|
|
|
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: Timestamp(0),
|
|
|
|
EndTimestamp: Timestamp(0),
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
},
|
2021-03-12 14:22:09 +08:00
|
|
|
TimeTickMsg: internalpb.TimeTickMsg{
|
2021-01-19 11:37:16 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-01-19 11:37:16 +08:00
|
|
|
MsgID: UniqueID(0),
|
|
|
|
Timestamp: math.MaxUint64,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
timeTickMsgPack.Msgs = append(timeTickMsgPack.Msgs, timeTickMsg)
|
|
|
|
|
|
|
|
// pulsar produce
|
|
|
|
insertChannels := Params.InsertChannelNames
|
|
|
|
ddChannels := Params.DDChannelNames
|
|
|
|
|
2021-02-08 14:30:54 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
insertStream, _ := msFactory.NewMsgStream(ctx)
|
2021-02-04 14:37:12 +08:00
|
|
|
insertStream.AsProducer(insertChannels)
|
|
|
|
|
2021-02-08 14:30:54 +08:00
|
|
|
ddStream, _ := msFactory.NewMsgStream(ctx)
|
2021-02-04 14:37:12 +08:00
|
|
|
ddStream.AsProducer(ddChannels)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
var insertMsgStream msgstream.MsgStream = insertStream
|
|
|
|
insertMsgStream.Start()
|
|
|
|
|
|
|
|
var ddMsgStream msgstream.MsgStream = ddStream
|
|
|
|
ddMsgStream.Start()
|
|
|
|
|
2021-02-24 09:48:17 +08:00
|
|
|
err = insertMsgStream.Produce(ctx, &msgPack)
|
2021-01-19 11:37:16 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-02-24 09:48:17 +08:00
|
|
|
err = insertMsgStream.Broadcast(ctx, &timeTickMsgPack)
|
2021-01-19 11:37:16 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-24 09:48:17 +08:00
|
|
|
err = ddMsgStream.Broadcast(ctx, &timeTickMsgPack)
|
2021-01-19 11:37:16 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// dataSync
|
2021-01-22 09:36:40 +08:00
|
|
|
Params.FlushInsertBufferSize = 1
|
2021-02-03 17:30:10 +08:00
|
|
|
<-sync.ctx.Done()
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-01-24 21:20:11 +08:00
|
|
|
sync.close()
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|