2021-04-19 10:09:43 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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-01-31 14:55:36 +08:00
|
|
|
package proxynode
|
|
|
|
|
|
|
|
import (
|
2021-02-26 17:44:24 +08:00
|
|
|
"context"
|
2021-01-31 14:55:36 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-03-08 10:09:48 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-01-31 14:55:36 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
type MockRootCoordClientInterface struct {
|
|
|
|
types.RootCoord
|
2021-01-31 14:55:36 +08:00
|
|
|
}
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
func (m *MockRootCoordClientInterface) ShowPartitions(ctx context.Context, in *milvuspb.ShowPartitionsRequest) (*milvuspb.ShowPartitionsResponse, error) {
|
2021-01-31 14:55:36 +08:00
|
|
|
if in.CollectionName == "collection1" {
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2021-01-31 14:55:36 +08:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-31 14:55:36 +08:00
|
|
|
},
|
|
|
|
PartitionIDs: []typeutil.UniqueID{1, 2},
|
|
|
|
PartitionNames: []string{"par1", "par2"},
|
|
|
|
}, nil
|
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2021-01-31 14:55:36 +08:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-31 14:55:36 +08:00
|
|
|
},
|
|
|
|
PartitionIDs: []typeutil.UniqueID{},
|
|
|
|
PartitionNames: []string{},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
func (m *MockRootCoordClientInterface) DescribeCollection(ctx context.Context, in *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2021-01-31 14:55:36 +08:00
|
|
|
if in.CollectionName == "collection1" {
|
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-31 14:55:36 +08:00
|
|
|
},
|
|
|
|
CollectionID: typeutil.UniqueID(1),
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
AutoID: true,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
2021-01-31 14:55:36 +08:00
|
|
|
},
|
|
|
|
CollectionID: typeutil.UniqueID(0),
|
|
|
|
Schema: nil,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaCache_GetCollection(t *testing.T) {
|
2021-02-26 17:44:24 +08:00
|
|
|
ctx := context.Background()
|
2021-06-21 17:28:03 +08:00
|
|
|
client := &MockRootCoordClientInterface{}
|
2021-01-31 14:55:36 +08:00
|
|
|
err := InitMetaCache(client)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err := globalMetaCache.GetCollectionID(ctx, "collection1")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(1))
|
2021-02-26 17:44:24 +08:00
|
|
|
schema, err := globalMetaCache.GetCollectionSchema(ctx, "collection1")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, schema, &schemapb.CollectionSchema{
|
|
|
|
AutoID: true,
|
|
|
|
})
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err = globalMetaCache.GetCollectionID(ctx, "collection2")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(0))
|
2021-02-26 17:44:24 +08:00
|
|
|
schema, err = globalMetaCache.GetCollectionSchema(ctx, "collection2")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Nil(t, schema)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaCache_GetPartitionID(t *testing.T) {
|
2021-02-26 17:44:24 +08:00
|
|
|
ctx := context.Background()
|
2021-06-21 17:28:03 +08:00
|
|
|
client := &MockRootCoordClientInterface{}
|
2021-01-31 14:55:36 +08:00
|
|
|
err := InitMetaCache(client)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err := globalMetaCache.GetPartitionID(ctx, "collection1", "par1")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(1))
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err = globalMetaCache.GetPartitionID(ctx, "collection1", "par2")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(2))
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err = globalMetaCache.GetPartitionID(ctx, "collection1", "par3")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(0))
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err = globalMetaCache.GetPartitionID(ctx, "collection2", "par3")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(0))
|
2021-02-26 17:44:24 +08:00
|
|
|
id, err = globalMetaCache.GetPartitionID(ctx, "collection2", "par4")
|
2021-01-31 14:55:36 +08:00
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Equal(t, id, typeutil.UniqueID(0))
|
|
|
|
}
|