mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
85a544b79b
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
180 lines
4.2 KiB
Go
180 lines
4.2 KiB
Go
package querynode
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/etcdpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
|
|
)
|
|
|
|
func TestCollection_Partitions(t *testing.T) {
|
|
ctx := context.Background()
|
|
node := NewQueryNode(ctx, 0)
|
|
|
|
collectionName := "collection0"
|
|
fieldVec := schemapb.FieldSchema{
|
|
Name: "vec",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "16",
|
|
},
|
|
},
|
|
}
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
Name: "age",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_INT32,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "1",
|
|
},
|
|
},
|
|
}
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
Name: collectionName,
|
|
AutoID: true,
|
|
Fields: []*schemapb.FieldSchema{
|
|
&fieldVec, &fieldInt,
|
|
},
|
|
}
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
|
ID: UniqueID(0),
|
|
Schema: &schema,
|
|
CreateTime: Timestamp(0),
|
|
SegmentIDs: []UniqueID{0},
|
|
PartitionTags: []string{"default"},
|
|
}
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
var err = (*node.replica).addCollection(&collectionMeta, collectionMetaBlob)
|
|
assert.NoError(t, err)
|
|
|
|
collection, err := (*node.replica).getCollectionByName(collectionName)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
|
assert.Equal(t, (*node.replica).getCollectionNum(), 1)
|
|
|
|
for _, tag := range collectionMeta.PartitionTags {
|
|
err := (*node.replica).addPartition(collection.ID(), tag)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
partitions := collection.Partitions()
|
|
assert.Equal(t, len(collectionMeta.PartitionTags), len(*partitions))
|
|
}
|
|
|
|
func TestCollection_newCollection(t *testing.T) {
|
|
fieldVec := schemapb.FieldSchema{
|
|
Name: "vec",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "16",
|
|
},
|
|
},
|
|
}
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
Name: "age",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_INT32,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "1",
|
|
},
|
|
},
|
|
}
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
Name: "collection0",
|
|
AutoID: true,
|
|
Fields: []*schemapb.FieldSchema{
|
|
&fieldVec, &fieldInt,
|
|
},
|
|
}
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
|
ID: UniqueID(0),
|
|
Schema: &schema,
|
|
CreateTime: Timestamp(0),
|
|
SegmentIDs: []UniqueID{0},
|
|
PartitionTags: []string{"default"},
|
|
}
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
collection := newCollection(&collectionMeta, collectionMetaBlob)
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
|
}
|
|
|
|
func TestCollection_deleteCollection(t *testing.T) {
|
|
fieldVec := schemapb.FieldSchema{
|
|
Name: "vec",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "16",
|
|
},
|
|
},
|
|
}
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
Name: "age",
|
|
IsPrimaryKey: false,
|
|
DataType: schemapb.DataType_INT32,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{
|
|
Key: "dim",
|
|
Value: "1",
|
|
},
|
|
},
|
|
}
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
Name: "collection0",
|
|
AutoID: true,
|
|
Fields: []*schemapb.FieldSchema{
|
|
&fieldVec, &fieldInt,
|
|
},
|
|
}
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
|
ID: UniqueID(0),
|
|
Schema: &schema,
|
|
CreateTime: Timestamp(0),
|
|
SegmentIDs: []UniqueID{0},
|
|
PartitionTags: []string{"default"},
|
|
}
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
collection := newCollection(&collectionMeta, collectionMetaBlob)
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
|
|
|
deleteCollection(collection)
|
|
}
|