2020-11-26 15:18:36 +08:00
|
|
|
package reader
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
import (
|
|
|
|
"context"
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"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()
|
2020-11-17 20:00:23 +08:00
|
|
|
node := NewQueryNode(ctx, 0)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
collectionName := "collection0"
|
2020-11-12 11:18:23 +08:00
|
|
|
fieldVec := schemapb.FieldSchema{
|
|
|
|
Name: "vec",
|
|
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "16",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
|
|
Name: "age",
|
|
|
|
DataType: schemapb.DataType_INT32,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
schema := schemapb.CollectionSchema{
|
2020-11-13 17:20:13 +08:00
|
|
|
Name: collectionName,
|
2020-11-12 11:18:23 +08:00
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
&fieldVec, &fieldInt,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
2020-11-13 15:17:18 +08:00
|
|
|
ID: UniqueID(0),
|
2020-11-12 11:18:23 +08:00
|
|
|
Schema: &schema,
|
|
|
|
CreateTime: Timestamp(0),
|
2020-11-13 15:17:18 +08:00
|
|
|
SegmentIDs: []UniqueID{0},
|
2020-11-12 11:18:23 +08:00
|
|
|
PartitionTags: []string{"default"},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
var err = (*node.replica).addCollection(&collectionMeta, collectionMetaBlob)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
collection, err := (*node.replica).getCollectionByName(collectionName)
|
2020-11-13 17:20:13 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
2020-11-13 15:17:18 +08:00
|
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
2020-11-17 20:00:23 +08:00
|
|
|
assert.Equal(t, (*node.replica).getCollectionNum(), 1)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
for _, tag := range collectionMeta.PartitionTags {
|
2020-11-17 20:00:23 +08:00
|
|
|
err := (*node.replica).addPartition(collection.ID(), tag)
|
2020-11-12 11:18:23 +08:00
|
|
|
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",
|
|
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "16",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
|
|
Name: "age",
|
|
|
|
DataType: schemapb.DataType_INT32,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: "collection0",
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
&fieldVec, &fieldInt,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
2020-11-13 15:17:18 +08:00
|
|
|
ID: UniqueID(0),
|
2020-11-12 11:18:23 +08:00
|
|
|
Schema: &schema,
|
|
|
|
CreateTime: Timestamp(0),
|
2020-11-13 15:17:18 +08:00
|
|
|
SegmentIDs: []UniqueID{0},
|
2020-11-12 11:18:23 +08:00
|
|
|
PartitionTags: []string{"default"},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
|
|
|
|
collection := newCollection(&collectionMeta, collectionMetaBlob)
|
|
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
2020-11-13 15:17:18 +08:00
|
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_deleteCollection(t *testing.T) {
|
|
|
|
fieldVec := schemapb.FieldSchema{
|
|
|
|
Name: "vec",
|
|
|
|
DataType: schemapb.DataType_VECTOR_FLOAT,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "16",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldInt := schemapb.FieldSchema{
|
|
|
|
Name: "age",
|
|
|
|
DataType: schemapb.DataType_INT32,
|
|
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "dim",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
schema := schemapb.CollectionSchema{
|
|
|
|
Name: "collection0",
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
&fieldVec, &fieldInt,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMeta := etcdpb.CollectionMeta{
|
2020-11-13 15:17:18 +08:00
|
|
|
ID: UniqueID(0),
|
2020-11-12 11:18:23 +08:00
|
|
|
Schema: &schema,
|
|
|
|
CreateTime: Timestamp(0),
|
2020-11-13 15:17:18 +08:00
|
|
|
SegmentIDs: []UniqueID{0},
|
2020-11-12 11:18:23 +08:00
|
|
|
PartitionTags: []string{"default"},
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionMetaBlob := proto.MarshalTextString(&collectionMeta)
|
|
|
|
assert.NotEqual(t, "", collectionMetaBlob)
|
|
|
|
|
|
|
|
collection := newCollection(&collectionMeta, collectionMetaBlob)
|
|
|
|
assert.Equal(t, collection.meta.Schema.Name, "collection0")
|
2020-11-13 15:17:18 +08:00
|
|
|
assert.Equal(t, collection.meta.ID, UniqueID(0))
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
deleteCollection(collection)
|
|
|
|
}
|