2022-09-05 05:29:11 +00:00
|
|
|
package rootcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-10-16 12:49:27 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
2022-09-05 05:29:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_createPartitionTask_Prepare(t *testing.T) {
|
|
|
|
t.Run("invalid msg type", func(t *testing.T) {
|
|
|
|
task := &createPartitionTask{
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropCollection}},
|
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to get collection meta", func(t *testing.T) {
|
|
|
|
core := newTestCore(withInvalidMeta())
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreatePartition}},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName}
|
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
return coll.Clone(), nil
|
|
|
|
}
|
|
|
|
core := newTestCore(withMeta(meta))
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreatePartition}},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, coll.Equal(*task.collMeta))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_createPartitionTask_Execute(t *testing.T) {
|
|
|
|
t.Run("create duplicate partition", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{{PartitionName: partitionName}}}
|
|
|
|
task := &createPartitionTask{
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
2023-02-16 08:34:38 +00:00
|
|
|
t.Run("create too many partitions", func(t *testing.T) {
|
|
|
|
cfgMaxPartitionNum := Params.RootCoordCfg.MaxPartitionNum.GetAsInt()
|
|
|
|
partitions := make([]*model.Partition, 0, cfgMaxPartitionNum)
|
|
|
|
for i := 0; i < cfgMaxPartitionNum; i++ {
|
|
|
|
partitions = append(partitions, &model.Partition{})
|
|
|
|
}
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: partitions}
|
|
|
|
task := &createPartitionTask{
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2022-09-05 05:29:11 +00:00
|
|
|
t.Run("failed to allocate partition id", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{}}
|
|
|
|
core := newTestCore(withInvalidIDAllocator())
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to expire cache", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{}}
|
|
|
|
core := newTestCore(withValidIDAllocator(), withInvalidProxyManager())
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to add partition meta", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{}}
|
|
|
|
core := newTestCore(withValidIDAllocator(), withValidProxyManager(), withInvalidMeta())
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{}}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.AddPartitionFunc = func(ctx context.Context, partition *model.Partition) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
core := newTestCore(withValidIDAllocator(), withValidProxyManager(), withMeta(meta))
|
|
|
|
task := &createPartitionTask{
|
2022-09-24 04:42:51 +00:00
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
collMeta: coll,
|
|
|
|
Req: &milvuspb.CreatePartitionRequest{CollectionName: collectionName, PartitionName: partitionName},
|
2022-09-05 05:29:11 +00:00
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|