2021-10-15 18:09:00 +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 15:16:33 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-15 18:09:00 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 15:16:33 +08:00
|
|
|
//
|
2021-10-15 18:09:00 +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 15:16:33 +08:00
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2021-01-19 11:37:16 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-04-19 10:34:56 +08:00
|
|
|
const (
|
2021-09-09 10:14:00 +08:00
|
|
|
collectionID0 = UniqueID(2)
|
2021-04-19 10:34:56 +08:00
|
|
|
collectionID1 = UniqueID(1)
|
|
|
|
collectionName0 = "collection_0"
|
|
|
|
collectionName1 = "collection_1"
|
|
|
|
)
|
|
|
|
|
2021-01-25 18:33:10 +08:00
|
|
|
func TestMetaService_All(t *testing.T) {
|
2021-01-19 11:37:16 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
mFactory := &RootCoordFactory{
|
|
|
|
pkType: schemapb.DataType_Int64,
|
|
|
|
}
|
2021-04-19 10:34:56 +08:00
|
|
|
mFactory.setCollectionID(collectionID0)
|
|
|
|
mFactory.setCollectionName(collectionName0)
|
2021-06-08 19:25:37 +08:00
|
|
|
ms := newMetaService(mFactory, collectionID0)
|
2021-01-25 18:33:10 +08:00
|
|
|
|
2021-06-08 19:25:37 +08:00
|
|
|
t.Run("Test getCollectionSchema", func(t *testing.T) {
|
2021-01-25 18:33:10 +08:00
|
|
|
|
2021-06-08 19:25:37 +08:00
|
|
|
sch, err := ms.getCollectionSchema(ctx, collectionID0, 0)
|
2021-01-25 18:33:10 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-08 19:25:37 +08:00
|
|
|
assert.NotNil(t, sch)
|
|
|
|
assert.Equal(t, sch.Name, collectionName0)
|
2021-04-19 10:34:56 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test printCollectionStruct", func(t *testing.T) {
|
|
|
|
mf := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
collectionMeta := mf.GetCollectionMeta(collectionID0, collectionName0, schemapb.DataType_Int64)
|
2021-04-19 10:34:56 +08:00
|
|
|
printCollectionStruct(collectionMeta)
|
|
|
|
})
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
2021-08-30 10:03:58 +08:00
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
// RootCoordFails1 root coord mock for failure
|
2021-08-30 10:03:58 +08:00
|
|
|
type RootCoordFails1 struct {
|
|
|
|
RootCoordFactory
|
|
|
|
}
|
|
|
|
|
2023-01-04 16:37:35 +08:00
|
|
|
// DescribeCollectionInternal override method that will fails
|
|
|
|
func (rc *RootCoordFails1) DescribeCollectionInternal(ctx context.Context, req *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2021-08-30 10:03:58 +08:00
|
|
|
return nil, errors.New("always fail")
|
|
|
|
}
|
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
// RootCoordFails2 root coord mock for failure
|
2021-08-30 10:03:58 +08:00
|
|
|
type RootCoordFails2 struct {
|
|
|
|
RootCoordFactory
|
|
|
|
}
|
|
|
|
|
2023-01-04 16:37:35 +08:00
|
|
|
// DescribeCollectionInternal override method that will fails
|
|
|
|
func (rc *RootCoordFails2) DescribeCollectionInternal(ctx context.Context, req *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2021-08-30 10:03:58 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMetaServiceRootCoodFails(t *testing.T) {
|
|
|
|
|
|
|
|
t.Run("Test Describe with error", func(t *testing.T) {
|
|
|
|
rc := &RootCoordFails1{}
|
|
|
|
rc.setCollectionID(collectionID0)
|
|
|
|
rc.setCollectionName(collectionName0)
|
|
|
|
|
|
|
|
ms := newMetaService(rc, collectionID0)
|
|
|
|
_, err := ms.getCollectionSchema(context.Background(), collectionID1, 0)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-08-30 10:03:58 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Describe wit nil response", func(t *testing.T) {
|
|
|
|
rc := &RootCoordFails2{}
|
|
|
|
rc.setCollectionID(collectionID0)
|
|
|
|
rc.setCollectionName(collectionName0)
|
|
|
|
|
|
|
|
ms := newMetaService(rc, collectionID0)
|
|
|
|
_, err := ms.getCollectionSchema(context.Background(), collectionID1, 0)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.Error(t, err)
|
2021-08-30 10:03:58 +08:00
|
|
|
})
|
|
|
|
}
|