2021-11-29 20:13:50 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
import (
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-02-08 21:57:46 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2020-11-12 11:18:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------- collection
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getCollectionNum(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.replica.getCollectionNum(), 1)
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_addCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_removeCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, 0, 0)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.replica.getCollectionNum(), 1)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.removeCollection(0)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
assert.Equal(t, node.historical.replica.getCollectionNum(), 0)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getCollectionByID(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetCollection, err := node.historical.replica.getCollectionByID(collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, targetCollection)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, targetCollection.ID(), collectionID)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_hasCollection(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-05-28 10:26:30 +08:00
|
|
|
hasCollection := node.historical.replica.hasCollection(collectionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasCollection, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasCollection = node.historical.replica.hasCollection(UniqueID(1))
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasCollection, false)
|
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- partition
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getPartitionNum(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-24 15:59:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-24 15:59:51 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
for _, id := range partitionIDs {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.replica.getPartitionByID(id)
|
2020-11-24 15:59:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-05-28 10:26:30 +08:00
|
|
|
partitionNum := node.historical.replica.getPartitionNum()
|
2021-09-07 15:45:59 +08:00
|
|
|
assert.Equal(t, partitionNum, len(partitionIDs))
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_addPartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
|
|
|
for _, id := range partitionIDs {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.replica.getPartitionByID(id)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_removePartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
partitionIDs := []UniqueID{1, 2, 3}
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
for _, id := range partitionIDs {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.replica.getPartitionByID(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2021-05-28 10:26:30 +08:00
|
|
|
err = node.historical.replica.removePartition(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getPartitionByTag(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-02-03 18:12:48 +08:00
|
|
|
for _, id := range collectionMeta.PartitionIDs {
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
partition, err := node.historical.replica.getPartitionByID(id)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-03 18:12:48 +08:00
|
|
|
assert.Equal(t, partition.ID(), id)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NotNil(t, partition)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_hasPartition(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2021-05-28 10:26:30 +08:00
|
|
|
err := node.historical.replica.addPartition(collectionID, collectionMeta.PartitionIDs[0])
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasPartition := node.historical.replica.hasPartition(defaultPartitionID)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasPartition, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasPartition = node.historical.replica.hasPartition(defaultPartitionID + 1)
|
2020-11-25 10:31:51 +08:00
|
|
|
assert.Equal(t, hasPartition, false)
|
2021-02-05 10:53:11 +08:00
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 15:59:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- segment
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_addSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.replica.getSegmentByID(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_removeSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.replica.getSegmentByID(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
2021-05-28 10:26:30 +08:00
|
|
|
err = node.historical.replica.removeSegment(UniqueID(i))
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-24 16:12:39 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_getSegmentByID(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-24 16:12:39 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-24 16:12:39 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.replica.getSegmentByID(UniqueID(i))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 16:00:55 +08:00
|
|
|
func TestCollectionReplica_getSegmentInfosByColID(t *testing.T) {
|
|
|
|
node := newQueryNodeMock()
|
|
|
|
collectionID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
collection := node.historical.replica.addCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
node.historical.replica.addPartition(collectionID, defaultPartitionID)
|
|
|
|
|
|
|
|
// test get indexed segment info
|
|
|
|
vectorFieldIDDs, err := node.historical.replica.getVecFieldIDsByCollectionID(collectionID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(vectorFieldIDDs))
|
|
|
|
fieldID := vectorFieldIDDs[0]
|
|
|
|
|
|
|
|
indexID := UniqueID(10000)
|
2022-03-30 21:11:28 +08:00
|
|
|
indexInfo := &IndexedFieldInfo{
|
|
|
|
indexInfo: &querypb.FieldIndexInfo{
|
2022-02-08 21:57:46 +08:00
|
|
|
IndexName: "test-index-name",
|
|
|
|
IndexID: indexID,
|
|
|
|
EnableIndex: true,
|
|
|
|
},
|
|
|
|
}
|
2021-11-05 16:00:55 +08:00
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
segment1, err := newSegment(collection, UniqueID(1), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-02-08 21:57:46 +08:00
|
|
|
err = node.historical.replica.setSegment(segment1)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-02-08 21:57:46 +08:00
|
|
|
|
|
|
|
segment2, err := newSegment(collection, UniqueID(2), defaultPartitionID, collectionID, "", segmentTypeSealed, true)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-03-30 21:11:28 +08:00
|
|
|
segment2.setIndexedFieldInfo(fieldID, indexInfo)
|
2022-02-08 21:57:46 +08:00
|
|
|
err = node.historical.replica.setSegment(segment2)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
targetSegs, err := node.historical.replica.getSegmentInfosByColID(collectionID)
|
2021-11-05 16:00:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Equal(t, 2, len(targetSegs))
|
|
|
|
for _, segment := range targetSegs {
|
|
|
|
if segment.GetSegmentState() == segmentTypeGrowing {
|
|
|
|
assert.Equal(t, UniqueID(0), segment.IndexID)
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, indexID, segment.IndexID)
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 16:00:55 +08:00
|
|
|
|
|
|
|
err = node.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func TestCollectionReplica_hasSegment(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
|
|
|
const segmentNum = 3
|
2020-12-08 14:41:04 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
for i := 0; i < segmentNum; i++ {
|
2021-06-15 12:41:40 +08:00
|
|
|
err := node.historical.replica.addSegment(UniqueID(i), defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-05-28 10:26:30 +08:00
|
|
|
targetSeg, err := node.historical.replica.getSegmentByID(UniqueID(i))
|
2020-11-13 16:53:55 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.Equal(t, targetSeg.segmentID, UniqueID(i))
|
2021-05-28 10:26:30 +08:00
|
|
|
hasSeg := node.historical.replica.hasSegment(UniqueID(i))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.Equal(t, hasSeg, true)
|
2021-05-28 10:26:30 +08:00
|
|
|
hasSeg = node.historical.replica.hasSegment(UniqueID(i + 100))
|
2020-11-24 16:12:39 +08:00
|
|
|
assert.Equal(t, hasSeg, false)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionReplica_freeAll(t *testing.T) {
|
2021-01-15 15:28:54 +08:00
|
|
|
node := newQueryNodeMock()
|
2020-11-25 10:31:51 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
initTestMeta(t, node, collectionID, 0)
|
2020-11-25 10:31:51 +08:00
|
|
|
|
2021-02-05 10:53:11 +08:00
|
|
|
err := node.Stop()
|
|
|
|
assert.NoError(t, err)
|
2021-02-07 21:26:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-10 09:33:43 +08:00
|
|
|
func TestCollectionReplica_statistic(t *testing.T) {
|
|
|
|
t.Run("test getCollectionIDs", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
ids := replica.getCollectionIDs()
|
|
|
|
assert.Len(t, ids, 1)
|
|
|
|
assert.Equal(t, defaultCollectionID, ids[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test getCollectionIDs", func(t *testing.T) {
|
|
|
|
replica, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
num := replica.getSegmentNum()
|
|
|
|
assert.Equal(t, 0, num)
|
|
|
|
})
|
|
|
|
}
|