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"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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{}
|
|
|
|
sync := newDataSyncService(ctx, flushChan, replica, allocFactory)
|
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},
|
|
|
|
},
|
|
|
|
TimeTickMsg: internalpb2.TimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_kTimeTick,
|
|
|
|
MsgID: UniqueID(0),
|
|
|
|
Timestamp: math.MaxUint64,
|
|
|
|
SourceID: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
timeTickMsgPack.Msgs = append(timeTickMsgPack.Msgs, timeTickMsg)
|
|
|
|
|
|
|
|
// pulsar produce
|
|
|
|
const receiveBufSize = 1024
|
|
|
|
insertChannels := Params.InsertChannelNames
|
|
|
|
ddChannels := Params.DDChannelNames
|
|
|
|
|
2021-02-04 14:37:12 +08:00
|
|
|
factory := pulsarms.NewFactory(pulsarURL, receiveBufSize, 1024)
|
|
|
|
insertStream, _ := factory.NewMsgStream(ctx)
|
|
|
|
insertStream.AsProducer(insertChannels)
|
|
|
|
|
|
|
|
ddStream, _ := factory.NewMsgStream(ctx)
|
|
|
|
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()
|
|
|
|
|
|
|
|
err := insertMsgStream.Produce(&msgPack)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = insertMsgStream.Broadcast(&timeTickMsgPack)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = ddMsgStream.Broadcast(&timeTickMsgPack)
|
|
|
|
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
|
|
|
}
|