Add GetVChanPosition new cases ut (#9544)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2021-10-09 20:57:33 +08:00 committed by GitHub
parent f6e4d8680e
commit 02dc2a2453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -666,6 +666,7 @@ func (s *Server) GetVChanPositions(vchans []vchannel, seekFromStartPosition bool
} }
} }
// use collection start position when segment position is not found
if seekPosition == nil { if seekPosition == nil {
coll := s.meta.GetCollection(vchan.CollectionID) coll := s.meta.GetCollection(vchan.CollectionID)
if coll != nil { if coll != nil {

View File

@ -1038,7 +1038,24 @@ func TestGetVChannelPos(t *testing.T) {
svr.meta.AddCollection(&datapb.CollectionInfo{ svr.meta.AddCollection(&datapb.CollectionInfo{
ID: 0, ID: 0,
Schema: schema, Schema: schema,
StartPositions: []*commonpb.KeyDataPair{
{
Key: "ch1",
Data: []byte{8, 9, 10},
},
},
}) })
svr.meta.AddCollection(&datapb.CollectionInfo{
ID: 1,
Schema: schema,
StartPositions: []*commonpb.KeyDataPair{
{
Key: "ch0",
Data: []byte{8, 9, 10},
},
},
})
s1 := &datapb.SegmentInfo{ s1 := &datapb.SegmentInfo{
ID: 1, ID: 1,
CollectionID: 0, CollectionID: 0,
@ -1102,6 +1119,21 @@ func TestGetVChannelPos(t *testing.T) {
assert.EqualValues(t, 2, pair[0].UnflushedSegments[0].ID) assert.EqualValues(t, 2, pair[0].UnflushedSegments[0].ID)
assert.EqualValues(t, []byte{1, 2, 3}, pair[0].UnflushedSegments[0].DmlPosition.MsgID) assert.EqualValues(t, []byte{1, 2, 3}, pair[0].UnflushedSegments[0].DmlPosition.MsgID)
}) })
t.Run("empty collection", func(t *testing.T) {
infos, err := svr.GetVChanPositions([]vchannel{
{
CollectionID: 1,
DmlChannel: "ch0_suffix",
},
}, true)
assert.Nil(t, err)
assert.EqualValues(t, 1, len(infos))
assert.EqualValues(t, 1, infos[0].CollectionID)
assert.EqualValues(t, 0, len(infos[0].FlushedSegments))
assert.EqualValues(t, 0, len(infos[0].UnflushedSegments))
assert.EqualValues(t, []byte{8, 9, 10}, infos[0].SeekPosition.MsgID)
})
} }
func TestGetRecoveryInfo(t *testing.T) { func TestGetRecoveryInfo(t *testing.T) {